Taming The View for Rubyconf India

1,700 views
1,607 views

Published on

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total views
1,700
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
25
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

Taming The View for Rubyconf India

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

×