SlideShare a Scribd company logo
1 of 50
Download to read offline
smartbomb




DRY your views!
          Lachie Cox
   lachie@smartbomb.com.au



                        r o ro
smartbomb
                                  bmobtrams




             DRY
‣ don’t repeat yourself, mmkay?
smartbomb
                    bmobtrams




  MVC
‣ v is for vexing
smartbomb
             bmobtrams




DRYing models is
     easy
smartbomb
               bmobtrams




DRYing ctrllrs is
      OK
smartbomb
             bmobtrams




DRYing views is
   vexatious
WET views   smartbomb
            bmobtrams




   sca olding
smartbomb
bmobtrams
WET views          smartbomb
                   bmobtrams




          erb
        layouts
        partials
smartbomb
bmobtrams
smartbomb
                                           bmobtrams




<% labeled_form_for :thing, things_path do |f| %>
  <%= f.text_field :name %>
  <%= f.text_field :aspect %>
  <%= f.check_box :existing %>
  <%= submit_tag 'Save' %>
<% end %>
smartbomb
                                           bmobtrams



                   WASTE
<% labeled_form_for :thing, things_path do |f| %>
  <%= f.text_field :name %>
  <%= f.text_field :aspect %>
  <%= f.check_box :existing %>
  <%= submit_tag 'Save' %>
<% end %>
waste baaaad   smartbomb
               bmobtrams
smartbomb
             bmobtrams



components


 engines
smartbomb
bmobtrams
smartbomb
                               bmobtrams




‣ http://codefluency.com/2007/5/18/
  when-v-is-for-vexing
‣ Bruce Williams
smartbomb
              bmobtrams




Don’t Fear Helpers
 Make them APIs
smartbomb
            bmobtrams




Make them
 semantic
helpers as api          smartbomb
                        bmobtrams




   <%= describe person,
   :blank_message => quot;Nobodyquot;
   %>
helpers as api          smartbomb
                        bmobtrams




     <% rounded_box do %>
       <h2>Products</h2>
     <% end %>
stencil                             smartbomb
                                    bmobtrams




   ‣ http://stencil.rubyforge.org
smartbomb
             bmobtrams




semantic helpers
   as objects
a cart stencil                                 smartbomb
                                               bmobtrams

  class CartStencil < Stencil
    ...
    def to_s
      render(:partial => 'shared/cart', :object => @cart)
    end

    def summary
      if @cart.blank?
        quot;Your cart is empty. Buy stuff!quot;
      else
        quot;You have #{@cart.size} items in your cart.quot;
      end
    end
  end
a cart stencil                     smartbomb
                                   bmobtrams



<% cart = cart() %> <!-- CartStencil.new -->

<%= cart.summary %>

<%= cart %>   <!-- cart.to_s -->
more than a stencil           smartbomb
                              bmobtrams
    module CartControllerHelper
      ...
    end



    class UserController
      include CartControllerHelper

      load_cart :only => [:show]
    end
smartbomb
                      bmobtrams




C         V
 cart       cart
(mixin)   (stencil)
smartbomb
             bmobtrams
  Stencil
     +
  Mixin
     +
javascript
     +
   CSS
    &c.
smartbomb
              bmobtrams




lightweight
  widgetty
   thingo
smartbomb
bmobtrams
smartbomb
             bmobtrams




   DRY
javascript
smartbomb
      bmobtrams




RJS
smartbomb
bmobtrams
smartbomb
                            bmobtrams




document.getElementById(quot;foobarquot;)

           $(quot;foobarquot;)
smartbomb
                       bmobtrams




      use prototype
‣ until optimisation
smartbomb
                                 bmobtrams


<%= link_to_function 'declaim',
     'alert(quot;yay for smarties!quot;)' %>




<%= link_to 'delete', smarty_path(42),
     :method => :delete %>
smartbomb
bmobtrams
srsly, wtf?                       smartbomb
                                  bmobtrams


<a onclick=quot;var f = document.createElement
('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method =
'POST'; f.action = this.href;var m =
document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
m.setAttribute('value', 'delete');
f.appendChild(m);f.submit();return false;quot;
href=quot;/smarties/1quot;>delete</a>
smartbomb
bmobtrams
smartbomb
            bmobtrams




   be
  less
obtrusive
smartbomb
       bmobtrams




 use
less
code
smartbomb
              bmobtrams



   OMG
 javascript
has classes
    too!
smartbomb
        bmobtrams




 use
  &
reuse
smartbomb
                              bmobtrams




              lowpro
‣ http://danwebb.net/lowpro
smartbomb
             bmobtrams




 reusable
behaviours
smartbomb
bmobtrams
smartbomb
bmobtrams
smartbomb
                                         bmobtrams

                    HTML
<a class=quot;forgottenquot; href=quot;/accounts/forgottenquot;>
 I've forgotten my password.
 </a>
smartbomb
                                             bmobtrams

                       HTML
  <a class=quot;forgottenquot; href=quot;/accounts/forgottenquot;>
   I've forgotten my password.
   </a>




                      javascript
Event.addBehavior({
   '.forgotten': Toggler('forgotten_password','cancel')
})
smartbomb
bmobtrams
smartbomb
              bmobtrams




      DRY
its good for the
      soul

More Related Content

Viewers also liked

L I B R O D E A N I M A L E S D E 1 A
L I B R O  D E  A N I M A L E S  D E 1 AL I B R O  D E  A N I M A L E S  D E 1 A
L I B R O D E A N I M A L E S D E 1 AGabriela
 
O Que é Saudade 1(Nx Power Lite)03
O Que é Saudade  1(Nx Power Lite)03O Que é Saudade  1(Nx Power Lite)03
O Que é Saudade 1(Nx Power Lite)03carioca44
 
CSS For Coders
CSS For CodersCSS For Coders
CSS For Codersggfergu
 
The X Factor Team Presentation
The X Factor Team PresentationThe X Factor Team Presentation
The X Factor Team PresentationXanGolicious
 
SEO For Coders
SEO For CodersSEO For Coders
SEO For Codersggfergu
 
프레젠테이션1
프레젠테이션1프레젠테이션1
프레젠테이션1conmee4u
 
Our Trip To Norway 2007 Mm
Our Trip To Norway 2007 MmOur Trip To Norway 2007 Mm
Our Trip To Norway 2007 MmMartyman
 
Lago Maggiori, Italia
Lago Maggiori, ItaliaLago Maggiori, Italia
Lago Maggiori, Italiapacho54
 
La Maestra Luisa
La Maestra LuisaLa Maestra Luisa
La Maestra Luisalilimede
 
城大電信管理研究所 2007.09.08 高雄大碩招生投影片
城大電信管理研究所 2007.09.08 高雄大碩招生投影片城大電信管理研究所 2007.09.08 高雄大碩招生投影片
城大電信管理研究所 2007.09.08 高雄大碩招生投影片guest33b42a
 
Cuaderno Viajero 1 C
Cuaderno Viajero 1 CCuaderno Viajero 1 C
Cuaderno Viajero 1 CGabriela
 
Xabier Prieto
Xabier PrietoXabier Prieto
Xabier Prietominina
 
Reflex (Bg)
Reflex (Bg)Reflex (Bg)
Reflex (Bg)Vili 48
 

Viewers also liked (20)

Consejos Para La Vida
Consejos Para La VidaConsejos Para La Vida
Consejos Para La Vida
 
L I B R O D E A N I M A L E S D E 1 A
L I B R O  D E  A N I M A L E S  D E 1 AL I B R O  D E  A N I M A L E S  D E 1 A
L I B R O D E A N I M A L E S D E 1 A
 
O Que é Saudade 1(Nx Power Lite)03
O Que é Saudade  1(Nx Power Lite)03O Que é Saudade  1(Nx Power Lite)03
O Que é Saudade 1(Nx Power Lite)03
 
Hello
HelloHello
Hello
 
Visuals Format
Visuals FormatVisuals Format
Visuals Format
 
CSS For Coders
CSS For CodersCSS For Coders
CSS For Coders
 
The X Factor Team Presentation
The X Factor Team PresentationThe X Factor Team Presentation
The X Factor Team Presentation
 
Presentación
PresentaciónPresentación
Presentación
 
Bel Y Hol
Bel Y HolBel Y Hol
Bel Y Hol
 
Hello
HelloHello
Hello
 
SEO For Coders
SEO For CodersSEO For Coders
SEO For Coders
 
프레젠테이션1
프레젠테이션1프레젠테이션1
프레젠테이션1
 
Ecuaciones
EcuacionesEcuaciones
Ecuaciones
 
Our Trip To Norway 2007 Mm
Our Trip To Norway 2007 MmOur Trip To Norway 2007 Mm
Our Trip To Norway 2007 Mm
 
Lago Maggiori, Italia
Lago Maggiori, ItaliaLago Maggiori, Italia
Lago Maggiori, Italia
 
La Maestra Luisa
La Maestra LuisaLa Maestra Luisa
La Maestra Luisa
 
城大電信管理研究所 2007.09.08 高雄大碩招生投影片
城大電信管理研究所 2007.09.08 高雄大碩招生投影片城大電信管理研究所 2007.09.08 高雄大碩招生投影片
城大電信管理研究所 2007.09.08 高雄大碩招生投影片
 
Cuaderno Viajero 1 C
Cuaderno Viajero 1 CCuaderno Viajero 1 C
Cuaderno Viajero 1 C
 
Xabier Prieto
Xabier PrietoXabier Prieto
Xabier Prieto
 
Reflex (Bg)
Reflex (Bg)Reflex (Bg)
Reflex (Bg)
 

Similar to DRY up your views

Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyLindsay Holmwood
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)Kirill Zonov
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsMark
 
Bootstrap 3 training
Bootstrap 3 trainingBootstrap 3 training
Bootstrap 3 trainingVison Sunon
 
Using Node.js to make HTML5 work for everyone
Using Node.js to make HTML5 work for everyone Using Node.js to make HTML5 work for everyone
Using Node.js to make HTML5 work for everyone Tom Croucher
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in RailsBenjamin Vandgrift
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBen Limmer
 
Creating Responsive Experiences
Creating Responsive ExperiencesCreating Responsive Experiences
Creating Responsive ExperiencesTim Kadlec
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編Masakuni Kato
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
fast prototyping with sinatra sequel w2tags
fast prototyping with sinatra sequel w2tagsfast prototyping with sinatra sequel w2tags
fast prototyping with sinatra sequel w2tagswidi harsojo
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineJames Daniels
 
Merb Slices
Merb SlicesMerb Slices
Merb Sliceshassox
 

Similar to DRY up your views (20)

Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Bootstrap 3 training
Bootstrap 3 trainingBootstrap 3 training
Bootstrap 3 training
 
Using Node.js to make HTML5 work for everyone
Using Node.js to make HTML5 work for everyone Using Node.js to make HTML5 work for everyone
Using Node.js to make HTML5 work for everyone
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in Rails
 
Satchmo
SatchmoSatchmo
Satchmo
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Creating Responsive Experiences
Creating Responsive ExperiencesCreating Responsive Experiences
Creating Responsive Experiences
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
fast prototyping with sinatra sequel w2tags
fast prototyping with sinatra sequel w2tagsfast prototyping with sinatra sequel w2tags
fast prototyping with sinatra sequel w2tags
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset Pipeline
 
Cells
CellsCells
Cells
 
Merb Slices
Merb SlicesMerb Slices
Merb Slices
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

DRY up your views

  • 1. smartbomb DRY your views! Lachie Cox lachie@smartbomb.com.au r o ro
  • 2. smartbomb bmobtrams DRY ‣ don’t repeat yourself, mmkay?
  • 3. smartbomb bmobtrams MVC ‣ v is for vexing
  • 4. smartbomb bmobtrams DRYing models is easy
  • 5. smartbomb bmobtrams DRYing ctrllrs is OK
  • 6. smartbomb bmobtrams DRYing views is vexatious
  • 7. WET views smartbomb bmobtrams sca olding
  • 9. WET views smartbomb bmobtrams erb layouts partials
  • 11. smartbomb bmobtrams <% labeled_form_for :thing, things_path do |f| %> <%= f.text_field :name %> <%= f.text_field :aspect %> <%= f.check_box :existing %> <%= submit_tag 'Save' %> <% end %>
  • 12. smartbomb bmobtrams WASTE <% labeled_form_for :thing, things_path do |f| %> <%= f.text_field :name %> <%= f.text_field :aspect %> <%= f.check_box :existing %> <%= submit_tag 'Save' %> <% end %>
  • 13. waste baaaad smartbomb bmobtrams
  • 14. smartbomb bmobtrams components engines
  • 16. smartbomb bmobtrams ‣ http://codefluency.com/2007/5/18/ when-v-is-for-vexing ‣ Bruce Williams
  • 17. smartbomb bmobtrams Don’t Fear Helpers Make them APIs
  • 18. smartbomb bmobtrams Make them semantic
  • 19. helpers as api smartbomb bmobtrams <%= describe person, :blank_message => quot;Nobodyquot; %>
  • 20. helpers as api smartbomb bmobtrams <% rounded_box do %> <h2>Products</h2> <% end %>
  • 21. stencil smartbomb bmobtrams ‣ http://stencil.rubyforge.org
  • 22. smartbomb bmobtrams semantic helpers as objects
  • 23. a cart stencil smartbomb bmobtrams class CartStencil < Stencil ... def to_s render(:partial => 'shared/cart', :object => @cart) end def summary if @cart.blank? quot;Your cart is empty. Buy stuff!quot; else quot;You have #{@cart.size} items in your cart.quot; end end end
  • 24. a cart stencil smartbomb bmobtrams <% cart = cart() %> <!-- CartStencil.new --> <%= cart.summary %> <%= cart %> <!-- cart.to_s -->
  • 25. more than a stencil smartbomb bmobtrams module CartControllerHelper ... end class UserController include CartControllerHelper load_cart :only => [:show] end
  • 26. smartbomb bmobtrams C V cart cart (mixin) (stencil)
  • 27. smartbomb bmobtrams Stencil + Mixin + javascript + CSS &c.
  • 28. smartbomb bmobtrams lightweight widgetty thingo
  • 30. smartbomb bmobtrams DRY javascript
  • 31. smartbomb bmobtrams RJS
  • 33. smartbomb bmobtrams document.getElementById(quot;foobarquot;) $(quot;foobarquot;)
  • 34. smartbomb bmobtrams use prototype ‣ until optimisation
  • 35. smartbomb bmobtrams <%= link_to_function 'declaim', 'alert(quot;yay for smarties!quot;)' %> <%= link_to 'delete', smarty_path(42), :method => :delete %>
  • 37. srsly, wtf? smartbomb bmobtrams <a onclick=quot;var f = document.createElement ('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit();return false;quot; href=quot;/smarties/1quot;>delete</a>
  • 39. smartbomb bmobtrams be less obtrusive
  • 40. smartbomb bmobtrams use less code
  • 41. smartbomb bmobtrams OMG javascript has classes too!
  • 42. smartbomb bmobtrams use & reuse
  • 43. smartbomb bmobtrams lowpro ‣ http://danwebb.net/lowpro
  • 44. smartbomb bmobtrams reusable behaviours
  • 47. smartbomb bmobtrams HTML <a class=quot;forgottenquot; href=quot;/accounts/forgottenquot;> I've forgotten my password. </a>
  • 48. smartbomb bmobtrams HTML <a class=quot;forgottenquot; href=quot;/accounts/forgottenquot;> I've forgotten my password. </a> javascript Event.addBehavior({ '.forgotten': Toggler('forgotten_password','cancel') })
  • 50. smartbomb bmobtrams DRY its good for the soul