From 09dd03095a1c93e6e9fdf87f889acc157bd2e360 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:12:31 +0530 Subject: [PATCH 1/5] some corrections in assets pipeline guide --- railties/guides/source/asset_pipeline.textile | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 5884ff7e66..9f80a5e96c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -13,7 +13,7 @@ endprologue. h3. What is the Asset Pipeline? -The asset pipeline provides a framework to concatenate and minify or compress Javascript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB. +The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 includes the +sprockets-rails+ gem, which depends on the +sprockets+ gem, by default. @@ -22,7 +22,7 @@ By having this as a core feature of Rails, all developers can benefit from the p In new Rails 3.1 application the asset pipeline is enable by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition: - config.assets.enabled = false +config.assets.enabled = false It is recommended that you use the defaults for all new apps. @@ -36,7 +36,7 @@ The default behavior in Rails 3.1 and onward is to concatenate all files into on The second feature is to minify or compress. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. -The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for Javascript, and ERB for both. +The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both. h4. What is Fingerprinting and Why Should I Care? @@ -63,19 +63,17 @@ This has several disadvantages:
  1. Not all caches will cache content with a query string
    - "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
  2. -
  3. - The filename can change between nodes in multi-server environments.
    - The query string in Rails is based on the files mtime (mtime is the file modification time). When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request. + The file name can change between nodes in multi-server environments.
    + The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
-The other problems is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. +The other problem is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. -Fingerprinting avoids all these problems be ensuring filenames are consistent based on the content. +Fingerprinting avoids all these problems by ensuring filenames are consistent based on the content. More reading: @@ -112,20 +110,20 @@ To access assets, we can use the same tags that we are generally familiar with: Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application" %> +<%= stylesheet_link_tag "application" %> +<%= javascript_include_tag "application" %> In regular views you can access images in the +assets/images+ directory like this: - <%= image_tag "rails.png" %> +<%= image_tag "rails.png" %> Images can be organized into directories if required, and they can be accessed by specifying the directory's name in the tag: - <%= image_tag "icons/rails.png" %> +<%= image_tag "icons/rails.png" %> Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. @@ -134,22 +132,21 @@ Alternatively, a file with an MD5 hash after its name such as +public/assets/rai Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. -If you want to use a "css data uri":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. +If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. - - #logo { background: url(<%= asset_data_uri 'logo.png' %>) - - -This will insert a correctly formatted data uri into the CSS source. + +#logo { background: url(<%= asset_data_uri 'logo.png' %>) + +This will insert a correctly formatted data URI into the CSS source. h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+ then you can use the +asset_path+ helper in your CSS rules: - + .class{background-image:<%= asset_path 'image.png' %>} - + This will write the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file then that path will be referenced. @@ -229,15 +226,15 @@ You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sp By default, this would only render this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout: - + When the +debug_assets+ parameter is set, this line will be expanded out into three separate lines, separating out the combined file into their parts. - - - + + + This allows the individual parts of an asset to be rendered and debugged separately. @@ -279,7 +276,7 @@ before 'deploy:symlink' do end -If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. +If you are not precompiling your assets, and you are using the default cache file store (which is the file system), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure in order to persist the cached file between deployments. TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35). @@ -289,7 +286,7 @@ The default matcher for compiling files will include +application.js+, +applicat [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] -If you have other manifests or individual stylesheet and javascript files to include, you can append them to the +precompile+ array: +If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array: config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js'] @@ -335,23 +332,23 @@ config.assets.css_compressor = :yui The +config.assets.compress+ must be set to +true+ to enable CSS compression -h4. Javascript +h4. JavaScript -Possible options for Javascript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. +Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. -The following line will invoke uglifier for Javascript compression. +The following line will invoke uglifier for JavaScript compression. config.assets.js_compressor = :uglifier -The +config.assets.compress+ must be set to +true+ to enable Javascript compression +The +config.assets.compress+ must be set to +true+ to enable JavaScript compression h4. Using Your Own Compressor -The compressor config settings for CSS and Javascript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. +The compressor config settings for CSS and JavaScript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. class Transformer @@ -382,9 +379,9 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr h4. X-Sendfile Headers -The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the server to do work. Files are faster served by the webserver. Both Apache and nginx support this option. +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the web server to do the file serving, which is usually faster. Both Apache and nginx support this option. -New applications contain this line in +production.rb+ +The configuration is available in config/environments/production.rb. config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx @@ -392,11 +389,11 @@ config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' You should check that your server or hosting service actually supports this, otherwise comment it out. -Gotcha: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+ ). +WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behaviour. h3. How Caching Works -Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production. +Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is file names are fingerprinted and get far-future headers in production. TODO: Add more about changing the default store. From 4885e5d3ebffa4a95f98dcedfeed9613308377d0 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:19:40 +0530 Subject: [PATCH 2/5] minor corrections in form helpers guide and api docs --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- railties/guides/source/form_helpers.textile | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index e730526163..5b41750b52 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -864,7 +864,7 @@ module ActionView # some browsers # # ==== Examples - # + # # search_field(:user, :name) # # => # search_field(:user, :name, :autosave => false) @@ -900,7 +900,7 @@ module ActionView # Returns a text_field of type "tel". # - # telephone_field("user", "phone") + # telephone_field("user", "phone") # # => def telephone_field(object_name, method, options = {}) diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index e10620272b..96a52af612 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -177,12 +177,12 @@ Other form controls worth mentioning are the text area, password input, hidden i <%= password_field_tag(:password) %> <%= hidden_field_tag(:parent_id, "5") %> <%= search_field(:user, :name) %> -<%= telephone_field(:user, :phone) %> -<%= url_field(:user, "homepage) %> +<%= telephone_field(:user, :phone) %> +<%= url_field(:user, :homepage) %> <%= email_field(:user, :address) %> -output: +Output: @@ -194,8 +194,7 @@ output: -Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. The search, tel, url and email inputs are specified in HTML5 and may receive special handling and/or formatting -in some user-agents. +Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. The search, tel, url and email inputs are specified in HTML5 and may receive special handling and/or formatting in some user-agents. TIP: If you're using password input fields (for any purpose), you might want to configure your application to prevent those parameters from being logged. From 4719543c80a243655b584f512f333818638089cb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:34:24 +0530 Subject: [PATCH 3/5] reword select_date's behaviour clearly when an incomplete options array is passed --- actionpack/lib/action_view/helpers/date_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 0ef84fb0b6..417ba11fd3 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -8,7 +8,7 @@ module ActionView module Helpers # = Action View Date Helpers # - # The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time + # The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time # elements. All of the select-type methods share a number of common options that are as follows: # # * :prefix - overwrites the default prefix of "date" used for the select names. So specifying "birthday" @@ -343,8 +343,8 @@ module ActionView # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. # It's possible to explicitly set the order of the tags using the :order option with an array of - # symbols :year, :month and :day in the desired order. If you do not supply a symbol - # then all tags will be hidden. + # symbols :year, :month and :day in the desired order. + # If the array passed to the :order option does not contain all the three symbols, all tags will be hidden. # # If anything is passed in the html_options hash it will be applied to every select tag in the set. # From 4a54e404882708ee8b691ec8de9b663954f8b683 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:44:06 +0530 Subject: [PATCH 4/5] Fixing the incorrect change made in bae54c5 --- railties/guides/source/asset_pipeline.textile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 9f80a5e96c..8b3550b4b7 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -405,7 +405,4 @@ A good example of this is the +jquery-rails+ gem which comes with Rails as the s h3. Making Your Library or Gem a Pre-Processor -"You should be able to register [your gems] on "Tilt":Tilt and Sprockets will find them." - Josh -[Tilt]https://github.com/rtomayko/tilt - - +TODO: Registering gems on "Tilt":https://github.com/rtomayko/tilt enabling Sprockets to find them. From 46be69a220cf1815320ecdd7595d8fa37dcb5fd5 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:54:48 +0530 Subject: [PATCH 5/5] spacing fix --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 556aed19cf..b5b4c2becc 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -73,7 +73,7 @@ module Rails # == Paths # # Since Rails 3.0, applications and engines have more flexible path configuration (as - # opposed to the previous hardcoded path configuration). This means that you are not + # opposed to the previous hardcoded path configuration). This means that you are not # required to place your controllers at app/controllers, but in any place # which you find convenient. #