Advanced Views with Erector

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Advanced Views with Erector - Presentation Transcript

    1. Advanced Views with Erector A builder view framework Jeff Dean
    2. ERB views kinda suck
    3. Make you work more
    4. No encapsulation
    5. Refactoring can be hard
    6. We need something that...
    7. Requires less work
    8. Respects encapsulation
    9. Is testable in isolation
    10. Erector to the rescue!
    11. Views are classes
    12. Views are classes
      • Modular decomposition
      • Inheritance (nested layouts)
      • Consistent semantics
    13. Views are classes
      • class Views::Articles::Show < Erector::RailsWidget
      • def content div :class => &quot;content&quot; do p &quot;Hello <script> World!&quot; , :class => &quot;sidebar&quot; end end
      • end
    14. Does the right thing
    15. Does the right thing
      • Escapes HTML
      • Auto-closes tags
      • You control indenting and whitespace
    16. Does the right thing
      • class Views::Articles::Show < Erector::RailsWidget def content div :class => &quot;content&quot; do p &quot;Hello <script> World!&quot; , :class => &quot;sidebar&quot; end end end # <div class=&quot;content&quot;> # <p class=&quot;sidebar&quot;>Hello &lt;script&gt; World!</p> # </div>
    17. ERB Refactoring
      • <!-- app/views/articles/show.html.erb --> <%=h truncate(article.title, :length => 10 ) %>
      • <!-- app/views/articles/show.html.erb -->
      • <%=h display_name(article) %>
      • # app/helpers/articles.rb def display_name (article) truncate(article.title, :length => 10 ) end
      • <!-- app/views/articles/show.html.erb -->
      • <%=h article_display_name (article) %>
      • # app/helpers/articles.rb def article_display_name (article) truncate(article.title, :length => 10 ) end
      • <!-- app/views/articles/show.html.erb -->
      • <%=h article_display_name (article) %>
      • # app/helpers/articles.rb def article_display_name (article) truncate(article.title, :length => 10 ) end
      • <!-- app/views/articles/show.html.erb --> <%= article_display_name(article) %>
      • # app/helpers/articles.rb def article_display_name (article) content_tag :span , h(truncate(article.title, :length => 10 )), :title => article.title end
      • <!-- app/views/articles/show.html.erb --> <%= article_display_name(article) %>
      • # app/helpers/articles.rb def article_display_name (article) content_tag :span , h(truncate(article.title, :length => 10 )), :title => article.title end
      • <!-- app/views/articles/show.html.erb --> <%= article_display_name(article) %>
      • # app/helpers/articles.rb def article_display_name (article) content_tag :span , h(truncate(article.title, :length => 10 )), :title => article.title end
      • <!-- app/views/articles/show.html.erb --> <%= render ( &quot;articles/title&quot; , :title => article) %>
      • <!-- app/views/_title.html.erb --> <span title= &quot;<%= article.title %>&quot; > <%=h truncate(article.title, :length => 10 ) %> </span>
      • <!-- app/views/articles/show.html.erb --> <%= render ( &quot;articles/title&quot; , :title => article) %>
      • <!-- app/views/_title.html.erb --> <span title= &quot;<%= article.title %>&quot; > <%=h truncate(article.title, :length => 10 ) %> </span>
    18. Erector Refactoring
    19. # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content text do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content display_name end private def display_name text do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content display_name end private def display_name text do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content display_name end private def display_name span :title => @article .title do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content display_name end private def display_name span :title => @article .title do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Views::Articles::Base def content display_name end end
      • # app/views/articles/base.rb class Views::Articles::Base < Erector::RailsWidget def display_name span :title => @article .title do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Views::Articles::Base def content display_name end end
      • # app/views/articles/base.rb class Views::Articles::Base < Erector::RailsWidget def display_name span :title => @article .title do truncate @article .title, :length => 10 end end end
      • # app/views/articles/show.rb class Views::Articles::Show < Views::Articles::Base def content display_name end end
      • # app/views/articles/base.rb class Views::Articles::Base < Erector::RailsWidget def display_name span :title => @article .title do truncate @article .title, :length => 10 end end end
    20.  
    21. What’s next?
    22. more rails helpers
    23. better performance
    24. rails 3
    25. erector.rubyforge.org github.com/pivotal/erector [email_address] [email_address] [email_address] [email_address] [email_address]
    26. Questions

    + alexchaffeealexchaffee, 1 month ago

    custom

    343 views, 0 favs, 0 embeds more stats

    Erector is a Ruby gem that implements the “builde more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 343
      • 343 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 3
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories