SlideShare a Scribd company logo
Secrets Of The
                          Asset Pipeline
                             Ken Collins
                            metaskills.net



Sunday, December 18, 11
The Foundation
     What makes the asset
     pipeline possible.




Sunday, December 18, 11
Hike


Sunday, December 18, 11
Hike
                      Hike is a Ruby library for
                      nding les in a set of paths.
                      Use it to implement search
                    paths, load paths, and the like.


Sunday, December 18, 11
Find Ruby Files In Your Project

           trail = Hike::Trail.new "/Users/sam/Projects/hike"
           trail.append_extension ".rb"
           trail.append_paths "lib", "test"

           trail.find "hike/trail"
           # => "/Users/sam/Projects/hike/lib/hike/trail.rb"

           trail.find "test_trail"
           # => "/Users/sam/Projects/hike/test/test_trail.rb"




Sunday, December 18, 11
Explore Your Shell Path

              trail = Hike::Trail.new "/"
              trail.append_paths *ENV["PATH"].split(":")

              trail.find "ls"
              # => "/bin/ls"

              trail.find "gem"
              # => "/Users/sam/.rvm/rubies/ree/bin/gem"




Sunday, December 18, 11
Digging Deeper
                    # Fallback logical paths. Equivalent.
                    trail.find "hike", "hike/index"
                    trail.find("hike") || trail.find("hike/index")

                    # Block yields multiple matches.
                    trail.find("application") do |path|
                      return path if mime_type_for(path) == "text/css"
                    end

                    # Like Dir#entries. Filters "." and "~" swap files.
                    trail.entries('/usr/local/bin')

                    # Like File.stat.
                    trail.stat('/usr/local/bin')

                    # Cached trail. Avoids excess system calls.
                    trail.index




Sunday, December 18, 11
Tilt


Sunday, December 18, 11
Tilt
                Tilt is a thin interface over a bunch of
            different Ruby template engines in an attempt
            to make their usage as generic possible. is is
                useful for web frameworks, static site
              generators, and other systems that support
             multiple template engines but don't want to
                 code for each of them individually.


Sunday, December 18, 11
Common Features




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.
                   Ability to pass locals to template evaluation.




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.
                   Ability to pass locals to template evaluation.
                   Support for passing a block to template eval for "yield".




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.
                   Ability to pass locals to template evaluation.
                   Support for passing a block to template eval for "yield".
                   Backtraces with correct filenames and line numbers.




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.
                   Ability to pass locals to template evaluation.
                   Support for passing a block to template eval for "yield".
                   Backtraces with correct filenames and line numbers.
                   Template file caching and reloading.




Sunday, December 18, 11
Common Features
                   Custom template evaluation scopes / bindings.
                   Ability to pass locals to template evaluation.
                   Support for passing a block to template eval for "yield".
                   Backtraces with correct filenames and line numbers.
                   Template file caching and reloading.
                   Fast, method-based template source compilation.




Sunday, December 18, 11
Engine        File Extension          Required Lib.
                            ERB             .erb, .rhtml         none (stdlib)
                 Interpolated String            .str              none (core)
                           Erubis       .erb, .rhtml, .erubis        erubis
                            Haml               .haml                 haml
                            Sass               .sass              sass (>= 3.1)
                            Scss               .scss              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
Sunday, December 18, 11
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



Sunday, December 18, 11
Really Simple!

               require 'erb'
               require 'tilt'

               template = Tilt.new('templates/foo.erb')
               #<Tilt::ERBTemplate @file="templates/foo.rb"...>

               template.render # => "Hello world!"




Sunday, December 18, 11
Evaluation Scope

             template = Tilt::ERBTemplate.new('templates/foo.erb')
             joe = Person.find('joe')
             output = template.render(joe, :x => 35, :y => 42)

             jane = Person.find('jane')
             output = template.render(jane, :x => 22, :y => nil)




Sunday, December 18, 11
Sprockets


Sunday, December 18, 11
Sprockets
                  Rack-based asset packaging for compiling
                      and serving web assets. It features
                   declarative dependency management for
                    JavaScript and CSS assets, as well as a
                  powerful preprocessor pipeline that allows
                     you to write assets in languages like
                     CoffeeScript, Sass, SCSS and LESS.


Sunday, December 18, 11
Rack Application
                      # In config.ru

                      require 'sprockets'

                      map '/assets' do
                        environment = Sprockets::Environment.new
                        environment.append_path 'app/assets/javascripts'
                        environment.append_path 'app/assets/stylesheets'
                        run environment
                      end

                      map '/' do
                        run YourRackApp
                      end




Sunday, December 18, 11
Renders Templates
                             modal.css.scss.erb

                   /* Multi-line comment blocks (CSS, SCSS, JavaScript)
                    *= require foo
                    */

                   // Single-line comment blocks (SCSS, JavaScript)
                   //= require foo

                   # Single-line comment blocks (CoffeeScript)
                   #= require foo




Sunday, December 18, 11
Best Practices
     How to wire
     it up right!




Sunday, December 18, 11
Dir. Structure     $ tree app/assets
                          |
                          !"" images
                          #   !"" app
                          #   #   !"" ...
                          #   $"" site
                          #       $"" ...
                          !"" javascripts
                          #   !"" application.js
                          #   |   $"" ...
                          #   !"" shared
                          #   #   !"" base.js.coffee
                          #   #   !"" modal.js.coffee.erb
                          #   #   $"" ...
                          #   !"" site
                          |   |   !"" base.js.coffee
                          #   |   !"" flash.js.coffee
                          #   |   $"" ...
                          |   $"" site.js
                          $"" stylesheets
                              !"" application
                              #   $"" application.css.scss
                              !"" application.css
                              !"" shared
                              #   !"" base.scss
                              #   !"" modal.css.scss
                              #   $"" ...
                              !"" site
                              #   !"" 960.css
                              #   $"" site.css.scss
                              $"" site.css




Sunday, December 18, 11
Dir. Structure                 $ tree app/assets
                                      |
                                      !"" images
                                      #   !"" app

               Directory Namespaces   #   #   !"" ...
                                      #   $"" site
                                      #       $"" ...
                                      !"" javascripts
                                      #   !"" application.js
                                      #   |   $"" ...
                                      #   !"" shared
                                      #   #   !"" base.js.coffee
                                      #   #   !"" modal.js.coffee.erb
                                      #   #   $"" ...
                                      #   !"" site
                                      |   |   !"" base.js.coffee
                                      #   |   !"" flash.js.coffee
                                      #   |   $"" ...
                                      |   $"" site.js
                                      $"" stylesheets
                                          !"" application
                                          #   $"" application.css.scss
                                          !"" application.css
                                          !"" shared
                                          #   !"" base.scss
                                          #   !"" modal.css.scss
                                          #   $"" ...
                                          !"" site
                                          #   !"" 960.css
                                          #   $"" site.css.scss
                                          $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared
                                         #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                                         |   |   !"" base.js.coffee
                                         #   |   !"" flash.js.coffee
                                         #   |   $"" ...
                                         |   $"" site.js
                                         $"" stylesheets
                                             !"" application
                                             #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared
                                             #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                                         |   |   !"" base.js.coffee
                                         #   |   !"" flash.js.coffee
                                         #   |   $"" ...
                                         |   $"" site.js
                                         $"" stylesheets
                                             !"" application
                                             #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared
                                             #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                  Require Tree Bad       |   |
                                         #   |
                                                 !"" base.js.coffee
                                                 !"" flash.js.coffee
                                         #   |   $"" ...
                                         |   $"" site.js
                                         $"" stylesheets
                                             !"" application
                                             #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared
                                             #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                  Require Tree Bad       |   |
                                         #   |
                                                 !"" base.js.coffee
                                                 !"" flash.js.coffee
                                         #   |   $"" ...
                                             $"" site.js
                  Try To Match With      |
                                         $"" stylesheets
                                             !"" application
                  Layout Names               #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared
                                             #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
site.js

                          //=   require   jquery-1.6.2.min
                          //=   require   jquery-ui-1.8.12.ui-darkness.min
                          //=   require   jquery_ujs
                          //=   require   shared/base
                          //=   require   shared/utils
                          //=   require   shared/modal
                          //=   require   shared/spinner
                          //=   require   site/quickie
                          //=   require   site/flash
                          //=   require   site/site




Sunday, December 18, 11
site.css

                          /*
                           *= require application/application
                           *= require shared/modal
                           *= require shared/utility
                          */




Sunday, December 18, 11
Precompile Additional Assets!
                             config/production.rb


                      # Precompile additional assets
                      # (application.js, application.css,
                      # and all non-JS/CSS are already added)
                      config.assets.precompile += ['site.js', 'site.css']




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                  Require Tree Bad       |   |
                                         #   |
                                                 !"" base.js.coffee
                                                 !"" flash.js.coffee
                                         #   |   $"" ...
                                             $"" site.js
                  Try To Match With      |
                                         $"" stylesheets
                                             !"" application
                  Layout Names               #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared
                                             #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                  Require Tree Bad       |   |
                                         #   |
                                                 !"" base.js.coffee
                                                 !"" flash.js.coffee
                                         #   |   $"" ...
                                             $"" site.js
                  Try To Match With      |
                                         $"" stylesheets
                                             !"" application
                  Layout Names               #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared

               Sub Files @import’ed          #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                                             #   !"" 960.css
                                             #   $"" site.css.scss
                                             $"" site.css




Sunday, December 18, 11
Dir. Structure                    $ tree app/assets
                                         |
                                         !"" images
                                         #   !"" app

               Directory Namespaces      #   #   !"" ...
                                         #   $"" site
                                         #       $"" ...
                                         !"" javascripts
               Manifest Only Top Files   #   !"" application.js
                                         #   |   $"" ...
                                         #   !"" shared

                  Generators Garbage     #   #   !"" base.js.coffee
                                         #   #   !"" modal.js.coffee.erb
                                         #   #   $"" ...
                                         #   !"" site
                  Require Tree Bad       |   |
                                         #   |
                                                 !"" base.js.coffee
                                                 !"" flash.js.coffee
                                         #   |   $"" ...
                                             $"" site.js
                  Try To Match With      |
                                         $"" stylesheets
                                             !"" application
                  Layout Names               #   $"" application.css.scss
                                             !"" application.css
                                             !"" shared

               Sub Files @import’ed          #   !"" base.scss
                                             #   !"" modal.css.scss
                                             #   $"" ...
                                             !"" site
                  Base Files Are             #   !"" 960.css
                                             #   $"" site.css.scss
                  Your Compass               $"" site.css




Sunday, December 18, 11
Base Files Are Your Compass
                          app/assets/stylesheets/shared/base.scss


                             $legacy-support-for-ie: false;
                             $experimental-support-for-opera: false;
                             $experimental-support-for-khtml: false;
                             @import "compass";
                             @import "compass/layout";


                          app/assets/stylesheets/shared/modal.scss


                             /*
                              *= depend_on shared/base.scss
                              */
                             @import "shared/base";




Sunday, December 18, 11
Advanced Usage
     Secrets of the
     asset pipeline.




Sunday, December 18, 11
Hooking Into Sprockets
           Rails.application.assets
           # => #<Sprockets::Environment:0x3fda9a195f8c root="/Repos/
           homemarks_app", paths=["/Repos/homemarks_app/app/assets/images",
           "/Repos/homemarks_app/app/assets/javascripts", "/Repos/
           homemarks_app/app/assets/stylesheets", "/Repos/homemarks_app/
           vendor/assets/javascripts", "/Repos/homemarks_app/vendor/assets/
           stylesheets", "/Users/ken/.rbenv/versions/1.9.3/lib/ruby/gems/
           1.9.1/gems/jquery-rails-1.0.13/vendor/assets/javascripts"],
           digest="46dde6621c301f4928e3b34efee9e3b5">




                          Or use the `asset_environment` helper.




Sunday, December 18, 11
Finding Assets
          #find_asset method (aliased as [])

           Rails.application.assets['shared/modal']
           # => #<Sprockets::BundledAsset:0x3fcd7e90c6cc pathname="/
           Repos/homemarks_app/app/assets/javascripts/shared/
           modal.js.coffee.erb", mtime=2011-11-25 17:41:11 -0500,
           digest="775822db3e101bf38d7978627380e62b">




Sunday, December 18, 11
Incomplete
                          * Advanced Usage
                            - Where is sprockets.
                              > Rails.application.assets (helpers can use asset_environment)
                            - Finding Assets.
                              #find_asset method (aliased as [])


              Notes
                              Rails.application.assets['shared/modal'] # => Sprockets::BundledAsset
                              Call to_s on the resulting asset to access its contents, length to get its length in bytes, mtime to
                          query its last-modified time, and pathname to get its full path on the filesystem.
                            - Asset Helpers. - image, asset-data-uri, etc.
                              Move all images to app/assets!!!
                              Rails.application.assets['site/hmlogo.png']
                              # => #<Sprockets::StaticAsset:0x3fda99465d08 pathname="/Users/kencollins/Repositories/
                          homemarks_app/app/assets/images/site/hmlogo.png", mtime=2011-11-16 19:31:44 -0500,
                          digest="eed9e6f3fd9fa546ccd7ce49edd99f49">
                            - Custom SASS
                            - Preprocessors.
                            - Assets in other assets.
                            - Precompiling. Fingerprints. When they are used.
                            - JavaScript Templating with EJS and Eco (read sprockets page)
                              - JST (define)
                              - EJS or Eco
                            - CSS Compressors (:uglifier default, but use :yui for both css/js)
                              group :assets do
                                # ...
                                gem 'yui-compressor', :require => 'yui/compressor'
                              end
                            - Your config/application.rb
                              if defined?(Bundler)
                                # If you precompile assets before deploying to production, use this line
                                Bundler.require *Rails.groups(:assets => %w(development test))
                                # If you want your assets lazily compiled in production, use this line
                                # Bundler.require(:default, :assets, Rails.env)
                              end

                          * CSS Frameworks.
                            - Less
                            - Stylus
                            - Sass
                              - http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#each-directive
                              - http://github.com/kuroir/SCSS.tmbundle
                            - Compass
                              - mate "$(bundle show compass)/frameworks/compass/stylesheets"



Sunday, December 18, 11
Thanks!
                           Ken Collins
                          metaskills.net



Sunday, December 18, 11

More Related Content

Similar to Secrets of the asset pipeline

OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
Randy Bias
 
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdfOpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
OpenStack Foundation
 
Smalltalk on rubinius
Smalltalk on rubiniusSmalltalk on rubinius
Smalltalk on rubinius
Konstantin Haase
 
Hands on with Ruby & MongoDB
Hands on with Ruby & MongoDBHands on with Ruby & MongoDB
Hands on with Ruby & MongoDB
Wynn Netherland
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
Dr Nic Williams
 
Breaking a riak cluster
Breaking a riak clusterBreaking a riak cluster
Breaking a riak cluster
Jeffrey Kirkell
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
Hiroshi SHIBATA
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)
Stoyan Zhekov
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Gems on Ruby
Gems on RubyGems on Ruby
Gems on Ruby
Hiroshi SHIBATA
 
MongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchMongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouch
Wynn Netherland
 
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Running High Performance & Fault-tolerant Elasticsearch Clusters on DockerRunning High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Sematext Group, Inc.
 
Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?
Pravin Mishra
 
Introduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf TrainingIntroduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf Training
Sean Cribbs
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)
Sebastian Cohnen
 
Querying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary IndicesQuerying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary Indices
Rusty Klophaus
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
MongoDB
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
alexismidon
 

Similar to Secrets of the asset pipeline (20)

OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
OpenStack Summit :: Redundancy Doesn't Always Mean "HA" or "Cluster"
 
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdfOpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
OpenStack-Design-Summit-HA-Pairs-Are-Not-The-Only-Answer copy.pdf
 
Smalltalk on rubinius
Smalltalk on rubiniusSmalltalk on rubinius
Smalltalk on rubinius
 
Hands on with Ruby & MongoDB
Hands on with Ruby & MongoDBHands on with Ruby & MongoDB
Hands on with Ruby & MongoDB
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Breaking a riak cluster
Breaking a riak clusterBreaking a riak cluster
Breaking a riak cluster
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Gems on Ruby
Gems on RubyGems on Ruby
Gems on Ruby
 
Using MRuby in a database
Using MRuby in a databaseUsing MRuby in a database
Using MRuby in a database
 
MongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchMongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouch
 
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Running High Performance & Fault-tolerant Elasticsearch Clusters on DockerRunning High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
 
Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?
 
Introduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf TrainingIntroduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf Training
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)
 
Querying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary IndicesQuerying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary Indices
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 

More from Ken Collins

Ruby struct
Ruby structRuby struct
Ruby struct
Ken Collins
 
Dominion Enterprises _H@&lt;k@th0n_
Dominion Enterprises _H@&lt;k@th0n_Dominion Enterprises _H@&lt;k@th0n_
Dominion Enterprises _H@&lt;k@th0n_Ken Collins
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
Ken Collins
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rbKen Collins
 
Oo java script class construction
Oo java script class constructionOo java script class construction
Oo java script class constructionKen Collins
 
Tool Time
Tool TimeTool Time
Tool Time
Ken Collins
 
Synchronizing Core Data With Rails
Synchronizing Core Data With RailsSynchronizing Core Data With Rails
Synchronizing Core Data With Rails
Ken Collins
 

More from Ken Collins (7)

Ruby struct
Ruby structRuby struct
Ruby struct
 
Dominion Enterprises _H@&lt;k@th0n_
Dominion Enterprises _H@&lt;k@th0n_Dominion Enterprises _H@&lt;k@th0n_
Dominion Enterprises _H@&lt;k@th0n_
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rb
 
Oo java script class construction
Oo java script class constructionOo java script class construction
Oo java script class construction
 
Tool Time
Tool TimeTool Time
Tool Time
 
Synchronizing Core Data With Rails
Synchronizing Core Data With RailsSynchronizing Core Data With Rails
Synchronizing Core Data With Rails
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

Secrets of the asset pipeline

  • 1. Secrets Of The Asset Pipeline Ken Collins metaskills.net Sunday, December 18, 11
  • 2. The Foundation What makes the asset pipeline possible. Sunday, December 18, 11
  • 4. Hike Hike is a Ruby library for nding les in a set of paths. Use it to implement search paths, load paths, and the like. Sunday, December 18, 11
  • 5. Find Ruby Files In Your Project trail = Hike::Trail.new "/Users/sam/Projects/hike" trail.append_extension ".rb" trail.append_paths "lib", "test" trail.find "hike/trail" # => "/Users/sam/Projects/hike/lib/hike/trail.rb" trail.find "test_trail" # => "/Users/sam/Projects/hike/test/test_trail.rb" Sunday, December 18, 11
  • 6. Explore Your Shell Path trail = Hike::Trail.new "/" trail.append_paths *ENV["PATH"].split(":") trail.find "ls" # => "/bin/ls" trail.find "gem" # => "/Users/sam/.rvm/rubies/ree/bin/gem" Sunday, December 18, 11
  • 7. Digging Deeper # Fallback logical paths. Equivalent. trail.find "hike", "hike/index" trail.find("hike") || trail.find("hike/index") # Block yields multiple matches. trail.find("application") do |path| return path if mime_type_for(path) == "text/css" end # Like Dir#entries. Filters "." and "~" swap files. trail.entries('/usr/local/bin') # Like File.stat. trail.stat('/usr/local/bin') # Cached trail. Avoids excess system calls. trail.index Sunday, December 18, 11
  • 9. Tilt Tilt is a thin interface over a bunch of different Ruby template engines in an attempt to make their usage as generic possible. is is useful for web frameworks, static site generators, and other systems that support multiple template engines but don't want to code for each of them individually. Sunday, December 18, 11
  • 11. Common Features Custom template evaluation scopes / bindings. Sunday, December 18, 11
  • 12. Common Features Custom template evaluation scopes / bindings. Ability to pass locals to template evaluation. Sunday, December 18, 11
  • 13. Common Features Custom template evaluation scopes / bindings. Ability to pass locals to template evaluation. Support for passing a block to template eval for "yield". Sunday, December 18, 11
  • 14. Common Features Custom template evaluation scopes / bindings. Ability to pass locals to template evaluation. Support for passing a block to template eval for "yield". Backtraces with correct filenames and line numbers. Sunday, December 18, 11
  • 15. Common Features Custom template evaluation scopes / bindings. Ability to pass locals to template evaluation. Support for passing a block to template eval for "yield". Backtraces with correct filenames and line numbers. Template file caching and reloading. Sunday, December 18, 11
  • 16. Common Features Custom template evaluation scopes / bindings. Ability to pass locals to template evaluation. Support for passing a block to template eval for "yield". Backtraces with correct filenames and line numbers. Template file caching and reloading. Fast, method-based template source compilation. Sunday, December 18, 11
  • 17. Engine File Extension Required Lib. ERB .erb, .rhtml none (stdlib) Interpolated String .str none (core) Erubis .erb, .rhtml, .erubis erubis Haml .haml haml Sass .sass sass (>= 3.1) Scss .scss 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 Sunday, December 18, 11
  • 18. 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 Sunday, December 18, 11
  • 19. Really Simple! require 'erb' require 'tilt' template = Tilt.new('templates/foo.erb') #<Tilt::ERBTemplate @file="templates/foo.rb"...> template.render # => "Hello world!" Sunday, December 18, 11
  • 20. Evaluation Scope template = Tilt::ERBTemplate.new('templates/foo.erb') joe = Person.find('joe') output = template.render(joe, :x => 35, :y => 42) jane = Person.find('jane') output = template.render(jane, :x => 22, :y => nil) Sunday, December 18, 11
  • 22. Sprockets Rack-based asset packaging for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets, as well as a powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass, SCSS and LESS. Sunday, December 18, 11
  • 23. Rack Application # In config.ru require 'sprockets' map '/assets' do environment = Sprockets::Environment.new environment.append_path 'app/assets/javascripts' environment.append_path 'app/assets/stylesheets' run environment end map '/' do run YourRackApp end Sunday, December 18, 11
  • 24. Renders Templates modal.css.scss.erb /* Multi-line comment blocks (CSS, SCSS, JavaScript) *= require foo */ // Single-line comment blocks (SCSS, JavaScript) //= require foo # Single-line comment blocks (CoffeeScript) #= require foo Sunday, December 18, 11
  • 25. Best Practices How to wire it up right! Sunday, December 18, 11
  • 26. Dir. Structure $ tree app/assets | !"" images #   !"" app #   #   !"" ... #   $"" site #   $"" ... !"" javascripts #   !"" application.js #   | $"" ... #   !"" shared #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site | | !"" base.js.coffee #   | !"" flash.js.coffee #   | $"" ... | $"" site.js $"" stylesheets !"" application #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 27. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts #   !"" application.js #   | $"" ... #   !"" shared #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site | | !"" base.js.coffee #   | !"" flash.js.coffee #   | $"" ... | $"" site.js $"" stylesheets !"" application #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 28. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site | | !"" base.js.coffee #   | !"" flash.js.coffee #   | $"" ... | $"" site.js $"" stylesheets !"" application #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 29. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site | | !"" base.js.coffee #   | !"" flash.js.coffee #   | $"" ... | $"" site.js $"" stylesheets !"" application #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 30. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site Require Tree Bad | | #   | !"" base.js.coffee !"" flash.js.coffee #   | $"" ... | $"" site.js $"" stylesheets !"" application #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 31. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site Require Tree Bad | | #   | !"" base.js.coffee !"" flash.js.coffee #   | $"" ... $"" site.js Try To Match With | $"" stylesheets !"" application Layout Names #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 32. site.js //= require jquery-1.6.2.min //= require jquery-ui-1.8.12.ui-darkness.min //= require jquery_ujs //= require shared/base //= require shared/utils //= require shared/modal //= require shared/spinner //= require site/quickie //= require site/flash //= require site/site Sunday, December 18, 11
  • 33. site.css /* *= require application/application *= require shared/modal *= require shared/utility */ Sunday, December 18, 11
  • 34. Precompile Additional Assets! config/production.rb # Precompile additional assets # (application.js, application.css, # and all non-JS/CSS are already added) config.assets.precompile += ['site.js', 'site.css'] Sunday, December 18, 11
  • 35. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site Require Tree Bad | | #   | !"" base.js.coffee !"" flash.js.coffee #   | $"" ... $"" site.js Try To Match With | $"" stylesheets !"" application Layout Names #   $"" application.css.scss !"" application.css !"" shared #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 36. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site Require Tree Bad | | #   | !"" base.js.coffee !"" flash.js.coffee #   | $"" ... $"" site.js Try To Match With | $"" stylesheets !"" application Layout Names #   $"" application.css.scss !"" application.css !"" shared Sub Files @import’ed #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site #   !"" 960.css #   $"" site.css.scss $"" site.css Sunday, December 18, 11
  • 37. Dir. Structure $ tree app/assets | !"" images #   !"" app Directory Namespaces #   #   !"" ... #   $"" site #   $"" ... !"" javascripts Manifest Only Top Files #   !"" application.js #   | $"" ... #   !"" shared Generators Garbage #   #   !"" base.js.coffee #   #   !"" modal.js.coffee.erb #   #   $"" ... #   !"" site Require Tree Bad | | #   | !"" base.js.coffee !"" flash.js.coffee #   | $"" ... $"" site.js Try To Match With | $"" stylesheets !"" application Layout Names #   $"" application.css.scss !"" application.css !"" shared Sub Files @import’ed #   !"" base.scss #   !"" modal.css.scss #   $"" ... !"" site Base Files Are #   !"" 960.css #   $"" site.css.scss Your Compass $"" site.css Sunday, December 18, 11
  • 38. Base Files Are Your Compass app/assets/stylesheets/shared/base.scss $legacy-support-for-ie: false; $experimental-support-for-opera: false; $experimental-support-for-khtml: false; @import "compass"; @import "compass/layout"; app/assets/stylesheets/shared/modal.scss /* *= depend_on shared/base.scss */ @import "shared/base"; Sunday, December 18, 11
  • 39. Advanced Usage Secrets of the asset pipeline. Sunday, December 18, 11
  • 40. Hooking Into Sprockets Rails.application.assets # => #<Sprockets::Environment:0x3fda9a195f8c root="/Repos/ homemarks_app", paths=["/Repos/homemarks_app/app/assets/images", "/Repos/homemarks_app/app/assets/javascripts", "/Repos/ homemarks_app/app/assets/stylesheets", "/Repos/homemarks_app/ vendor/assets/javascripts", "/Repos/homemarks_app/vendor/assets/ stylesheets", "/Users/ken/.rbenv/versions/1.9.3/lib/ruby/gems/ 1.9.1/gems/jquery-rails-1.0.13/vendor/assets/javascripts"], digest="46dde6621c301f4928e3b34efee9e3b5"> Or use the `asset_environment` helper. Sunday, December 18, 11
  • 41. Finding Assets #find_asset method (aliased as []) Rails.application.assets['shared/modal'] # => #<Sprockets::BundledAsset:0x3fcd7e90c6cc pathname="/ Repos/homemarks_app/app/assets/javascripts/shared/ modal.js.coffee.erb", mtime=2011-11-25 17:41:11 -0500, digest="775822db3e101bf38d7978627380e62b"> Sunday, December 18, 11
  • 42. Incomplete * Advanced Usage - Where is sprockets. > Rails.application.assets (helpers can use asset_environment) - Finding Assets. #find_asset method (aliased as []) Notes Rails.application.assets['shared/modal'] # => Sprockets::BundledAsset Call to_s on the resulting asset to access its contents, length to get its length in bytes, mtime to query its last-modified time, and pathname to get its full path on the filesystem. - Asset Helpers. - image, asset-data-uri, etc. Move all images to app/assets!!! Rails.application.assets['site/hmlogo.png'] # => #<Sprockets::StaticAsset:0x3fda99465d08 pathname="/Users/kencollins/Repositories/ homemarks_app/app/assets/images/site/hmlogo.png", mtime=2011-11-16 19:31:44 -0500, digest="eed9e6f3fd9fa546ccd7ce49edd99f49"> - Custom SASS - Preprocessors. - Assets in other assets. - Precompiling. Fingerprints. When they are used. - JavaScript Templating with EJS and Eco (read sprockets page) - JST (define) - EJS or Eco - CSS Compressors (:uglifier default, but use :yui for both css/js) group :assets do # ... gem 'yui-compressor', :require => 'yui/compressor' end - Your config/application.rb if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end * CSS Frameworks. - Less - Stylus - Sass - http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#each-directive - http://github.com/kuroir/SCSS.tmbundle - Compass - mate "$(bundle show compass)/frameworks/compass/stylesheets" Sunday, December 18, 11
  • 43. Thanks! Ken Collins metaskills.net Sunday, December 18, 11