Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Implement beautiful DSL for iOS using Ruby
Search
Francis Chong
April 26, 2014
Programming
2
780
Implement beautiful DSL for iOS using Ruby
At RubyConf Taiwan 2014 #ruby #rubyconftw
Francis Chong
April 26, 2014
Tweet
Share
More Decks by Francis Chong
See All by Francis Chong
Migrate to Swift 3
siuying
0
210
CocoaPods - A better way to use and publish open source project for Objective-C
siuying
2
380
Legco OpenData
siuying
0
140
EverClip - Evernote DEVCUP Meetup 2013 Hong Kong
siuying
0
95
iOS Development with Ruby using RubyMotion
siuying
1
180
Other Decks in Programming
See All in Programming
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
100
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Fluid Templating in TYPO3 14
s2b
0
130
高速開発のためのコード整理術
sutetotanuki
1
390
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.4k
AtCoder Conference 2025
shindannin
0
1.1k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
220
Oxlint JS plugins
kazupon
1
880
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
100
Between Models and Reality
mayunak
1
180
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
57
50k
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
Embracing the Ebb and Flow
colly
88
5k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Documentation Writing (for coders)
carmenintech
77
5.2k
Evolving SEO for Evolving Search Engines
ryanjones
0
120
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
A better future with KSS
kneath
240
18k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
290
Transcript
Implement beautiful DSL for iOS using Ruby Francis Chong
About me
鍾振輝 Francis Chong @siuying
Indie Mobile Dev
Why DSL?
https://github.com/tzangms/iloveck101 “I love ck101.com” ! “… I just want the
pictures. But their site is slow, filled with ads and noise … ” @tzangms 海總理
None
None
People found this is a good idea!
• Go • https://github.com/wuman/go-ck101 • https://github.com/lazywei/iloveck101 • Ruby • https://github.com/wancw/iloveck101
• https://github.com/shunwen/iloveck101 • PHP • https://github.com/fukuball/iloveck101 • Objective-C • https://github.com/saiday/hornyfolks • https://github.com/siuying/iloveck101 • Node.js • https://github.com/clonn/iloveck101 • Groovy • https://github.com/tangblack/ groovy_ILoveCK101 • Racket • https://github.com/Domon/iloveck101 • JavaScript • https://github.com/poying/iloveck101 • GreaseMonekey • https://github.com/tomin/iloveck101
I made an iOS version too …
Can we generalize it?
Convert web sites into reusable data.
None
None
Goals • Keep existing code and tools • Add dynamic
behavior to a static app • Interact with native code • Simple to read and write
DSL
Domain Specific Language
–Martin Fowler “DSLs are small languages, focused on a particular
aspect of a software system.”
External & Internal DSL
How to implement DSL for iOS
Internal DSL with Objective-C / RubyMotion
Masonry https://github.com/cloudkite/Masonry
Moria https://github.com/siuying/moria
Kiwi https://github.com/allending/Kiwi
Parser generator like Bison, CoreParse or PEGKit
NUI https://github.com/tombenner/nui
mruby
objc-mruby example
JavaScriptCore
iOS 7.0
Bi-directional Bridge http://blog.bignerdranch.com/3784-javascriptcore-and-ios-7/
None
… but this is a Ruby conference?
Opal
Ruby to JavaScript Compiler http://opalrb.org/try/
Output
JavaScriptCore + Opal
Expose Native Classes to JS
Opal Wrapper for JS
Example
Goal: Convert web sites into reusable data.
Designing the DSL
1. Write an imaginary DSL
2. Make it valid
3. Make it work
4. Add more use case
Everything
http://cl.ly/3Y1y0N3y2J1V
Now we’ve supported one site
Let’s add more!
None
http://cl.ly/0R0k0t1x2v2r
Users could change the code themselves
Add sites without recompile
Practical Tips
JavaScriptCoreOpalAdditions
Compile Opal in Runtime
IGJavaScriptConsole
Interactive Console
Rake and sprockets
Gemfile
Rakefile
Integrate the project into Xcode
Custom Build Phase
Add build task to project
Pros and Cons
Based on features in iOS SDK
Dynamic behavior
Interaction with native code.
Easy to read and write.
One more layer of indirection.
–App Store Review Guidelines “Apps that download code in any
way or form will be rejected.”
Readings
http://www.duokan.com/book/43469
http://www.amazon.com/gp/product/0321712943
Question?