Your SlideShare is downloading. ×
0
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Presentation.Key
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Presentation.Key

549

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
549
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • You have to manage indenting and whitespace yourself
    You have to close the tags yourself
    You have to decide when to html escape
    Poor IDE support
    Proper factoring makes code slow - render partial
  • Helpers are typically available in all views
    No namespacing
    Instance variables are psuedo-global
    Yield has inconsistent semantics
    Concat binding fuckupedness
    The way variables are bound affects refactoring
  • Code lives in different files - view, layout, partial and the helpers module
    You have to know when to use auto-naming, instance variables, locals
    Inconsistent calling conventions for helpers
    View specs can be hard



    # helpers returning raw text
    [
    :image_tag,
    :javascript_include_tag,
    :stylesheet_link_tag,
    :sortable_element,
    :sortable_element_js,
    :text_field_with_auto_complete,



    # helpers returning raw text whose first parameter is HTML escaped
    [
    :link_to,
    :link_to_remote,
    :mail_to,
    :button_to,
    :submit_tag,



    # return text, take block
    [
    :link_to,
    :link_to_remote,
    :link_to_function,
    :text_field_tag,
    :password_field_tag,
    :check_box_tag



    # render text, take block
    [
    :error_messages_for,
    :form_tag,
    :form_for,
  • Auto-escape html
    Manage whitespace and indentation for you
    Auto-close your tags
    Good IDE support
    Consistent semantics
    Little magic
  • Methods, variables etc...
    How many of you are object oriented programmers? Functional gangbang
  • Unit testability proves/enables good design
    Enables refactoring
    Enables you to test-drive
    Dependency injection
  • "Dependency injection" via constructor params (aka "Complete Construction")



    Well-defined semantics for variables, loops, blocks
  • "Dependency injection" via constructor params (aka "Complete Construction")



    Well-defined semantics for variables, loops, blocks
  • "Dependency injection" via constructor params (aka "Complete Construction")



    Well-defined semantics for variables, loops, blocks
  • pretty printing
  • pretty printing
  • pretty printing
  • Rename has to go into both files
    Probably have to rename this since you probably have all helpers included by default
  • You have to decide where to h (this might change in rails 3)
  • Different semantics
  • 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 => "content" do p "Hello <script> World!", :class => "sidebar" 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 => "content" do p "Hello <script> World!", :class => "sidebar" end end end # <div class="content"> # <p class="sidebar">Hello &lt;script&gt; World!</p> # </div>
    • 17. ERB Refactoring
    • 18. <!-- app/views/articles/show.html.erb --> <%=h truncate(article.title, :length => 10) %>
    • 19. <!-- app/views/articles/show.html.erb --> <%=h display_name(article) %> # app/helpers/articles.rb def display_name(article) truncate(article.title, :length => 10) end
    • 20. <!-- 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
    • 21. <!-- 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
    • 22. <!-- 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
    • 23. <!-- 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
    • 24. <!-- 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
    • 25. <!-- app/views/articles/show.html.erb --> <%= render("articles/title", :title => article) %> <!-- app/views/_title.html.erb --> <span title="<%= article.title %>"> <%=h truncate(article.title, :length => 10) %> </span>
    • 26. <!-- app/views/articles/show.html.erb --> <%= render("articles/title", :title => article) %> <!-- app/views/_title.html.erb --> <span title="<%= article.title %>"> <%=h truncate(article.title, :length => 10) %> </span>
    • 27. Erector Refactoring
    • 28. # app/views/articles/show.rb class Views::Articles::Show < Erector::RailsWidget def content text do truncate @article.title, :length => 10 end end end
    • 29. # 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
    • 30. # 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
    • 31. # 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
    • 32. # 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
    • 33. # 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
    • 34. # 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
    • 35. # 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
    • 36. What’s next?
    • 37. more rails helpers
    • 38. better performance
    • 39. rails 3
    • 40. erector.rubyforge.org github.com/pivotal/erector jdean@pivotallabs.com
    • 41. Questions

    ×