taming the view for rubyconf india
TRANSCRIPT
![Page 1: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/1.jpg)
Taming of the ViewRubyConf India 2010Sarah Taraporewalla
ThoughtWorks
Sunday, 21 March 2010
![Page 2: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/2.jpg)
I will attempt to convince you that:
Sunday, 21 March 2010
![Page 3: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/3.jpg)
I will attempt to convince you that:
- the current template engines are too permissive
Sunday, 21 March 2010
![Page 4: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/4.jpg)
I will attempt to convince you that:
- the current template engines are too permissive
- there are loads of code bases that break fundamental principles
Sunday, 21 March 2010
![Page 5: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/5.jpg)
I will attempt to convince you that:
- the current template engines are too permissive
- there are loads of code bases that break fundamental principles
- you should turn to other template engines
Sunday, 21 March 2010
![Page 6: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/6.jpg)
What is wrong with these examples?
Sunday, 21 March 2010
![Page 7: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/7.jpg)
Example 1
Sunday, 21 March 2010
![Page 8: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/8.jpg)
Example 2
Sunday, 21 March 2010
![Page 9: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/9.jpg)
Example 3
Sunday, 21 March 2010
![Page 10: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/10.jpg)
Example 4
Sunday, 21 March 2010
![Page 11: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/11.jpg)
AGH! This is really really easy in Rails3
now!
Sunday, 21 March 2010
![Page 12: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/12.jpg)
Controller
Sunday, 21 March 2010
![Page 13: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/13.jpg)
Why do we get thin controllers?
Sunday, 21 March 2010
![Page 14: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/14.jpg)
Push vs Pull
http://www.flickr.com/photos/91772025@N00/444044158/ CC BY-ND 2.0
Sunday, 21 March 2010
![Page 15: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/15.jpg)
Pull
View Controllers Model
Sunday, 21 March 2010
![Page 16: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/16.jpg)
Pull - over time
ViewControllers Model
Sunday, 21 March 2010
![Page 17: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/17.jpg)
Push
View Controllers Model
Sunday, 21 March 2010
![Page 18: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/18.jpg)
Push - over time
View
Controllers
Model
Sunday, 21 March 2010
![Page 19: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/19.jpg)
Push - and then
View Controllers Services
Sunday, 21 March 2010
![Page 20: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/20.jpg)
What do we want?
Sunday, 21 March 2010
![Page 21: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/21.jpg)
Testable Code
Sunday, 21 March 2010
![Page 22: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/22.jpg)
Testable Code
Don’t put logic in your views
Sunday, 21 March 2010
![Page 23: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/23.jpg)
Single Responsibility
Sunday, 21 March 2010
![Page 24: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/24.jpg)
Single Responsibility
Don’t let changes in column names effect your views
Sunday, 21 March 2010
![Page 25: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/25.jpg)
Separation of Concerns
Sunday, 21 March 2010
![Page 26: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/26.jpg)
Separation of Concerns
Enforce strict separation of model and view
Sunday, 21 March 2010
![Page 27: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/27.jpg)
How do we improve on the examples?
Sunday, 21 March 2010
![Page 28: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/28.jpg)
Example 1 - Before
Sunday, 21 March 2010
![Page 29: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/29.jpg)
Example 1 - Improved
Sunday, 21 March 2010
![Page 30: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/30.jpg)
Example 2 - Before
Sunday, 21 March 2010
![Page 31: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/31.jpg)
Example 2 - Improved
Sunday, 21 March 2010
![Page 32: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/32.jpg)
Example 2 - Improved
Sunday, 21 March 2010
![Page 33: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/33.jpg)
Example 3 - Before
Sunday, 21 March 2010
![Page 34: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/34.jpg)
Example 4 - Before
Sunday, 21 March 2010
![Page 35: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/35.jpg)
Example 3,4 - Improved
Sunday, 21 March 2010
![Page 36: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/36.jpg)
Example 3,4 - Improved
Sunday, 21 March 2010
![Page 37: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/37.jpg)
If you make it easy to do the wrong thing, the
wrong thing will be done
Sunday, 21 March 2010
![Page 38: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/38.jpg)
If you make it easy to do the right thing, the
right thing will be done
Sunday, 21 March 2010
![Page 39: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/39.jpg)
Haml
Sunday, 21 March 2010
![Page 40: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/40.jpg)
Haml
Sunday, 21 March 2010
![Page 41: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/41.jpg)
Haml
Good
Sunday, 21 March 2010
![Page 42: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/42.jpg)
Haml
Good
But ...
Sunday, 21 March 2010
![Page 43: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/43.jpg)
Haml
Good
But ...
still allows ruby
Sunday, 21 March 2010
![Page 44: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/44.jpg)
String Template
Sunday, 21 March 2010
![Page 45: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/45.jpg)
StringTemplate
- Strict separation of model & view
- Fits well with functional programming
- Written in Java, .Net, Python
is NOT Turing complete
Sunday, 21 March 2010
![Page 46: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/46.jpg)
1. Create a StringTemplate Object with the template
Sunday, 21 March 2010
![Page 47: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/47.jpg)
1. Create a StringTemplate Object with the template
string or file
Sunday, 21 March 2010
![Page 48: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/48.jpg)
2. Set attributes and their values
Sunday, 21 March 2010
![Page 49: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/49.jpg)
3. Call toString() to mash attributes onto the template
Sunday, 21 March 2010
![Page 50: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/50.jpg)
Testable?
Sunday, 21 March 2010
![Page 51: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/51.jpg)
Testable? Yes!
Sunday, 21 March 2010
![Page 52: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/52.jpg)
Single Responsibility?
Sunday, 21 March 2010
![Page 53: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/53.jpg)
Single Responsibility? Yes!
Sunday, 21 March 2010
![Page 54: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/54.jpg)
Separation of Concerns?
Sunday, 21 March 2010
![Page 55: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/55.jpg)
Separation of Concerns? Yes!
It is the essence of its philosophy
Sunday, 21 March 2010
![Page 56: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/56.jpg)
Other cool things...
Sunday, 21 March 2010
![Page 57: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/57.jpg)
Templates (Partials)
Sunday, 21 March 2010
![Page 58: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/58.jpg)
Iterators
Sunday, 21 March 2010
![Page 59: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/59.jpg)
Iterators
Sunday, 21 March 2010
![Page 60: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/60.jpg)
Renderers
Sunday, 21 March 2010
![Page 61: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/61.jpg)
Localisation
Sunday, 21 March 2010
![Page 62: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/62.jpg)
But, we do Ruby
Sunday, 21 March 2010
![Page 63: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/63.jpg)
Slippers
Sunday, 21 March 2010
![Page 64: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/64.jpg)
Slippers
Sunday, 21 March 2010
![Page 65: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/65.jpg)
Slippers & Ramaze
Sunday, 21 March 2010
![Page 66: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/66.jpg)
Slippers - Example
Sunday, 21 March 2010
![Page 67: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/67.jpg)
Slippers - Example
Sunday, 21 March 2010
![Page 68: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/68.jpg)
Slippers - Example
Sunday, 21 March 2010
![Page 69: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/69.jpg)
Slippers - Exampleindex.st
person/index.st
person/age.stSunday, 21 March 2010
![Page 70: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/70.jpg)
Slippers - Exampleperson/age_renderer.rb
controller/role_renderer.rb
Sunday, 21 March 2010
![Page 71: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/71.jpg)
Slippers - Example
Sunday, 21 March 2010
![Page 72: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/72.jpg)
Slippers - Testable?
• Holes are correctly plugged
• Correct instance variables set
• Renderers
Sunday, 21 March 2010
![Page 73: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/73.jpg)
• Holes are correctly plugged
• Correct instance variables set
• Renderers
Slippers - Testable?
Sunday, 21 March 2010
![Page 74: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/74.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 75: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/75.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 76: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/76.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 77: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/77.jpg)
• Holes are correctly plugged
• Correct instance variables set
• Renderers
Slippers - Testable?
Sunday, 21 March 2010
![Page 78: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/78.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 79: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/79.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 80: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/80.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 81: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/81.jpg)
• Holes are correctly plugged
• Correct instance variables set
• Renderers
Slippers - Testable?
Sunday, 21 March 2010
![Page 82: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/82.jpg)
Slippers - Testable?
Sunday, 21 March 2010
![Page 83: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/83.jpg)
Slippers
Sunday, 21 March 2010
![Page 84: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/84.jpg)
Slippers
• Can be found at:
‣ http://slippersRb.com
‣ http://github.com/starapor/slippers
‣ http://gemcutter.org/gems/slippers
• Ramaze view template
‣ http://ramaze.net
Sunday, 21 March 2010
![Page 85: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/85.jpg)
Have I convinced you that:
Sunday, 21 March 2010
![Page 86: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/86.jpg)
Have I convinced you that:
- the current template engines are too permissive
Sunday, 21 March 2010
![Page 87: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/87.jpg)
Have I convinced you that:
- the current template engines are too permissive
- there are loads of code bases that break fundamental principles
Sunday, 21 March 2010
![Page 88: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/88.jpg)
Have I convinced you that:
- the current template engines are too permissive
- there are loads of code bases that break fundamental principles
- we should turn to other template engines
Sunday, 21 March 2010
![Page 89: Taming The View for Rubyconf India](https://reader036.vdocuments.site/reader036/viewer/2022081519/55512f71b4c905f1528b4f54/html5/thumbnails/89.jpg)
questions?
Sunday, 21 March 2010