asset_hat 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/HISTORY CHANGED
@@ -1,5 +1,11 @@
1
1
  = HISTORY
2
2
 
3
+ == Version 0.4.2 (2011-08-08)
4
+ * FIX: Changed Capistrano task to minify assets inside latest release path,
5
+ not previous release path. (Thanks, sauliusg[https://github.com/sauliusg]!)
6
+ * FIX: Fixed deprecation warnings when running Rake tasks. (Thanks,
7
+ jsonperl[https://github.com/jsonperl]!)
8
+
3
9
  == Version 0.4.1 (2011-05-06)
4
10
  * FIX: Stopped `gem install asset_hat` from foolishly requiring itself.
5
11
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Ron DeVera, Mint Digital
1
+ Copyright (c) 2011 Ron DeVera, Mint Digital
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  = AssetHat
2
2
 
3
- Your assets are covered.
3
+ Load CSS and JS faster. Your assets are covered.
4
4
 
5
5
  With Rails' default asset caching, CSS and JS are concatenated (not even
6
6
  minified) at runtime when that bundle is first requested. Not good enough.
@@ -8,10 +8,13 @@ To make your pages load faster, AssetHat can automatically:
8
8
 
9
9
  * Easily *minify* and *bundle* CSS and JS to reduce file sizes and
10
10
  HTTP requests. Do this on deploy, and avoid any performance hit at runtime.
11
- * Load popular <b>third-party JS</b> (like jQuery, YUI, and Ext JS)
12
- from {<b>Google's CDN</b>}[http://code.google.com/apis/ajaxlibs/]
11
+ * Load <b>popular libraries from the JS community</b> -- like jQuery, YUI, and
12
+ Dojo -- from {<b>Google's CDN</b>}[http://code.google.com/apis/ajaxlibs/]
13
13
  when in production, or from localhost in development. It's as simple as
14
14
  <code><%= include_js :jquery %></code> to load straight from Google.
15
+ * Load plenty of JS files in parallel in <b>{LABjs}[http://labjs.com/]
16
+ mode</b>. When calling <code>include_js</code>, just add <code>:loader =>
17
+ :lab_js</code>.
15
18
  * Force image URLs in your CSS to use <b>CDN subdomains</b>
16
19
  (including SSL support), not just the current host.
17
20
  * Add an image's last Git[http://git-scm.com/] commit ID to its CSS URLs to
@@ -35,16 +38,19 @@ Which expands into:
35
38
  <script src="/javascripts/bundles/common.min.js"
36
39
  type="text/javascript"></script>
37
40
 
38
- Don't have your own copy of jQuery? AssetHat detects this and loads jQuery
39
- from Google's CDN instead, whether you're in development or production.
41
+ Don't have your own copy of jQuery? AssetHat detects this and knows how to
42
+ load jQuery from Google's CDN instead, whether you're in development or
43
+ production.
40
44
 
41
45
  Add this to your deploy script, and your CSS/JS will be optimized
42
46
  automatically:
43
47
 
44
48
  rake asset_hat:minify
45
49
 
46
- Tested with Rails 2.3.x. For a quick overview, see
47
- {the AssetHat website}[http://mintdigital.github.com/asset_hat/].
50
+ Tested with Rails 3 and Rails 2.3.x (with Bundler). For a quick overview, see
51
+ {the AssetHat website}[http://mintdigital.github.com/asset_hat/]. To see how
52
+ AssetHat performs in production,
53
+ {check some stats}[http://logicalfriday.com/2011/05/06/assethat-0-4-load-css-and-js-faster-your-assets-are-covered/].
48
54
  For the gritty details, check the
49
55
  {complete docs}[http://mintdigital.github.com/asset_hat/doc/] and
50
56
  {change history}[http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html].
@@ -53,27 +59,27 @@ For the gritty details, check the
53
59
 
54
60
  == Installation
55
61
 
56
- * Rails 3.x:
62
+ === Rails 3.x
57
63
 
58
- 1. Add to your app's Gemfile: <code>gem 'asset_hat', '0.x.x'</code>
59
- 2. Command-line: <code>bundle install</code>
64
+ 1. Add to your app's Gemfile: <code>gem 'asset_hat', '0.x.x'</code>
65
+ 2. Command-line: <code>bundle install</code>
60
66
 
61
- * Rails 2.3.x:
67
+ === Rails 2.3.x
62
68
 
63
- 1. Add the gem:
69
+ 1. Add the gem:
64
70
 
65
- * If you're using {Bundler 0.9+}[http://github.com/carlhuda/bundler]:
71
+ * If you're using {Bundler 0.9+}[http://github.com/carlhuda/bundler]:
66
72
 
67
- 1. Add to your app's Gemfile: <code>gem 'asset_hat', '0.x.x'</code>
68
- 2. Command-line: <code>bundle install</code>
73
+ 1. Add to your app's Gemfile: <code>gem 'asset_hat', '0.x.x'</code>
74
+ 2. Command-line: <code>bundle install</code>
69
75
 
70
- * If you're using Rails 2.3.x's <code>config.gem</code>:
76
+ * If you're using Rails 2.3.x's <code>config.gem</code>:
71
77
 
72
- 1. Add to your app's <code>config/environment.rb</code>:
73
- <code>config.gem 'asset_hat', :version => '0.x.x'</code>
74
- 2. Command-line: <code>gem install asset_hat</code>
78
+ 1. Add to your app's <code>config/environment.rb</code>:
79
+ <code>config.gem 'asset_hat', :version => '0.x.x'</code>
80
+ 2. Command-line: <code>gem install asset_hat</code>
75
81
 
76
- 2. Add to your app's Rakefile: <code>require 'asset_hat/tasks'</code>
82
+ 2. Add to your app's Rakefile: <code>require 'asset_hat/tasks'</code>
77
83
 
78
84
 
79
85
 
@@ -122,6 +128,12 @@ For the gritty details, check the
122
128
  <code>public/stylesheets/bundles/</code> and
123
129
  <code>public/javascripts/bundles/</code>.
124
130
 
131
+ If you're using a CSS/JS layer like SASS or CoffeeScript, be sure to
132
+ compile/transpile to regular CSS/JS before running
133
+ <code>rake asset_hat:minify</code>. (When AssetHat is ready for Rails 3.1,
134
+ <code>rake asset_hat:minify</code> will automatically start with
135
+ <code>rake assets:precompile</code>.)
136
+
125
137
  === Advanced configuration
126
138
 
127
139
  If you manage deployments with Capistrano[http://www.capify.org/], see the
@@ -173,12 +185,13 @@ Additional settings are supported in <code>config/assets.yml</code>:
173
185
  JS will load from {Google's CDN}[http://code.google.com/apis/ajaxlibs/]
174
186
  in production (or any environment where
175
187
  <code>config.action_controller.consider_all_requests_local</code> is set
176
- to <code>true</code>). If the original request to your app used SSL, the
188
+ to <code>false</code>). If the original request to your app used SSL, the
177
189
  vendor JS will also load from Google's CDN via SSL. If you prefer to use a
178
190
  different CDN, specify its SSL/non-SSL URLs, and the appropriate URL will
179
191
  be used per request.
180
192
 
181
- A full list of supported vendors is in the AssetHat::JS::Vendors module.
193
+ A full list of supported vendors is in the
194
+ <code>AssetHat::JS::Vendors</code> module.
182
195
 
183
196
  === SSL configuration
184
197
 
@@ -251,6 +264,62 @@ Or include multiple bundles at once:
251
264
  When including multiple bundles at once, this yields one
252
265
  <code><link></code> or <code><script></code> element per bundle.
253
266
 
267
+ === LABjs mode
268
+
269
+ Say you're loading several JS bundles. However, because there are so many, you
270
+ decide to try a popular script loader like {LABjs}[http://labjs.com/] to see
271
+ how much it improves performance. Here's how it's done the old Rails way:
272
+
273
+ <%= javascript_include_tag 'LAB-1.2.0.min.js' %>
274
+ <script>
275
+ $LAB.
276
+ script('/javascripts/jquery-1.6.1.min.js').wait().
277
+ script('/javascripts/common.js').wait().
278
+ script('/javascripts/search.js').wait().
279
+ script('/javascripts/app.js').wait();
280
+ </script>
281
+
282
+ What a hassle. With AssetHat, just set up a bundle in
283
+ <code>config/assets.yml</code>:
284
+
285
+ js:
286
+ bundles:
287
+ app:
288
+ - common
289
+ - search
290
+ - app
291
+
292
+ Ready to go. Here's how to load jQuery and your bundle normally:
293
+
294
+ <%= include_js :jquery, :bundle => 'app' %>
295
+
296
+ And here's how to switch on LABjs mode:
297
+
298
+ <%= include_js :jquery, :bundle => 'app',
299
+ :loader => :lab_js %>
300
+
301
+ Add your preferred jQuery and LABjs versions to the config file if you haven't
302
+ already, and that's it. If you don't have a copy of LABjs locally, AssetHat
303
+ knows how to instead load it from {cdnjs}[http://cdnjs.com/], which uses
304
+ high-speed Amazon Cloudfront servers.
305
+
306
+ This is just the most common LABjs use case. If you want to fine-tune it even
307
+ further, you can have the best of both worlds:
308
+
309
+ <%= include_js :lab_js %>
310
+ <script>
311
+ $LAB.
312
+ script('<%= include_js :jquery, :only_url => true %>').wait().
313
+ script('<%= include_js "common", :only_url => true %>'). // Non-blocking
314
+ script('<%= include_js "search", :only_url => true %>').wait().
315
+ script('<%= include_js "app", :only_url => true %>').wait();
316
+ </script>
317
+
318
+ In this example, <code>common</code> is not a dependency for
319
+ <code>search</code>, so allow either to execute as soon as possible --
320
+ whichever happens to load first -- rather than always forcing
321
+ <code>common</code> to execute first.
322
+
254
323
  === Bundle tips
255
324
 
256
325
  Don't go overboard with huge bundles:
@@ -263,7 +332,35 @@ Don't go overboard with huge bundles:
263
332
  the cached plugin code.
264
333
  * Regardless of code-change frequency, it's sometimes faster to split a bundle
265
334
  in half, and load each half in parallel (i.e., two HTTP requests instead of
266
- one). Your own tests will tell what's optimal for your situation.
335
+ one). LABjs mode can help with loading several smaller bundles in parallel.
336
+ Your own tests will tell what's optimal for your situation.
337
+
338
+
339
+
340
+ == More info
341
+
342
+ * {Official website}[http://mintdigital.github.com/asset_hat/]
343
+ * {Full documentation}[http://mintdigital.github.com/asset_hat/doc/]
344
+ * {History/changelog}[http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html]
345
+ * Released under the
346
+ {MIT license}[https://github.com/mintdigital/asset_hat/blob/master/LICENSE].
347
+
348
+ === Contributing
349
+
350
+ Have an idea, problem, or bug report?
351
+ {Send a pull request}[http://help.github.com/send-pull-requests/]! Please base
352
+ pull requests on the `development` branch, not the `master` branch.
353
+
354
+ Contributors:
355
+
356
+ * {rondevera}[https://github.com/rondevera]
357
+ (maintainer; Twitter: {@ronalddevera}[https://twitter.com/#!/ronalddevera])
358
+ * {philnash}[https://github.com/philnash]
359
+ * {dstrelau}[https://github.com/dstrelau]
360
+ * {daphonz}[https://github.com/daphonz]
361
+ * {sauliusg}[https://github.com/sauliusg]
362
+ * {jsonperl}[https://github.com/jsonperl]
363
+
267
364
 
268
365
 
269
366
  == {What is best in AssetHat?}[http://www.youtube.com/watch?v=V30tyaXv6EI]
data/Rakefile CHANGED
@@ -8,12 +8,13 @@ begin
8
8
  gemspec.name = 'asset_hat'
9
9
  gemspec.summary = 'Your assets are covered.'
10
10
  gemspec.description = %{
11
- Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on
12
- deploy), not at runtime. Loads popular third-party JS (like jQuery, YUI,
13
- and Ext JS) from localhost in development, and auto-switches to Google's
14
- CDN in production. Lets you switch on LABjs to load more scripts in
15
- parallel. Can rewrite stylesheets to use CDN hosts (not just your web
16
- server) and cache-busting hashes for updated images.
11
+ Load CSS and JS faster. Minifies, bundles, and optimizes CSS/JS assets
12
+ ahead of time (e.g., on deploy), not at runtime. Loads popular
13
+ third-party JS (like jQuery, YUI, and Dojo) from localhost in
14
+ development, and auto-switches to Google's CDN in production. Lets you
15
+ switch on LABjs mode to load more scripts in parallel. Can rewrite
16
+ stylesheets to use CDN hosts (not just your web server) and
17
+ cache-busting hashes for updated images.
17
18
  }.strip.split.join(' ')
18
19
  gemspec.homepage = 'http://mintdigital.github.com/asset_hat'
19
20
 
@@ -2,4 +2,4 @@
2
2
  :major: 0
3
3
  :build:
4
4
  :minor: 4
5
- :patch: 1
5
+ :patch: 2
@@ -5,20 +5,20 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{asset_hat}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ron DeVera", "Mint Digital"]
12
- s.date = %q{2011-05-06}
13
- s.description = %q{Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on deploy), not at runtime. Loads popular third-party JS (like jQuery, YUI, and Ext JS) from localhost in development, and auto-switches to Google's CDN in production. Lets you switch on LABjs to load more scripts in parallel. Can rewrite stylesheets to use CDN hosts (not just your web server) and cache-busting hashes for updated images.}
12
+ s.date = %q{2011-08-08}
13
+ s.description = %q{Load CSS and JS faster. Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on deploy), not at runtime. Loads popular third-party JS (like jQuery, YUI, and Dojo) from localhost in development, and auto-switches to Google's CDN in production. Lets you switch on LABjs mode to load more scripts in parallel. Can rewrite stylesheets to use CDN hosts (not just your web server) and cache-busting hashes for updated images.}
14
14
  s.email = %q{hello@rondevera.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".gemtest",
20
21
  "Gemfile",
21
- "Gemfile.lock",
22
22
  "HISTORY",
23
23
  "LICENSE",
24
24
  "README.rdoc",
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # stylesheet_link_tag 'reset', 'application'
5
5
  # javascript_include_tag(
6
- # Rails.env.production? ? '<Google CDN URL>' : 'jquery-1.5.2')
6
+ # Rails.env.production? ? '<Google CDN URL>' : 'jquery-1.6.1')
7
7
  # javascript_include_tag 'utilities', 'application'
8
8
  #
9
9
  # Create matching bundles in this file (no `.css` or `.js` suffixes needed;
@@ -17,7 +17,7 @@
17
17
  # js:
18
18
  # vendors:
19
19
  # jquery:
20
- # version: 1.5.2
20
+ # version: 1.6.1
21
21
  # bundles:
22
22
  # application:
23
23
  # - utilities
@@ -65,7 +65,7 @@ js:
65
65
  #
66
66
  # vendors:
67
67
  # jquery:
68
- # version: 1.5.2
68
+ # version: 1.6.1
69
69
  #
70
70
  # Supported vendors:
71
71
  # http://mintdigital.github.com/asset_hat/doc/classes/AssetHat/JS/Vendors.html
@@ -186,7 +186,7 @@
186
186
  HTTPS. Defaults to false.
187
187
 
188
188
  </dd>
189
- <dt>version</dt><dd>The vendor version, e.g., &#8216;1.5.0&#8217; for jQuery 1.5. By default,
189
+ <dt>version</dt><dd>The vendor version, e.g., &#8216;1.6.0&#8217; for jQuery 1.6. By default,
190
190
  each vendor version is taken from <tt>config/assets.yml</tt>; use this
191
191
  option to override the configuration.
192
192
 
@@ -85,7 +85,7 @@
85
85
  <a class='source-toggle' href='#' onclick="toggleCode('M000032-source'); return false">
86
86
  [show source]
87
87
  </a>
88
- <pre id='M000032-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 368</span>&#x000A;368: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">asset_path</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">source</span>)&#x000A;369: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_sym</span>&#x000A;370: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:css</span> ; <span class="ruby-identifier">stylesheet_path</span>(<span class="ruby-identifier">source</span>)&#x000A;371: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:js</span> ; <span class="ruby-identifier">javascript_path</span>(<span class="ruby-identifier">source</span>)&#x000A;372: <span class="ruby-keyword kw">else</span>&#x000A;373: <span class="ruby-identifier">raise</span> <span class="ruby-node">%{Unknown type &quot;#{type}&quot;; should be one of: #{TYPES.join(', ')}.}</span>&#x000A;374: <span class="ruby-keyword kw">end</span>&#x000A;375: <span class="ruby-keyword kw">end</span></pre>
88
+ <pre id='M000032-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 363</span>&#x000A;363: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">asset_path</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">source</span>)&#x000A;364: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_sym</span>&#x000A;365: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:css</span> ; <span class="ruby-identifier">stylesheet_path</span>(<span class="ruby-identifier">source</span>)&#x000A;366: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:js</span> ; <span class="ruby-identifier">javascript_path</span>(<span class="ruby-identifier">source</span>)&#x000A;367: <span class="ruby-keyword kw">else</span>&#x000A;368: <span class="ruby-identifier">raise</span> <span class="ruby-node">%{&#x000A;369: Unknown type &quot;#{type}&quot;; should be one of:&#x000A;370: #{AssetHat::TYPES.join(', ')}.&#x000A;371: }</span>.<span class="ruby-identifier">squish!</span>&#x000A;372: <span class="ruby-keyword kw">end</span>&#x000A;373: <span class="ruby-keyword kw">end</span></pre>
89
89
  </div>
90
90
  </div>
91
91
  <div class='method public-instance' id='method-M000030'>
@@ -148,7 +148,7 @@
148
148
  <a class='source-toggle' href='#' onclick="toggleCode('M000030-source'); return false">
149
149
  [show source]
150
150
  </a>
151
- <pre id='M000030-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 159</span>&#x000A;159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_css</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;160: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;161: &#x000A;162: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;163: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>] <span class="ruby-operator">||=</span> {}&#x000A;164: &#x000A;165: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;166: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(&#x000A;167: <span class="ruby-identifier">:media</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'screen,projection'</span>, <span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>)&#x000A;168: <span class="ruby-identifier">cache_key</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]).<span class="ruby-identifier">inspect</span>&#x000A;169: &#x000A;170: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;171: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;172: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ssl</span>] <span class="ruby-operator">&amp;&amp;=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">ssl_asset_host_differs?</span>&#x000A;173: <span class="ruby-identifier">html</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>] =&#x000A;174: <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:css</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]))&#x000A;175: <span class="ruby-keyword kw">end</span>&#x000A;176: &#x000A;177: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;178: <span class="ruby-identifier">html</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:html_safe</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">html</span>.<span class="ruby-identifier">html_safe</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">html</span>&#x000A;179: <span class="ruby-keyword kw">end</span></pre>
151
+ <pre id='M000030-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 159</span>&#x000A;159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_css</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;160: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;161: &#x000A;162: <span class="ruby-identifier">initialize_html_cache</span> <span class="ruby-identifier">:css</span>&#x000A;163: &#x000A;164: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">setup_options</span>(<span class="ruby-identifier">args</span>,&#x000A;165: <span class="ruby-identifier">:media</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'screen,projection'</span>,&#x000A;166: <span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>&#x000A;167: )&#x000A;168: <span class="ruby-identifier">cache_key</span> = <span class="ruby-identifier">setup_cache_key</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>)&#x000A;169: &#x000A;170: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">asset_cached?</span>(<span class="ruby-identifier">:css</span>, <span class="ruby-identifier">cache_key</span>)&#x000A;171: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;172: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ssl</span>] <span class="ruby-operator">&amp;&amp;=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">ssl_asset_host_differs?</span>&#x000A;173: <span class="ruby-identifier">html</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>] =&#x000A;174: <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:css</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]))&#x000A;175: <span class="ruby-keyword kw">end</span>&#x000A;176: &#x000A;177: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;178: <span class="ruby-identifier">make_html_safe</span> <span class="ruby-identifier">html</span>&#x000A;179: <span class="ruby-keyword kw">end</span></pre>
152
152
  </div>
153
153
  </div>
154
154
  <div class='method public-instance' id='method-M000031'>
@@ -174,7 +174,7 @@
174
174
  <p>
175
175
  Include jQuery:
176
176
  </p>
177
- <pre># Development/test environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;/javascripts/jquery-VERSION.min.js&quot; ...&gt;&lt;/script&gt;&#x000A;&#x000A;# Staging/production environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;http://ajax.googleapis.com/.../jquery.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; # Set jQuery versions either in `config/assets.yml`, or by using&#x000A; # `include_js :jquery, :version =&gt; '1.6.0'`.</pre>
177
+ <pre># Development/test environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;/javascripts/jquery-VERSION.min.js&quot; ...&gt;&lt;/script&gt;&#x000A;&#x000A;# Staging/production environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;http://ajax.googleapis.com/.../jquery.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; # Set jQuery versions either in `config/assets.yml`, or by using&#x000A; # `include_js :jquery, :version =&gt; '1.6.1'`.</pre>
178
178
  <p>
179
179
  Include a bundle of JS files (i.e., a concatenated set of files; configure
180
180
  in <tt>config/assets.yml</tt>):
@@ -224,7 +224,7 @@
224
224
  <a class='source-toggle' href='#' onclick="toggleCode('M000031-source'); return false">
225
225
  [show source]
226
226
  </a>
227
- <pre id='M000031-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 295</span>&#x000A;295: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;296: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;297: &#x000A;298: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;299: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>] <span class="ruby-operator">||=</span> {}&#x000A;300: &#x000A;301: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;302: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>)&#x000A;303: <span class="ruby-identifier">cache_key</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]).<span class="ruby-identifier">inspect</span>&#x000A;304: &#x000A;305: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;306: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;307: &#x000A;308: <span class="ruby-identifier">htmls</span> = []&#x000A;309: <span class="ruby-identifier">include_assets_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>)&#x000A;310: <span class="ruby-identifier">loader</span> = <span class="ruby-keyword kw">nil</span>&#x000A;311: &#x000A;312: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:loader</span>].<span class="ruby-identifier">present?</span>&#x000A;313: <span class="ruby-identifier">loader</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:loader</span>)&#x000A;314: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">:only_url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)&#x000A;315: <span class="ruby-keyword kw">end</span>&#x000A;316: &#x000A;317: <span class="ruby-comment cmt"># Get vendor HTML/URLs</span>&#x000A;318: <span class="ruby-identifier">included_vendors</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">&amp;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">VENDORS</span>)&#x000A;319: &#x000A;320: <span class="ruby-comment cmt"># Add HTML inclusions for vendors</span>&#x000A;321: <span class="ruby-identifier">included_vendors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vendor</span><span class="ruby-operator">|</span>&#x000A;322: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;323: <span class="ruby-identifier">src</span> = <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">source_for</span>(&#x000A;324: <span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>))&#x000A;325: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-identifier">src</span>,&#x000A;326: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>).&#x000A;327: <span class="ruby-identifier">except</span>(<span class="ruby-identifier">:bundle</span>, <span class="ruby-identifier">:bundles</span>))&#x000A;328: <span class="ruby-keyword kw">end</span>&#x000A;329: &#x000A;330: <span class="ruby-comment cmt"># Get non-vendor HTML/URLs</span>&#x000A;331: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">include_assets_options</span>]))&#x000A;332: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">reject!</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:blank?</span>)&#x000A;333: &#x000A;334: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">loader</span>&#x000A;335: <span class="ruby-comment cmt"># `htmls` actually contains URLs; convert to an HTML/JS block</span>&#x000A;336: <span class="ruby-identifier">urls</span> = <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">flatten</span>&#x000A;337: <span class="ruby-identifier">htmls</span> = []&#x000A;338: &#x000A;339: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">loader</span>&#x000A;340: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:lab_js</span>&#x000A;341: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-identifier">:lab_js</span>)&#x000A;342: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;script type=&quot;text/javascript&quot;&gt;'</span>&#x000A;343: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">loader_js</span>(<span class="ruby-identifier">:lab_js</span>, <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">urls</span>)&#x000A;344: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;/script&gt;'</span>&#x000A;345: <span class="ruby-keyword kw">end</span>&#x000A;346: <span class="ruby-keyword kw">end</span>&#x000A;347: &#x000A;348: <span class="ruby-comment cmt"># Convert to a URL (string), array of URLs, or one long HTML string</span>&#x000A;349: <span class="ruby-identifier">html</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only_url</span>]&#x000A;350: <span class="ruby-comment cmt"># Return one URL (string) or multiple (array of strings).</span>&#x000A;351: <span class="ruby-comment cmt"># Not actually HTML.</span>&#x000A;352: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">flatten!</span>&#x000A;353: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">htmls</span>&#x000A;354: <span class="ruby-keyword kw">else</span>&#x000A;355: <span class="ruby-comment cmt"># Return one long string of HTML</span>&#x000A;356: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;357: <span class="ruby-keyword kw">end</span>&#x000A;358: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>] = <span class="ruby-identifier">html</span>&#x000A;359: <span class="ruby-keyword kw">end</span>&#x000A;360: &#x000A;361: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;362: <span class="ruby-identifier">html</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:html_safe</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">html</span>.<span class="ruby-identifier">html_safe</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">html</span>&#x000A;363: <span class="ruby-keyword kw">end</span></pre>
227
+ <pre id='M000031-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 295</span>&#x000A;295: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;296: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;297: &#x000A;298: <span class="ruby-identifier">initialize_html_cache</span> <span class="ruby-identifier">:js</span>&#x000A;299: &#x000A;300: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">setup_options</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>)&#x000A;301: <span class="ruby-identifier">cache_key</span> = <span class="ruby-identifier">setup_cache_key</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>)&#x000A;302: &#x000A;303: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">asset_cached?</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-identifier">cache_key</span>)&#x000A;304: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;305: &#x000A;306: <span class="ruby-identifier">htmls</span> = []&#x000A;307: <span class="ruby-identifier">include_assets_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>)&#x000A;308: &#x000A;309: <span class="ruby-identifier">loader</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:loader</span>)&#x000A;310: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">:only_url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">loader</span>&#x000A;311: &#x000A;312: <span class="ruby-comment cmt"># Get vendor HTML/URLs</span>&#x000A;313: <span class="ruby-identifier">included_vendors</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">&amp;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">VENDORS</span>)&#x000A;314: &#x000A;315: <span class="ruby-comment cmt"># Add HTML inclusions for vendors</span>&#x000A;316: <span class="ruby-identifier">included_vendors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vendor</span><span class="ruby-operator">|</span>&#x000A;317: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;318: <span class="ruby-identifier">src</span> = <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">source_for</span>(&#x000A;319: <span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>))&#x000A;320: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-identifier">src</span>,&#x000A;321: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>).&#x000A;322: <span class="ruby-identifier">except</span>(<span class="ruby-identifier">:bundle</span>, <span class="ruby-identifier">:bundles</span>))&#x000A;323: <span class="ruby-keyword kw">end</span>&#x000A;324: &#x000A;325: <span class="ruby-comment cmt"># Get non-vendor HTML/URLs</span>&#x000A;326: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">include_assets_options</span>]))&#x000A;327: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">reject!</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:blank?</span>)&#x000A;328: &#x000A;329: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">loader</span>&#x000A;330: <span class="ruby-comment cmt"># `htmls` actually contains URLs; convert to an HTML/JS block</span>&#x000A;331: <span class="ruby-identifier">urls</span> = <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">flatten</span>&#x000A;332: <span class="ruby-identifier">htmls</span> = []&#x000A;333: &#x000A;334: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">loader</span>&#x000A;335: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:lab_js</span>&#x000A;336: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-identifier">:lab_js</span>)&#x000A;337: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;script type=&quot;text/javascript&quot;&gt;'</span>&#x000A;338: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">loader_js</span>(<span class="ruby-identifier">:lab_js</span>, <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">urls</span>)&#x000A;339: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;/script&gt;'</span>&#x000A;340: <span class="ruby-keyword kw">end</span>&#x000A;341: <span class="ruby-keyword kw">end</span>&#x000A;342: &#x000A;343: <span class="ruby-comment cmt"># Convert to a URL (string), array of URLs, or one long HTML string</span>&#x000A;344: <span class="ruby-identifier">html</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only_url</span>]&#x000A;345: <span class="ruby-comment cmt"># Return one URL (string) or multiple (array of strings).</span>&#x000A;346: <span class="ruby-comment cmt"># Not actually HTML.</span>&#x000A;347: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">flatten!</span>&#x000A;348: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">htmls</span>&#x000A;349: <span class="ruby-keyword kw">else</span>&#x000A;350: <span class="ruby-comment cmt"># Return one long string of HTML</span>&#x000A;351: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;352: <span class="ruby-keyword kw">end</span>&#x000A;353: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>] = <span class="ruby-identifier">html</span>&#x000A;354: <span class="ruby-keyword kw">end</span>&#x000A;355: &#x000A;356: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;357: <span class="ruby-identifier">make_html_safe</span> <span class="ruby-identifier">html</span>&#x000A;358: <span class="ruby-keyword kw">end</span></pre>
228
228
  </div>
229
229
  </div>
230
230
  </div>
@@ -1 +1 @@
1
- Fri, 06 May 2011 18:12:56 -0400
1
+ Mon, 08 Aug 2011 14:30:15 -0400
@@ -31,13 +31,25 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Fri May 06 18:12:52 -0400 2011</span>
34
+ <span class='datetime'>Mon Aug 08 13:47:59 -0400 2011</span>
35
35
  </div>
36
36
  </div>
37
37
  <div id='content'>
38
38
  <div id='text'>
39
39
  <div id='description'>
40
40
  <h1><a href="HISTORY.html">HISTORY</a></h1>
41
+ <h2>Version 0.4.2 (2011-08-08)</h2>
42
+ <ul>
43
+ <li>FIX: Changed Capistrano task to minify assets inside latest release path,
44
+ not previous release path. (Thanks, <a
45
+ href="https://github.com/sauliusg">sauliusg</a>!)
46
+
47
+ </li>
48
+ <li>FIX: Fixed deprecation warnings when running Rake tasks. (Thanks, <a
49
+ href="https://github.com/jsonperl">jsonperl</a>!)
50
+
51
+ </li>
52
+ </ul>
41
53
  <h2>Version 0.4.1 (2011-05-06)</h2>
42
54
  <ul>
43
55
  <li>FIX: Stopped `gem install asset_hat` from foolishly requiring itself.
@@ -31,14 +31,14 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Fri May 06 17:23:46 -0400 2011</span>
34
+ <span class='datetime'>Mon Aug 08 12:28:21 -0400 2011</span>
35
35
  </div>
36
36
  </div>
37
37
  <div id='content'>
38
38
  <div id='text'>
39
39
  <div id='description'>
40
40
  <p>
41
- Copyright &#169; 2010 Ron DeVera, Mint Digital
41
+ Copyright &#169; 2011 Ron DeVera, Mint Digital
42
42
  </p>
43
43
  <p>
44
44
  Permission is hereby granted, free of charge, to any person obtaining a
@@ -9,14 +9,14 @@
9
9
  function popupCode(url) {
10
10
  window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
11
11
  }
12
-
12
+
13
13
  function toggleCode(id) {
14
14
  var code = document.getElementById(id)
15
-
15
+
16
16
  code.style.display = code.style.display != 'block' ? 'block' : 'none'
17
17
  return true
18
18
  }
19
-
19
+
20
20
  // Make codeblocks hidden by default
21
21
  document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
22
22
  //]]>
@@ -31,7 +31,7 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Fri May 06 17:23:46 -0400 2011</span>
34
+ <span class='datetime'>Mon Aug 08 12:28:21 -0400 2011</span>
35
35
  </div>
36
36
  </div>
37
37
  <div id='content'>
@@ -39,7 +39,7 @@
39
39
  <div id='description'>
40
40
  <h1><a href="../classes/AssetHat.html">AssetHat</a></h1>
41
41
  <p>
42
- Your assets are covered.
42
+ Load CSS and JS faster. Your assets are covered.
43
43
  </p>
44
44
  <p>
45
45
  With Rails&#8217; default asset caching, CSS and JS are concatenated (not
@@ -50,22 +50,28 @@
50
50
  <ul>
51
51
  <li>Easily <b>minify</b> and <b>bundle</b> CSS and JS to reduce file sizes and
52
52
  HTTP requests. Do this on deploy, and avoid any performance hit at runtime.
53
-
53
+
54
54
  </li>
55
- <li>Load popular <b>third-party JS</b> (like jQuery, YUI, and Ext JS) from <a
55
+ <li>Load <b>popular libraries from the JS community</b> &#8212; like jQuery,
56
+ YUI, and Dojo &#8212; from <a
56
57
  href="http://code.google.com/apis/ajaxlibs/">Google's CDN</a> when in
57
58
  production, or from localhost in development. It&#8217;s as simple as
58
59
  <tt>&lt;%= include_js :jquery %&gt;</tt> to load straight from Google.
59
-
60
+
61
+ </li>
62
+ <li>Load plenty of JS files in parallel in <b><a
63
+ href="http://labjs.com/">LABjs</a> mode</b>. When calling
64
+ <tt>include_js</tt>, just add <tt>:loader =&gt; :lab_js</tt>.
65
+
60
66
  </li>
61
67
  <li>Force image URLs in your CSS to use <b>CDN subdomains</b> (including SSL
62
68
  support), not just the current host.
63
-
69
+
64
70
  </li>
65
71
  <li>Add an image&#8217;s last <a href="http://git-scm.com/">Git</a> commit ID
66
72
  to its CSS URLs to <b>bust browser caches</b> (e.g.,
67
73
  <tt>/images/foo.png?ab12cd3</tt>).
68
-
74
+
69
75
  </li>
70
76
  </ul>
71
77
  <p>
@@ -78,9 +84,9 @@
78
84
  <pre>&lt;link href=&quot;/stylesheets/bundles/application.min.css&quot;&#x000A; media=&quot;screen,projection&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;&#x000A;&lt;script src=&quot;/javascripts/jquery-1.x.x.min.js&quot;&#x000A; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&#x000A; &lt;!-- In production, jQuery loads from Google's CDN instead. --&gt;&#x000A;&lt;script src=&quot;/javascripts/bundles/plugins.min.js&quot;&#x000A; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&#x000A;&lt;script src=&quot;/javascripts/bundles/common.min.js&quot;&#x000A; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
79
85
  <p>
80
86
  Don&#8217;t have your own copy of jQuery? <a
81
- href="../classes/AssetHat.html">AssetHat</a> detects this and loads jQuery
82
- from Google&#8217;s CDN instead, whether you&#8217;re in development or
83
- production.
87
+ href="../classes/AssetHat.html">AssetHat</a> detects this and knows how to
88
+ load jQuery from Google&#8217;s CDN instead, whether you&#8217;re in
89
+ development or production.
84
90
  </p>
85
91
  <p>
86
92
  Add this to your deploy script, and your CSS/JS will be optimized
@@ -88,84 +94,81 @@
88
94
  </p>
89
95
  <pre>rake asset_hat:minify</pre>
90
96
  <p>
91
- Tested with Rails 2.3.x. For a quick overview, see <a
92
- href="http://mintdigital.github.com/asset_hat/">the AssetHat website</a>.
93
- For the gritty details, check the <a
97
+ Tested with Rails 3 and Rails 2.3.x (with Bundler). For a quick overview,
98
+ see <a href="http://mintdigital.github.com/asset_hat/">the AssetHat
99
+ website</a>. To see how <a href="../classes/AssetHat.html">AssetHat</a>
100
+ performs in production, <a
101
+ href="http://logicalfriday.com/2011/05/06/assethat-0-4-load-css-and-js-faster-your-assets-are-covered/">check
102
+ some stats</a>. For the gritty details, check the <a
94
103
  href="http://mintdigital.github.com/asset_hat/doc/">complete docs</a> and
95
104
  <a
96
105
  href="http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html">change
97
106
  history</a>.
98
107
  </p>
99
108
  <h2>Installation</h2>
100
- <ul>
101
- <li>Rails 3.x:
102
-
109
+ <h3>Rails 3.x</h3>
103
110
  <ol>
104
111
  <li>Add to your app&#8217;s Gemfile: <tt>gem 'asset_hat', '0.x.x'</tt>
105
-
112
+
106
113
  </li>
107
114
  <li>Command-line: <tt>bundle install</tt>
108
-
115
+
109
116
  </li>
110
117
  </ol>
111
- </li>
112
- <li>Rails 2.3.x:
113
-
118
+ <h3>Rails 2.3.x</h3>
114
119
  <ol>
115
120
  <li>Add the gem:
116
-
121
+
117
122
  <ul>
118
123
  <li>If you&#8217;re using <a href="http://github.com/carlhuda/bundler">Bundler
119
124
  0.9+</a>:
120
-
125
+
121
126
  <ol>
122
127
  <li>Add to your app&#8217;s Gemfile: <tt>gem 'asset_hat', '0.x.x'</tt>
123
-
128
+
124
129
  </li>
125
130
  <li>Command-line: <tt>bundle install</tt>
126
-
131
+
127
132
  </li>
128
133
  </ol>
129
134
  </li>
130
135
  <li>If you&#8217;re using Rails 2.3.x&#8217;s <tt>config.gem</tt>:
131
-
136
+
132
137
  <ol>
133
138
  <li>Add to your app&#8217;s <tt>config/environment.rb</tt>: <tt>config.gem
134
139
  'asset_hat', :version =&gt; '0.x.x'</tt>
135
-
140
+
136
141
  </li>
137
142
  <li>Command-line: <tt>gem install asset_hat</tt>
138
-
143
+
139
144
  </li>
140
145
  </ol>
141
146
  </li>
142
147
  </ul>
143
148
  </li>
144
149
  <li>Add to your app&#8217;s Rakefile: <tt>require 'asset_hat/tasks'</tt>
145
-
150
+
146
151
  </li>
147
152
  </ol>
148
- </li>
149
- </ul>
150
153
  <h2>Quick start &amp; configuration</h2>
151
154
  <ol>
152
155
  <li>In all of your layouts and views, change <tt>stylesheet_link_tag</tt> to
153
156
  <tt>include_css</tt>, and change <tt>javascript_include_tag</tt> to
154
157
  <tt>include_js</tt>. (Don&#8217;t worry, these helpers use the same
155
158
  arguments as Rails&#8217; helpers. Nothing will break.)
156
-
159
+
157
160
  </li>
158
161
  <li>Create the default config file:
159
-
162
+
160
163
  <pre>rake asset_hat:config</pre>
161
164
  </li>
162
165
  <li>In your app, open the new file at <tt>config/assets.yml</tt>, and set up
163
166
  your CSS/JS bundles according to that file&#8217;s example.
164
-
167
+
165
168
  </li>
166
169
  <li>In your layouts and views, switch to the new bundles. For example, if you
167
170
  originally had this:
168
-
171
+
169
172
  <pre>&lt;%# app/views/layouts/application.html.erb: %&gt;&#x000A;&lt;%= stylesheet_include_tag 'reset', 'application' %&gt;</pre>
170
173
  <p>
171
174
  Then you&#8217;ll now have:
@@ -173,7 +176,7 @@
173
176
  <pre># config/assets.yml:&#x000A;css:&#x000A; bundles:&#x000A; application: ['reset', 'application']&#x000A;&#x000A;&lt;%# app/views/layouts/application.html.erb: %&gt;&#x000A;&lt;%= include_css :bundle =&gt; 'application' %&gt;</pre>
174
177
  </li>
175
178
  <li>Add this to your deployment script:
176
-
179
+
177
180
  <pre>rake asset_hat:minify</pre>
178
181
  <p>
179
182
  This minifies all of the CSS/JS files listed in <tt>config/assets.yml</tt>,
@@ -186,6 +189,14 @@
186
189
  <tt>public/stylesheets/bundles/</tt> and
187
190
  <tt>public/javascripts/bundles/</tt>.
188
191
  </p>
192
+ <p>
193
+ If you&#8217;re using a CSS/JS layer like SASS or CoffeeScript, be sure to
194
+ compile/transpile to regular CSS/JS before running <tt>rake
195
+ asset_hat:minify</tt>. (When <a
196
+ href="../classes/AssetHat.html">AssetHat</a> is ready for Rails 3.1,
197
+ <tt>rake asset_hat:minify</tt> will automatically start with <tt>rake
198
+ assets:precompile</tt>.)
199
+ </p>
189
200
  </li>
190
201
  </ol>
191
202
  <h3>Advanced configuration</h3>
@@ -216,7 +227,7 @@
216
227
  Lecomte&#8217;s YUI Compressor and Schlueter&#8217;s PHP cssmin), and JS is
217
228
  minified with <a href="http://github.com/rgrove/jsmin">rgrove/jsmin</a> (a
218
229
  Ruby port of Crockford&#8217;s JSMin).
219
-
230
+
220
231
  <p>
221
232
  If you&#8217;d prefer to have slightly more readable code for debugging
222
233
  purposes, you can switch both the CSS and JS engines to <tt>weak</tt>.
@@ -226,7 +237,7 @@
226
237
  <li><tt>vendors</tt>: Configures third-party JS that&#8217;s loaded from a CDN
227
238
  or other external source. The following example configures jQuery and
228
239
  jQuery UI for use throughout the app:
229
-
240
+
230
241
  <pre>js:&#x000A; vendors:&#x000A; jquery:&#x000A; version: 1.5.2&#x000A; jquery_ui:&#x000A; version: 1.8.12&#x000A; remote_url: http://cdn.example.com/js/jquery-ui-1.8.12.min.js&#x000A; remote_ssl_url: https://cdn-ssl.example.com/js/jquery-ui-1.8.12.min.js</pre>
231
242
  <p>
232
243
  Configuration keys per vendor:
@@ -236,22 +247,21 @@
236
247
  above, <tt>&lt;%= include_js :jquery %&gt;</tt> uses version 1.5.2 by
237
248
  default. You can override this for special layouts/views with <tt>&lt;%=
238
249
  include_js :jquery, :version =&gt; '1.3.2' %&gt;</tt>.
239
-
250
+
240
251
  </li>
241
252
  <li><tt>remote_url</tt>, <tt>remote_ssl_url</tt>: By default, vendor JS will
242
253
  load from <a href="http://code.google.com/apis/ajaxlibs/">Google's CDN</a>
243
254
  in production (or any environment where
244
255
  <tt>config.action_controller.consider_all_requests_local</tt> is set to
245
- <tt>true</tt>). If the original request to your app used SSL, the vendor JS
246
- will also load from Google&#8217;s CDN via SSL. If you prefer to use a
256
+ <tt>false</tt>). If the original request to your app used SSL, the vendor
257
+ JS will also load from Google&#8217;s CDN via SSL. If you prefer to use a
247
258
  different CDN, specify its SSL/non-SSL URLs, and the appropriate URL will
248
259
  be used per request.
249
-
260
+
250
261
  </li>
251
262
  </ul>
252
263
  <p>
253
- A full list of supported vendors is in the <a
254
- href="../classes/AssetHat/JS/Vendors.html">AssetHat::JS::Vendors</a>
264
+ A full list of supported vendors is in the <tt>AssetHat::JS::Vendors</tt>
255
265
  module.
256
266
  </p>
257
267
  </li>
@@ -319,6 +329,45 @@
319
329
  When including multiple bundles at once, this yields one
320
330
  <tt>&lt;link&gt;</tt> or <tt>&lt;script&gt;</tt> element per bundle.
321
331
  </p>
332
+ <h3>LABjs mode</h3>
333
+ <p>
334
+ Say you&#8217;re loading several JS bundles. However, because there are so
335
+ many, you decide to try a popular script loader like <a
336
+ href="http://labjs.com/">LABjs</a> to see how much it improves performance.
337
+ Here&#8217;s how it&#8217;s done the old Rails way:
338
+ </p>
339
+ <pre>&lt;%= javascript_include_tag 'LAB-1.2.0.min.js' %&gt;&#x000A;&lt;script&gt;&#x000A; $LAB.&#x000A; script('/javascripts/jquery-1.6.1.min.js').wait().&#x000A; script('/javascripts/common.js').wait().&#x000A; script('/javascripts/search.js').wait().&#x000A; script('/javascripts/app.js').wait();&#x000A;&lt;/script&gt;</pre>
340
+ <p>
341
+ What a hassle. With <a href="../classes/AssetHat.html">AssetHat</a>, just
342
+ set up a bundle in <tt>config/assets.yml</tt>:
343
+ </p>
344
+ <pre>js:&#x000A; bundles:&#x000A; app:&#x000A; - common&#x000A; - search&#x000A; - app</pre>
345
+ <p>
346
+ Ready to go. Here&#8217;s how to load jQuery and your bundle normally:
347
+ </p>
348
+ <pre>&lt;%= include_js :jquery, :bundle =&gt; 'app' %&gt;</pre>
349
+ <p>
350
+ And here&#8217;s how to switch on LABjs mode:
351
+ </p>
352
+ <pre>&lt;%= include_js :jquery, :bundle =&gt; 'app',&#x000A; :loader =&gt; :lab_js %&gt;</pre>
353
+ <p>
354
+ Add your preferred jQuery and LABjs versions to the config file if you
355
+ haven&#8217;t already, and that&#8217;s it. If you don&#8217;t have a copy
356
+ of LABjs locally, <a href="../classes/AssetHat.html">AssetHat</a> knows how
357
+ to instead load it from <a href="http://cdnjs.com/">cdnjs</a>, which uses
358
+ high-speed Amazon Cloudfront servers.
359
+ </p>
360
+ <p>
361
+ This is just the most common LABjs use case. If you want to fine-tune it
362
+ even further, you can have the best of both worlds:
363
+ </p>
364
+ <pre>&lt;%= include_js :lab_js %&gt;&#x000A;&lt;script&gt;&#x000A; $LAB.&#x000A; script('&lt;%= include_js :jquery, :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js &quot;common&quot;, :only_url =&gt; true %&gt;'). // Non-blocking&#x000A; script('&lt;%= include_js &quot;search&quot;, :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js &quot;app&quot;, :only_url =&gt; true %&gt;').wait();&#x000A;&lt;/script&gt;</pre>
365
+ <p>
366
+ In this example, <tt>common</tt> is not a dependency for <tt>search</tt>,
367
+ so allow either to execute as soon as possible &#8212; whichever happens to
368
+ load first &#8212; rather than always forcing <tt>common</tt> to execute
369
+ first.
370
+ </p>
322
371
  <h3>Bundle tips</h3>
323
372
  <p>
324
373
  Don&#8217;t go overboard with huge bundles:
@@ -326,31 +375,82 @@
326
375
  <ul>
327
376
  <li>Mobile browsers may not cache CSS/JS files that are too large, regardless
328
377
  of gzipping. Check the latest specs for each mobile browser you support.
329
-
378
+
330
379
  </li>
331
380
  <li>You might want to put plugins (rarely changed) in one bundle, and
332
381
  application code (frequently changed) in another bundle. This way, when the
333
382
  app code changes, the browser re-downloads only the new app code, and uses
334
383
  the cached plugin code.
335
-
384
+
336
385
  </li>
337
386
  <li>Regardless of code-change frequency, it&#8217;s sometimes faster to split a
338
387
  bundle in half, and load each half in parallel (i.e., two HTTP requests
339
- instead of one). Your own tests will tell what&#8217;s optimal for your
388
+ instead of one). LABjs mode can help with loading several smaller bundles
389
+ in parallel. Your own tests will tell what&#8217;s optimal for your
340
390
  situation.
341
-
391
+
392
+ </li>
393
+ </ul>
394
+ <h2>More info</h2>
395
+ <ul>
396
+ <li><a href="http://mintdigital.github.com/asset_hat/">Official website</a>
397
+
398
+ </li>
399
+ <li><a href="http://mintdigital.github.com/asset_hat/doc/">Full
400
+ documentation</a>
401
+
402
+ </li>
403
+ <li><a
404
+ href="http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html">History/changelog</a>
405
+
406
+ </li>
407
+ <li>Released under the <a
408
+ href="https://github.com/mintdigital/asset_hat/blob/master/LICENSE">MIT
409
+ license</a>.
410
+
411
+ </li>
412
+ </ul>
413
+ <h3>Contributing</h3>
414
+ <p>
415
+ Have an idea, problem, or bug report? <a
416
+ href="http://help.github.com/send-pull-requests/">Send a pull request</a>!
417
+ Please base pull requests on the `development` branch, not the `master`
418
+ branch.
419
+ </p>
420
+ <p>
421
+ Contributors:
422
+ </p>
423
+ <ul>
424
+ <li><a href="https://github.com/rondevera">rondevera</a> (maintainer; Twitter:
425
+ <a href="https://twitter.com/#!/ronalddevera">@ronalddevera</a>)
426
+
427
+ </li>
428
+ <li><a href="https://github.com/philnash">philnash</a>
429
+
430
+ </li>
431
+ <li><a href="https://github.com/dstrelau">dstrelau</a>
432
+
433
+ </li>
434
+ <li><a href="https://github.com/daphonz">daphonz</a>
435
+
436
+ </li>
437
+ <li><a href="https://github.com/sauliusg">sauliusg</a>
438
+
439
+ </li>
440
+ <li><a href="https://github.com/jsonperl">jsonperl</a>
441
+
342
442
  </li>
343
443
  </ul>
344
444
  <h2><a href="http://www.youtube.com/watch?v=V30tyaXv6EI">What is best in AssetHat?</a></h2>
345
445
  <ul>
346
446
  <li>To crush your assets;
347
-
447
+
348
448
  </li>
349
449
  <li>See them bundled before you; and
350
-
450
+
351
451
  </li>
352
452
  <li>Hear no more lamentation about slow page loads.
353
-
453
+
354
454
  </li>
355
455
  </ul>
356
456
  </div>