SlideShare a Scribd company logo
1 of 11
Download to read offline
Statische websites in Rails 3.1
- Maar waarom?

- Rails 3.1 project aanmaken met 45north_template
- PagesController aanmaken met statische views
- Layout, partials en helpers gebruiken
- Lo(l)cales
- Asset pijpleiding in Rails 3.1
- SCSS >>>>>>>>>>>>>>>> (twee schermen verder) >>> CSS
- Haml >>>> ERB
45north_template
- Simpele manier om Rails 3.1 template te maken
- Github repo: https://github.com/45north/45north_template

~/.bash_profile
function rails3() {
  curl "https://raw.github.com/45north/45north_template/master/generate_template" | bash -s "$@";
  cd "$@";
}




Terminal
rails3 rails3_static
Statische Views
Terminal
rails g controller pages




/app/controllers/pages_controller.rb
class PagesController < ApplicationController
  def index
  end

  def about
  end                                                       /config/routes.rb
                                                            get "about" => "pages#about", :as => :about
  def contact
                                                            get "contact" => "pages#contact", :as => :contact
  end
                                                            root :to => "pages#index"
end




/app/views/pages
/ index.html.haml                 / about.html.haml                / contact.html.haml
- content_for(:title, "Home")     - content_for(:title, "About")   - content_for(:title, "Contact")
%h1 Home                          %h1 About                        %h1 Contact
Layout
- Alle standaard HTML in layout stoppen
- Yield = Awesome

/app/views/layouts/application.html.haml
!!! HTML5
%html
  %head
    %title Rails 3 Static - #{yield(:title)}
    = stylesheet_link_tag("application")
    = javascript_include_tag("application")
    = csrf_meta_tags
  %body
    %ul#menu
      %li= link_to("Home", :root)
      %li= link_to("About", :about)
      %li= link_to("Contact", :contact)

    = yield
Partials
- Partials = DRY
- Voor grote stukken HTML die vaker voorkomen
- Template Inheritance in Rails 3.1

/app/views/application/_menu.html.haml


                                          DRY
%ul#menu
  %li= link_to("Home", :root)
  %li= link_to("About", :about)
  %li= link_to("Contact", :contact)




Partial toevoegen                         DON’T REPEAT YOURSELF
%body
  = render("menu")
  = yield
Helpers
- Helpers = DRY
- Helpers voor kleine stukken HTML die vaker voorkomen

/app/helpers/application_helper.rb
module ApplicationHelper
  def menu_li(lbl, path, *args)
    options = args.extract_options!
    options.merge!(:class => "active") if url_for(path) == request.fullpath




                                                                              DRY
    content_tag(:li, link_to(lbl, path), options)
  end
end




Helper aanroepen
%ul#menu
                                                                              DON’T REPEAT YOURSELF
  = menu_li("Home", :root)
  = menu_li("About", :about)
  = menu_li("Contact", :contact)
Locales
- Statische teksten » Locale
- YAML (bijna net zo awesome als Haml)

/config/locales/en.yml
en:
  home:
    page_title: "Home"
  about:
    page_title: "About"
  contact:                                   Meer weten?
    page_title: "Contact"
                                    http://guides.rubyonrails.org/
                                              i18n.html
Locale aanspreken
= t("home.page_title")
Asset pipeline                                                                Meer weten?
                                                                     http://guides.rubyonrails.org/
JavaScript, CSS en Images                                                 asset_pipeline.html
/public          =   No-way
/app/assets      =   Yes-way   # => Speciaal voor jouw applicatie.
/lib/assets      =   Yes-way   # => Je eigen libraries.
/vendor/assets   =   Yes-way   # => Libraries van anderen.




/app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require_tree .




/app/assets/stylesheets/application.css
/*
 *= require_self
 *= require_tree .
*/
SCSS = SASS + CSS syntax
- Standaard in Rails 3.1

/app/assets/stylesheets/application.css.scss
$primary-color: #500;
$focus-color: #f00;

@mixin menu {
  padding: 0; margin: 0;
  float: left; width: 100%;
  list-style: none;

    li {                                        Meer weten?
      float: left;
      a { color: $primary-color; }          http://sass-lang.com/
      &.active a { color: $focus-color; }
    }
}

#menu {
  @include menu;
}
Haml
- Makkelijker HTML schrijven
- Beter dan ERB (duh)
- 2 spaces (soft tab)
- Lange regels = No-go
%h1.my_class H1-tag met class
%span#my_id Span-tag met id
#header Div-tag met id
.footer Div-tag met class
= "Ruby code uitvoeren en laten zien"
- "Ruby code uitvoeren en niet laten zien"        Meer weten?
/ HTML comment

%ul
                                             http://haml-lang.com/
  %li
    Nesten doe
    je zo.
  %li En zo
  %li= "En zo met Ruby"
  %li{ :name => "attribuut" }
  %li(name="attribuut")
DEMO TIME!
https://github.com/RobinBrouwer/rails3_static

More Related Content

What's hot

Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
Albert Jessurum
 

What's hot (19)

Why I love Haml
Why I love HamlWhy I love Haml
Why I love Haml
 
Beyond HTML - Scriptsprachen, Frameworks, Templatesprachen und vieles mehr
Beyond HTML - Scriptsprachen, Frameworks, Templatesprachen und vieles mehrBeyond HTML - Scriptsprachen, Frameworks, Templatesprachen und vieles mehr
Beyond HTML - Scriptsprachen, Frameworks, Templatesprachen und vieles mehr
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference Client
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
 
Hows Haml?
Hows Haml?Hows Haml?
Hows Haml?
 
Haml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web DevelopmentHaml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web Development
 
Pecha Kucha Delicious
Pecha Kucha DeliciousPecha Kucha Delicious
Pecha Kucha Delicious
 
Haml And Sass
Haml And SassHaml And Sass
Haml And Sass
 
Clever Joomla! Templating Tips and Tricks
Clever Joomla! Templating Tips and TricksClever Joomla! Templating Tips and Tricks
Clever Joomla! Templating Tips and Tricks
 
Capybara
CapybaraCapybara
Capybara
 
CSS basic cheat sheet
CSS basic cheat sheetCSS basic cheat sheet
CSS basic cheat sheet
 
Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
Semantic accessibility
Semantic accessibilitySemantic accessibility
Semantic accessibility
 
WordPress as a Content Management System
WordPress as a Content Management SystemWordPress as a Content Management System
WordPress as a Content Management System
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme Kickstart
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
 

Viewers also liked

Early national literature
Early national literatureEarly national literature
Early national literature
ms_faris
 
FUM Belize Friends School
FUM Belize Friends SchoolFUM Belize Friends School
FUM Belize Friends School
Kelly Kellum
 
Looking for the best Marketing of 2013? Well, it's not in here...
Looking for the best Marketing of 2013? Well, it's not in here...Looking for the best Marketing of 2013? Well, it's not in here...
Looking for the best Marketing of 2013? Well, it's not in here...
Carmichael Billingsley
 
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
leonvit2005
 
AWS が面白くなる話、詰め合わせました
AWS が面白くなる話、詰め合わせましたAWS が面白くなる話、詰め合わせました
AWS が面白くなる話、詰め合わせました
Eikichi Gotoh
 
National day of romania ziua nationala a romaniei
National day of romania ziua nationala a romanieiNational day of romania ziua nationala a romaniei
National day of romania ziua nationala a romaniei
balada65
 

Viewers also liked (20)

Agra tour iii article
Agra tour iii articleAgra tour iii article
Agra tour iii article
 
Early national literature
Early national literatureEarly national literature
Early national literature
 
Nltrv55
Nltrv55Nltrv55
Nltrv55
 
Silvennoinen: Digitaalisen pelaamisen koukut - tavoitteita, sosiaalisuutta ja...
Silvennoinen: Digitaalisen pelaamisen koukut - tavoitteita, sosiaalisuutta ja...Silvennoinen: Digitaalisen pelaamisen koukut - tavoitteita, sosiaalisuutta ja...
Silvennoinen: Digitaalisen pelaamisen koukut - tavoitteita, sosiaalisuutta ja...
 
FUM Belize Friends School
FUM Belize Friends SchoolFUM Belize Friends School
FUM Belize Friends School
 
Paganini
PaganiniPaganini
Paganini
 
2
22
2
 
Looking for the best Marketing of 2013? Well, it's not in here...
Looking for the best Marketing of 2013? Well, it's not in here...Looking for the best Marketing of 2013? Well, it's not in here...
Looking for the best Marketing of 2013? Well, it's not in here...
 
JOTIBA
JOTIBAJOTIBA
JOTIBA
 
Программы здоровья ТРАДО
Программы здоровья ТРАДО Программы здоровья ТРАДО
Программы здоровья ТРАДО
 
BuddyPress: Social Networks for WordPress
BuddyPress: Social Networks for WordPressBuddyPress: Social Networks for WordPress
BuddyPress: Social Networks for WordPress
 
Database List owners' prespective
Database List owners' prespectiveDatabase List owners' prespective
Database List owners' prespective
 
Q 4 week 2
Q 4 week 2Q 4 week 2
Q 4 week 2
 
White label demo admin Appsmakerstore
White label demo admin AppsmakerstoreWhite label demo admin Appsmakerstore
White label demo admin Appsmakerstore
 
Deep Dive Into Quantum
Deep Dive Into QuantumDeep Dive Into Quantum
Deep Dive Into Quantum
 
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
 
AWS が面白くなる話、詰め合わせました
AWS が面白くなる話、詰め合わせましたAWS が面白くなる話、詰め合わせました
AWS が面白くなる話、詰め合わせました
 
Discussion continuum - Dostep do leczenia
Discussion continuum - Dostep do leczeniaDiscussion continuum - Dostep do leczenia
Discussion continuum - Dostep do leczenia
 
Gao report
Gao reportGao report
Gao report
 
National day of romania ziua nationala a romaniei
National day of romania ziua nationala a romanieiNational day of romania ziua nationala a romaniei
National day of romania ziua nationala a romaniei
 

Similar to Statische Websites in Rails 3.1

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
Benjamin Vandgrift
 
Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)
Joao Lucas Santana
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 

Similar to Statische Websites in Rails 3.1 (20)

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
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011
 
Ariane
ArianeAriane
Ariane
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon Rails
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Rails + Sencha = Netzke
Rails + Sencha = NetzkeRails + Sencha = Netzke
Rails + Sencha = Netzke
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing science
 
Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Ams adapters
Ams adaptersAms adapters
Ams adapters
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Statische Websites in Rails 3.1

  • 1. Statische websites in Rails 3.1 - Maar waarom? - Rails 3.1 project aanmaken met 45north_template - PagesController aanmaken met statische views - Layout, partials en helpers gebruiken - Lo(l)cales - Asset pijpleiding in Rails 3.1 - SCSS >>>>>>>>>>>>>>>> (twee schermen verder) >>> CSS - Haml >>>> ERB
  • 2. 45north_template - Simpele manier om Rails 3.1 template te maken - Github repo: https://github.com/45north/45north_template ~/.bash_profile function rails3() { curl "https://raw.github.com/45north/45north_template/master/generate_template" | bash -s "$@"; cd "$@"; } Terminal rails3 rails3_static
  • 3. Statische Views Terminal rails g controller pages /app/controllers/pages_controller.rb class PagesController < ApplicationController def index end def about end /config/routes.rb get "about" => "pages#about", :as => :about def contact get "contact" => "pages#contact", :as => :contact end root :to => "pages#index" end /app/views/pages / index.html.haml / about.html.haml / contact.html.haml - content_for(:title, "Home") - content_for(:title, "About") - content_for(:title, "Contact") %h1 Home %h1 About %h1 Contact
  • 4. Layout - Alle standaard HTML in layout stoppen - Yield = Awesome /app/views/layouts/application.html.haml !!! HTML5 %html %head %title Rails 3 Static - #{yield(:title)} = stylesheet_link_tag("application") = javascript_include_tag("application") = csrf_meta_tags %body %ul#menu %li= link_to("Home", :root) %li= link_to("About", :about) %li= link_to("Contact", :contact) = yield
  • 5. Partials - Partials = DRY - Voor grote stukken HTML die vaker voorkomen - Template Inheritance in Rails 3.1 /app/views/application/_menu.html.haml DRY %ul#menu %li= link_to("Home", :root) %li= link_to("About", :about) %li= link_to("Contact", :contact) Partial toevoegen DON’T REPEAT YOURSELF %body = render("menu") = yield
  • 6. Helpers - Helpers = DRY - Helpers voor kleine stukken HTML die vaker voorkomen /app/helpers/application_helper.rb module ApplicationHelper def menu_li(lbl, path, *args) options = args.extract_options! options.merge!(:class => "active") if url_for(path) == request.fullpath DRY content_tag(:li, link_to(lbl, path), options) end end Helper aanroepen %ul#menu DON’T REPEAT YOURSELF = menu_li("Home", :root) = menu_li("About", :about) = menu_li("Contact", :contact)
  • 7. Locales - Statische teksten » Locale - YAML (bijna net zo awesome als Haml) /config/locales/en.yml en: home: page_title: "Home" about: page_title: "About" contact: Meer weten? page_title: "Contact" http://guides.rubyonrails.org/ i18n.html Locale aanspreken = t("home.page_title")
  • 8. Asset pipeline Meer weten? http://guides.rubyonrails.org/ JavaScript, CSS en Images asset_pipeline.html /public = No-way /app/assets = Yes-way # => Speciaal voor jouw applicatie. /lib/assets = Yes-way # => Je eigen libraries. /vendor/assets = Yes-way # => Libraries van anderen. /app/assets/javascripts/application.js //= require jquery //= require jquery_ujs //= require_tree . /app/assets/stylesheets/application.css /* *= require_self *= require_tree . */
  • 9. SCSS = SASS + CSS syntax - Standaard in Rails 3.1 /app/assets/stylesheets/application.css.scss $primary-color: #500; $focus-color: #f00; @mixin menu { padding: 0; margin: 0; float: left; width: 100%; list-style: none; li { Meer weten? float: left; a { color: $primary-color; } http://sass-lang.com/ &.active a { color: $focus-color; } } } #menu { @include menu; }
  • 10. Haml - Makkelijker HTML schrijven - Beter dan ERB (duh) - 2 spaces (soft tab) - Lange regels = No-go %h1.my_class H1-tag met class %span#my_id Span-tag met id #header Div-tag met id .footer Div-tag met class = "Ruby code uitvoeren en laten zien" - "Ruby code uitvoeren en niet laten zien" Meer weten? / HTML comment %ul http://haml-lang.com/ %li Nesten doe je zo. %li En zo %li= "En zo met Ruby" %li{ :name => "attribuut" } %li(name="attribuut")