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
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 <script> World!</p>
# </div>
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
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)