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

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 

Recently uploaded (20)

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 

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