aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-08-15 21:46:21 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-08-15 21:46:21 +0530
commitc0c5d5fd2e40f89fa56bf1c6785a392077f4263a (patch)
treecc0c75f4789f0eb1b0f826d987cd9bcfd57d7a20
parentb8363f84da3356d66a7b30b8d180ad01eb7e0eb3 (diff)
downloadrails-c0c5d5fd2e40f89fa56bf1c6785a392077f4263a.tar.gz
rails-c0c5d5fd2e40f89fa56bf1c6785a392077f4263a.tar.bz2
rails-c0c5d5fd2e40f89fa56bf1c6785a392077f4263a.zip
assets guide - add info about require_directory, minor rephrasings
-rw-r--r--railties/guides/source/asset_pipeline.textile12
1 files changed, 7 insertions, 5 deletions
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8a4d61dc3a..a83226aa21 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -166,7 +166,7 @@ The more generic form can also be used but the asset path and class must both be
h4. Manifest Files and Directives
-Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time is greatly reduced as there is not as many requests to make for each file.
+Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are not as many requests to make.
For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines:
@@ -176,9 +176,11 @@ For example, in the default Rails application there's a +app/assets/javascripts/
//= require_tree .
</plain>
-In JavaScript files, directives begin with +//=+. In this case, the following file is using the +require+ directive and the +require_tree+ directive. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require
+In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets what are the files that we would like to require. Here, we are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. We need not supply the extensions explicitly. Sprockets will assume we are requiring a +.js+ file when done from within a +.js+ file.
-The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified.
+NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem.
+
+The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
There's also a default +app/assets/stylesheets/application.css+ file which contains these lines:
@@ -344,10 +346,10 @@ Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yu
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.
<erb>
-config.assets.js_compressor = :uglifier
+config.assets.js_compressor = :uglifier
</erb>
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression