SlideShare una empresa de Scribd logo
1 de 25
Rails 3.1: Asset Pipeline
         James Daniels
About me
            @danielsju6 Boston, MA
   Entrepreneur & Rails Developer; Founder of
@marginleft, @accelgolf, lead on @appblade, over
user of CamelCase, and a @techstars Boston Alum
appblade.com
Makes mobile provisioning, beta tests,
and enterprise deployments not suck.
    SERIOUSLY CHECK IT OUT.
Rails 3.1: Asset Pipeline
      “Like a boss”
         James Daniels
The problem
The problem
The problem
The problem

• Third-party code mixed into yours
• JS/CSS/IMG treated as second class citizens
• Organization is fucked
• JavaScript in views
• Who uses :cache => true anyway
The problem


•   /public is a fucking junk drawer
The solution
/app
   /assets
     /javascripts
     /stylesheets
     /images
/lib
   /assets
     /...
/vendor
   /assets
     /...
The solution
/app
   /assets          gem ‘jquery-rails’
     /javascripts
     /stylesheets   //=
require
modernizr
     /images        //=
require
jquery
                    //=
require
jquery_ujs
/lib                //=
require
jqueryui
   /assets          //=
require
underscore
     /...           //=
require
backbone
                    //=
require_tree
.
/vendor
   /assets
     /...
The solution
//=
require_tree
.
requires
app/assets/javascripts/**/*
The solution

/=   require_tree .
/=   require_self
/=   require_directory ‘posts’
/=   include ‘file’
/=   depend_on ‘file.png’
/=   provide ‘something’
The solution
• rails generate scaffold post
  invoke


assets
  create




app/assets/javascripts/posts.js
  invoke


css
  create




app/assets/stylesheets/users.css
  invoke


css
  create




app/assets/stylesheets/_scaffold.css
Features
• Cache friendly static filenames
  application‐908e25f4bf641868d8683022a5b62f54.css


• Asset organization
• Links to assets
• Pre-processing
  projects.css.scss.erb


• Post-processing
Sprockets
• Manifest files to load js/css
  app/assets/javascripts/application.js
  app/assets/stylesheets/application.css


• Coffeescript, less, sass, scss, erb
• Assets brought in by gems
  //=
require
modernizr
  //=
require
jquery
  //=
require
jquery_ujs
  //=
require
jqueryui
  //=
require
underscore
  //=
require
backbone
  //=
require_tree
.
Coffeescript... meh
• Language that compiles to javascript
   hopefully Mark convinced you and me on this

 # Assignment:              # Objects:
 number   = 42              math =
 opposite = true              root:    Math.sqrt
                              square: square
                              cube:    (x) -> x * square x
 # Conditions:
 number = -42 if opposite   # Splats:
                            race = (winner, runners...) ->
 # Functions:                 print winner, runners
 square = (x) -> x * x
                            # Existence:
                            alert "I knew it!" if elvis?
 # Arrays:
 list = [1, 2, 3, 4, 5]
                            # Array comprehensions:
                            cubes = (math.cube num for num in list)
Javascript compression

•   config.assets.js_compressor
=
:uglifier



• Uses execjs which needs to have a
    javascript runtime
    node.js, ‘therubyracer’, ‘mustang’, etc.
Sass... FUCK YEAH!
    $blue: #3bbfce;
    $margin: 16px;

    .content-navigation {
      border-color: $blue;
      color:
        darken($blue, 9%);
    }

    .border {
      padding: $margin / 2;
      margin: $margin / 2;
      border-color: $blue;
    }
Checkout Bourbon
        • Vendor specific SCSS helpers
#Functions                                  #Mixins                                  #More mixins
--------------------------------            --------------------------------         --------------------------------
  compact(*args)                              animation                                @ inline-block
  golden-ratio(*args)                           @ animation(*args)                     @ linear-gradient(*args)
  linear-gradient(*args)                        @ animation-basic(*args)               @ radial-gradient(*args)
  grid-width(*args)                             @ animation-delay(*args)               @ transform(*args)
  shade(*args)                                  @ animation-direction(*args)
  tint(*args)                                   @ animation-duration(*args)           transition
                                                @ animation-fill-mode(*args)            @ transition(*args)
                                                @ animation-iteration-count(*args)      @ transition-delay(*args)
#Addons                                         @ animation-name(*args)                 @ transition-duration(*args)
--------------------------------                @ animation-play-state(*args)           @ transition-property(*args)
  animation-keyframes (fade-in, fade-out)       @ animation-timing-function(*args)      @ transition-timing-function(*args)
@ button(*args)
@ position(*args)                            @   background-image(*args)
                                             @   border-radius(*args)
                                             @   box-shadow(*args)
                                             @   box-sizing(*args)

                                             flex-box
                                               @ box(*args)
                                               @ box-align(*args)
                                               @ box-direction(*args)
                                               @ box-flex(*args)
                                               @ box-flex-group(*args)
                                               @ box-lines(*args)
                                               @ box-ordinal-group(*args)
                                               @ box-orient(*args)
                                               @ box-pack(*args)
                                               @ display-box
Asset dependencies
/*
 *= require blueprint/reset
 *= require blueprint/typography
 */
body {
  background: url(<%= asset_path "fuck_coffeescript_this_is_cool.png" %>);
}
Tilt
ENGINE                       FILE EXTENSIONS           REQUIRED LIBRARIES
--------------------------   -----------------------   ----------------------------
ERB                          .erb, .rhtml              none (included ruby stdlib)
Interpolated String          .str                      none (included ruby core)
Erubis                       .erb, .rhtml, .erubis     erubis
Haml                         .haml                     haml
Sass                         .sass                     haml (< 3.1) or sass (>= 3.1)
Scss                         .scss                     haml (< 3.1) or sass (>= 3.1)
Less CSS                     .less                     less
Builder                      .builder                  builder
Liquid                       .liquid                   liquid
RDiscount                    .markdown, .mkd, .md      rdiscount
Redcarpet                    .markdown, .mkd, .md      redcarpet
BlueCloth                    .markdown, .mkd, .md      bluecloth
Kramdown                     .markdown, .mkd, .md      kramdown
Maruku                       .markdown, .mkd, .md      maruku
RedCloth                     .textile                  redcloth
RDoc                         .rdoc                     rdoc
Radius                       .radius                   radius
Markaby                      .mab                      markaby
Nokogiri                     .nokogiri                 nokogiri
CoffeeScript                 .coffee                   coffee-script (+ javascript)
Creole (Wiki markup)         .wiki, .creole            creole
WikiCloth (Wiki markup)      .wiki, .mediawiki, .mw    wikicloth
Yajl                         .yajl                     yajl-ruby
Production

• Pre-compilation
• Capistrano
  before :"deploy:symlink", :"deploy:assets";

  desc "Compile asets"
  task :assets do
    run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
  end
That’s all folks


• gem install rails --pre
• Rails guides are being updated

Más contenido relacionado

La actualidad más candente

Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS LayoutRachel Andrew
 
Upgrading to Rails 3
Upgrading to Rails 3Upgrading to Rails 3
Upgrading to Rails 3juliangiuca
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
CSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NERachel Andrew
 
CSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoCSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoRachel Andrew
 
Introducing CSS Grid Layout
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid LayoutRachel Andrew
 
Talk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutRachel Andrew
 
AEA Chicago CSS Grid Layout
AEA Chicago CSS Grid LayoutAEA Chicago CSS Grid Layout
AEA Chicago CSS Grid LayoutRachel Andrew
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The ServerPerconaPerformance
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real WorldRachel Andrew
 
CSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenCSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenRachel Andrew
 
Introducción rápida a SQL
Introducción rápida a SQLIntroducción rápida a SQL
Introducción rápida a SQLCarlos Hernando
 
Render Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRachel Andrew
 
CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureCSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureRachel Andrew
 
Future Layout & Performance
Future Layout & PerformanceFuture Layout & Performance
Future Layout & PerformanceRachel Andrew
 

La actualidad más candente (20)

Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS Layout
 
Upgrading to Rails 3
Upgrading to Rails 3Upgrading to Rails 3
Upgrading to Rails 3
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
CSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NE
 
Next-level CSS
Next-level CSSNext-level CSS
Next-level CSS
 
CSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoCSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart Orlando
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
 
Introducing CSS Grid Layout
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid Layout
 
Talk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid Layout
 
AEA Chicago CSS Grid Layout
AEA Chicago CSS Grid LayoutAEA Chicago CSS Grid Layout
AEA Chicago CSS Grid Layout
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The Server
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real World
 
DataMapper
DataMapperDataMapper
DataMapper
 
CSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenCSS Grid Layout - All Things Open
CSS Grid Layout - All Things Open
 
Merb
MerbMerb
Merb
 
Introducción rápida a SQL
Introducción rápida a SQLIntroducción rápida a SQL
Introducción rápida a SQL
 
Render Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout Today
 
CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureCSSConf.asia - Laying out the future
CSSConf.asia - Laying out the future
 
Future Layout & Performance
Future Layout & PerformanceFuture Layout & Performance
Future Layout & Performance
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 

Similar a Rails 3.1 Asset Pipeline

TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyFabio Akita
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
Riak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup GroupRiak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup Groupsiculars
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Trickssiculars
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemMaithreya Chakravarthula
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartConanandvns
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik ErlandsonDatabricks
 
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...Databricks
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 

Similar a Rails 3.1 Asset Pipeline (20)

TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em Ruby
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Riak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup GroupRiak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup Group
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Tricks
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartCon
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Groovy
GroovyGroovy
Groovy
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Dart
DartDart
Dart
 
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
 
Scala active record
Scala active recordScala active record
Scala active record
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 

Último

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
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
 
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
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Último (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
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.
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Rails 3.1 Asset Pipeline

  • 1. Rails 3.1: Asset Pipeline James Daniels
  • 2. About me @danielsju6 Boston, MA Entrepreneur & Rails Developer; Founder of @marginleft, @accelgolf, lead on @appblade, over user of CamelCase, and a @techstars Boston Alum
  • 3. appblade.com Makes mobile provisioning, beta tests, and enterprise deployments not suck. SERIOUSLY CHECK IT OUT.
  • 4. Rails 3.1: Asset Pipeline “Like a boss” James Daniels
  • 8. The problem • Third-party code mixed into yours • JS/CSS/IMG treated as second class citizens • Organization is fucked • JavaScript in views • Who uses :cache => true anyway
  • 9. The problem • /public is a fucking junk drawer
  • 10.
  • 11. The solution /app /assets /javascripts /stylesheets /images /lib /assets /... /vendor /assets /...
  • 12. The solution /app /assets gem ‘jquery-rails’ /javascripts /stylesheets //=
require
modernizr /images //=
require
jquery //=
require
jquery_ujs /lib //=
require
jqueryui /assets //=
require
underscore /... //=
require
backbone //=
require_tree
. /vendor /assets /...
  • 14. The solution /= require_tree . /= require_self /= require_directory ‘posts’ /= include ‘file’ /= depend_on ‘file.png’ /= provide ‘something’
  • 15. The solution • rails generate scaffold post invoke


assets create




app/assets/javascripts/posts.js invoke


css create




app/assets/stylesheets/users.css invoke


css create




app/assets/stylesheets/_scaffold.css
  • 16. Features • Cache friendly static filenames application‐908e25f4bf641868d8683022a5b62f54.css • Asset organization • Links to assets • Pre-processing projects.css.scss.erb • Post-processing
  • 17. Sprockets • Manifest files to load js/css app/assets/javascripts/application.js app/assets/stylesheets/application.css • Coffeescript, less, sass, scss, erb • Assets brought in by gems //=
require
modernizr //=
require
jquery //=
require
jquery_ujs //=
require
jqueryui //=
require
underscore //=
require
backbone //=
require_tree
.
  • 18. Coffeescript... meh • Language that compiles to javascript hopefully Mark convinced you and me on this # Assignment: # Objects: number = 42 math = opposite = true root: Math.sqrt square: square cube: (x) -> x * square x # Conditions: number = -42 if opposite # Splats: race = (winner, runners...) -> # Functions: print winner, runners square = (x) -> x * x # Existence: alert "I knew it!" if elvis? # Arrays: list = [1, 2, 3, 4, 5] # Array comprehensions: cubes = (math.cube num for num in list)
  • 19. Javascript compression • config.assets.js_compressor
=
:uglifier • Uses execjs which needs to have a javascript runtime node.js, ‘therubyracer’, ‘mustang’, etc.
  • 20. Sass... FUCK YEAH! $blue: #3bbfce; $margin: 16px; .content-navigation { border-color: $blue; color: darken($blue, 9%); } .border { padding: $margin / 2; margin: $margin / 2; border-color: $blue; }
  • 21. Checkout Bourbon • Vendor specific SCSS helpers #Functions #Mixins #More mixins -------------------------------- -------------------------------- -------------------------------- compact(*args) animation @ inline-block golden-ratio(*args) @ animation(*args) @ linear-gradient(*args) linear-gradient(*args) @ animation-basic(*args) @ radial-gradient(*args) grid-width(*args) @ animation-delay(*args) @ transform(*args) shade(*args) @ animation-direction(*args) tint(*args) @ animation-duration(*args) transition @ animation-fill-mode(*args) @ transition(*args) @ animation-iteration-count(*args) @ transition-delay(*args) #Addons @ animation-name(*args) @ transition-duration(*args) -------------------------------- @ animation-play-state(*args) @ transition-property(*args) animation-keyframes (fade-in, fade-out) @ animation-timing-function(*args) @ transition-timing-function(*args) @ button(*args) @ position(*args) @ background-image(*args) @ border-radius(*args) @ box-shadow(*args) @ box-sizing(*args) flex-box @ box(*args) @ box-align(*args) @ box-direction(*args) @ box-flex(*args) @ box-flex-group(*args) @ box-lines(*args) @ box-ordinal-group(*args) @ box-orient(*args) @ box-pack(*args) @ display-box
  • 22. Asset dependencies /*  *= require blueprint/reset  *= require blueprint/typography  */ body {   background: url(<%= asset_path "fuck_coffeescript_this_is_cool.png" %>); }
  • 23. Tilt ENGINE FILE EXTENSIONS REQUIRED LIBRARIES -------------------------- ----------------------- ---------------------------- ERB .erb, .rhtml none (included ruby stdlib) Interpolated String .str none (included ruby core) Erubis .erb, .rhtml, .erubis erubis Haml .haml haml Sass .sass haml (< 3.1) or sass (>= 3.1) Scss .scss haml (< 3.1) or sass (>= 3.1) Less CSS .less less Builder .builder builder Liquid .liquid liquid RDiscount .markdown, .mkd, .md rdiscount Redcarpet .markdown, .mkd, .md redcarpet BlueCloth .markdown, .mkd, .md bluecloth Kramdown .markdown, .mkd, .md kramdown Maruku .markdown, .mkd, .md maruku RedCloth .textile redcloth RDoc .rdoc rdoc Radius .radius radius Markaby .mab markaby Nokogiri .nokogiri nokogiri CoffeeScript .coffee coffee-script (+ javascript) Creole (Wiki markup) .wiki, .creole creole WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth Yajl .yajl yajl-ruby
  • 24. Production • Pre-compilation • Capistrano before :"deploy:symlink", :"deploy:assets"; desc "Compile asets" task :assets do   run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile" end
  • 25. That’s all folks • gem install rails --pre • Rails guides are being updated

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n