Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
770
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
200
CocoaPods - A better way to use and publish open source project for Objective-C
siuying
2
370
Legco OpenData
siuying
0
140
EverClip - Evernote DEVCUP Meetup 2013 Hong Kong
siuying
0
94
iOS Development with Ruby using RubyMotion
siuying
1
180
Other Decks in Programming
See All in Programming
20 years of Symfony, what's next?
fabpot
1
130
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
540
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
4
390
俺流レスポンシブコーディング 2025
tak_dcxi
0
530
CSC305 Lecture 14
javiergs
PRO
0
330
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
How Software Deployment tools have changed in the past 20 years
geshan
0
25k
『実践MLOps』から学ぶ DevOps for ML
nsakki55
2
490
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
4
1.7k
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
200
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
230
OSS開発者の憂鬱
yusukebe
15
12k
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
59
Automating Front-end Workflow
addyosmani
1371
200k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
How to Think Like a Performance Engineer
csswizardry
28
2.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
11
950
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.2k
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?