asset_hat 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +37 -0
  3. data/HISTORY +10 -0
  4. data/README.rdoc +117 -75
  5. data/Rakefile +4 -4
  6. data/VERSION.yml +2 -2
  7. data/asset_hat.gemspec +69 -7
  8. data/config/assets.yml +46 -24
  9. data/doc/classes/AssetHat.html +183 -118
  10. data/doc/classes/AssetHat/CSS.html +21 -21
  11. data/doc/classes/AssetHat/CSS/Engines.html +10 -10
  12. data/doc/classes/AssetHat/JS.html +13 -13
  13. data/doc/classes/AssetHat/JS/Engines.html +10 -10
  14. data/doc/classes/AssetHat/JS/Vendors.html +85 -22
  15. data/doc/classes/AssetHatHelper.html +94 -19
  16. data/doc/created.rid +1 -1
  17. data/doc/files/HISTORY.html +20 -2
  18. data/doc/files/LICENSE.html +1 -1
  19. data/doc/files/README_rdoc.html +87 -31
  20. data/doc/files/lib/asset_hat/capistrano_rb.html +1 -1
  21. data/doc/files/lib/asset_hat/css_rb.html +1 -1
  22. data/doc/files/lib/asset_hat/initializers/action_view_rb.html +49 -0
  23. data/doc/files/lib/asset_hat/initializers/cache_last_commit_ids_rb.html +49 -0
  24. data/doc/files/lib/asset_hat/js/vendors_rb.html +1 -1
  25. data/doc/files/lib/asset_hat/js_rb.html +1 -1
  26. data/doc/files/lib/asset_hat/railtie_rb.html +61 -0
  27. data/doc/files/lib/asset_hat/tasks/css_rb.html +1 -1
  28. data/doc/files/lib/asset_hat/tasks/js_rb.html +1 -1
  29. data/doc/files/lib/asset_hat/tasks_rb.html +2 -1
  30. data/doc/files/lib/asset_hat/unicorn_rb.html +58 -0
  31. data/doc/files/lib/asset_hat/vcs_rb.html +1 -1
  32. data/doc/files/lib/asset_hat/version_rb.html +1 -1
  33. data/doc/files/{app/helpers → lib}/asset_hat_helper_rb.html +3 -3
  34. data/doc/files/lib/asset_hat_rb.html +9 -1
  35. data/doc/files/lib/tasks/asset_hat_rake.html +54 -0
  36. data/doc/fr_file_index.html +6 -1
  37. data/doc/fr_method_index.html +60 -52
  38. data/lib/asset_hat.rb +104 -59
  39. data/lib/asset_hat/initializers/action_view.rb +1 -0
  40. data/lib/asset_hat/initializers/cache_last_commit_ids.rb +1 -0
  41. data/lib/asset_hat/js/vendors.rb +198 -72
  42. data/lib/asset_hat/railtie.rb +19 -0
  43. data/lib/asset_hat/tasks.rb +5 -2
  44. data/lib/asset_hat/unicorn.rb +9 -0
  45. data/lib/asset_hat/vcs.rb +3 -2
  46. data/{app/helpers → lib}/asset_hat_helper.rb +184 -29
  47. data/{tasks → lib/tasks}/asset_hat.rake +0 -0
  48. data/rails/init.rb +2 -2
  49. data/test/asset_hat_helper_test.rb +731 -148
  50. data/test/asset_hat_test.rb +23 -2
  51. data/test/test_helper.rb +4 -8
  52. metadata +311 -30
@@ -31,7 +31,7 @@
31
31
  </h1>
32
32
  <ol class='paths'>
33
33
  <li>
34
- <a href="../files/app/helpers/asset_hat_helper_rb.html">app/helpers/asset_hat_helper.rb</a>
34
+ <a href="../files/lib/asset_hat_helper_rb.html">lib/asset_hat_helper.rb</a>
35
35
  </li>
36
36
  </ol>
37
37
  </div>
@@ -47,8 +47,9 @@
47
47
  <h2>Methods</h2>
48
48
  <h3>public instance</h3>
49
49
  <ol>
50
- <li><a href="#M000027">include_css</a></li>
51
- <li><a href="#M000028">include_js</a></li>
50
+ <li><a href="#M000032">asset_path</a></li>
51
+ <li><a href="#M000030">include_css</a></li>
52
+ <li><a href="#M000031">include_js</a></li>
52
53
  </ol>
53
54
  </div>
54
55
  <div id='section'>
@@ -66,24 +67,45 @@
66
67
  </div>
67
68
  <div id='methods'>
68
69
  <h2>Public instance methods</h2>
69
- <div class='method public-instance' id='method-M000027'>
70
- <a name='M000027'></a>
70
+ <div class='method public-instance' id='method-M000032'>
71
+ <a name='M000032'></a>
72
+ <div class='synopsis'>
73
+ <span class='name'>asset_path</span>
74
+ <span class='arguments'>(type, source)</span>
75
+ </div>
76
+ <div class='description'>
77
+ <p>
78
+ Returns the public URL path to the given source file.
79
+ </p>
80
+ <p>
81
+ <tt>type</tt> argument: <tt>:css</tt> or <tt>:js</tt>
82
+ </p>
83
+ </div>
84
+ <div class='source'>
85
+ <a class='source-toggle' href='#' onclick="toggleCode('M000032-source'); return false">
86
+ [show source]
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>
89
+ </div>
90
+ </div>
91
+ <div class='method public-instance' id='method-M000030'>
92
+ <a name='M000030'></a>
71
93
  <div class='synopsis'>
72
94
  <span class='name'>include_css</span>
73
95
  <span class='arguments'>(*args)</span>
74
96
  </div>
75
97
  <div class='description'>
76
98
  <p>
77
- <tt><a href="AssetHatHelper.html#M000027">include_css</a></tt> is a smart
99
+ <tt><a href="AssetHatHelper.html#M000030">include_css</a></tt> is a smart
78
100
  wrapper for Rails&#8217; <tt>stylesheet_link_tag</tt>. The two can be used
79
101
  together while migrating to <a href="AssetHat.html">AssetHat</a>.
80
102
  </p>
81
103
  <p>
82
- Include a single stylesheet:
104
+ Include a single, minified stylesheet:
83
105
  </p>
84
106
  <pre>include_css 'diagnostics'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/diagnostics.min.css&quot; media=&quot;screen,projection&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</pre>
85
107
  <p>
86
- Include a single unminified stylesheet:
108
+ Include a single, unminified stylesheet:
87
109
  </p>
88
110
  <pre>include_css 'diagnostics.css'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/diagnostics.css&quot; media=&quot;screen,projection&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</pre>
89
111
  <p>
@@ -94,43 +116,65 @@
94
116
  <p>
95
117
  Include multiple stylesheets separately (not as cool):
96
118
  </p>
97
- <pre>include_css 'reset', 'application', 'clearfix'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/reset.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/application.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/clearfix.min.css&quot; ... /&gt;</pre>
119
+ <pre>include_css 'reset', 'application'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/reset.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/application.min.css&quot; ... /&gt;</pre>
98
120
  <p>
99
121
  Include a stylesheet with extra media types:
100
122
  </p>
101
123
  <pre>include_css 'mobile', :media =&gt; 'handheld,screen,projection'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/mobile.min.css&quot;&#x000A; media=&quot;handheld,screen,projection&quot; ... /&gt;</pre>
124
+ <p>
125
+ Get the URL for a single, minified stylesheet:
126
+ </p>
127
+ <pre>include_css 'diagnostics', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/diagnostics.min.css'</pre>
128
+ <p>
129
+ Get the URL for a single, unminified stylesheet:
130
+ </p>
131
+ <pre>include_css 'diagnostics.css', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/diagnostics.css'</pre>
132
+ <p>
133
+ Get the URL for a bundle of stylesheets when environment <b>enables</b>
134
+ caching (e.g., staging, production):
135
+ </p>
136
+ <pre>include_css :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/bundles/application.min.css'</pre>
137
+ <p>
138
+ Get URLs for a bundle of stylesheets when environment <b>disables</b>
139
+ caching (e.g., development, test):
140
+ </p>
141
+ <pre>include_css :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; ['/stylesheets/reset.css', '/stylesheets/common.css', ...]</pre>
142
+ <p>
143
+ Get URLs for multiple stylesheets manually:
144
+ </p>
145
+ <pre>include_css 'reset', 'application', :only_url =&gt; true&#x000A;=&gt; ['/stylesheets/reset.css', '/stylesheets/application.css']</pre>
102
146
  </div>
103
147
  <div class='source'>
104
- <a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false">
148
+ <a class='source-toggle' href='#' onclick="toggleCode('M000030-source'); return false">
105
149
  [show source]
106
150
  </a>
107
- <pre id='M000027-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 129</span>&#x000A;129: <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;130: <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;131: &#x000A;132: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;133: <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;134: &#x000A;135: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;136: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(&#x000A;137: <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;138: <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;139: &#x000A;140: <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;141: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;142: <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;143: <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;144: <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;145: <span class="ruby-keyword kw">end</span>&#x000A;146: &#x000A;147: <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;148: <span class="ruby-identifier">html</span>&#x000A;149: <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-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>
108
152
  </div>
109
153
  </div>
110
- <div class='method public-instance' id='method-M000028'>
111
- <a name='M000028'></a>
154
+ <div class='method public-instance' id='method-M000031'>
155
+ <a name='M000031'></a>
112
156
  <div class='synopsis'>
113
157
  <span class='name'>include_js</span>
114
158
  <span class='arguments'>(*args)</span>
115
159
  </div>
116
160
  <div class='description'>
117
161
  <p>
118
- <tt><a href="AssetHatHelper.html#M000028">include_js</a></tt> is a smart
162
+ <tt><a href="AssetHatHelper.html#M000031">include_js</a></tt> is a smart
119
163
  wrapper for Rails&#8217; <tt>javascript_include_tag</tt>. The two can be
120
164
  used together while migrating to <a href="AssetHat.html">AssetHat</a>.
121
165
  </p>
122
166
  <p>
123
- Include a single JS file:
167
+ Include a single, minified JS file:
124
168
  </p>
125
169
  <pre>include_js 'application'&#x000A;=&gt; &lt;script src=&quot;/javascripts/application.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
126
170
  <p>
127
- Include a single JS unminified file:
171
+ Include a single, unminified JS file:
128
172
  </p>
129
173
  <pre>include_js 'application.js'&#x000A;=&gt; &lt;script src=&quot;/javascripts/application.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
130
174
  <p>
131
175
  Include jQuery:
132
176
  </p>
133
- <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.4'`.</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.0'`.</pre>
134
178
  <p>
135
179
  Include a bundle of JS files (i.e., a concatenated set of files; configure
136
180
  in <tt>config/assets.yml</tt>):
@@ -144,12 +188,43 @@
144
188
  Include multiple JS files separately (not as cool):
145
189
  </p>
146
190
  <pre>include_js 'bloombox', 'jquery.cookie', 'jquery.json.min'&#x000A;=&gt; &lt;script src=&quot;/javascripts/bloombox.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script src=&quot;/javascripts/jquery.cookie.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script src=&quot;/javascripts/jquery.json.min.js&quot; ...&gt;&lt;/script&gt;</pre>
191
+ <p>
192
+ Get the URL for a single, minified JS file:
193
+ </p>
194
+ <pre>include_js 'application', :only_url =&gt; true&#x000A;=&gt; '/javascripts/application.min.js'</pre>
195
+ <p>
196
+ Get the URL for a single, unminified JS file:
197
+ </p>
198
+ <pre>include_js 'application.js', :only_url =&gt; true&#x000A;=&gt; '/javascripts/application.js', :only_url =&gt; true</pre>
199
+ <p>
200
+ Get the URL for jQuery:
201
+ </p>
202
+ <pre># Development/test environment:&#x000A;include_js :jquery, :only_url =&gt; true&#x000A;=&gt; '/javascripts/jquery-VERSION.min.js'&#x000A;&#x000A;# Staging/production environment:&#x000A;include_js :jquery, :only_url =&gt; true&#x000A;=&gt; 'http://ajax.googleapis.com/.../jquery.min.js'</pre>
203
+ <p>
204
+ Get the URL for a bundle of JS files when environment <b>enables</b>
205
+ caching (e.g., staging, production):
206
+ </p>
207
+ <pre>include_js :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; '/javascripts/bundles/application.min.js'</pre>
208
+ <p>
209
+ Get URLs for a bundle of JS files when environment <b>disables</b> caching
210
+ (e.g., development, test):
211
+ </p>
212
+ <pre>include_js :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; ['/javascripts/jquery.plugin-foo.js',&#x000A; '/javascripts/jquery.plugin-bar.min.js',&#x000A; '/javascripts/json2.js',&#x000A; ...]</pre>
213
+ <p>
214
+ Get URLs for multiple JS files manually:
215
+ </p>
216
+ <pre>include_js 'json2', 'application', :only_url =&gt; true&#x000A;=&gt; ['/javascripts/json2.js', '/javascripts/application.js']</pre>
217
+ <p>
218
+ Load JS files with <a href="http://labjs.com">LABjs</a> (hosted either from
219
+ cdnjs or your own web server, if found in <tt>public/javascripts/</tt>):
220
+ </p>
221
+ <pre># config/assets.yml:&#x000A;js:&#x000A; vendors:&#x000A; lab_js:&#x000A; version: 1.x.x&#x000A;&#x000A;# Usage:&#x000A;include_js :jquery, :bundle =&gt; 'application', :loader =&gt; :lab_js&#x000A;=&gt; &lt;script src=&quot;http://ajax.cdnjs.com/.../1.x.x/LAB.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script type=&quot;text/javascript&quot;&gt;&#x000A; window.$LABinst=$LAB.&#x000A; script('http://ajax.googleapis.com/.../jquery.min.js').wait().&#x000A; script('/javascripts/bundles/application.min.js').wait();&#x000A; &lt;/script&gt;&#x000A;&#x000A;# For advanced fine-tuning, build the LABjs calls manually (based on&#x000A;# example from http://labjs.com/documentation.php ):&#x000A;&lt;script&gt;&#x000A; window.$LABinst = $LAB.&#x000A; script('&lt;%= include_js 'framework', :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js 'plugin.framework.js',&#x000A; :only_url =&gt; true %&gt;').&#x000A; script('&lt;%= include_js 'myplugin.framework.js',&#x000A; :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js 'init.js', :only_url =&gt; true %&gt;').wait();&#x000A;&lt;/script&gt;&#x000A;&#x000A;# If you want to execute an inline &lt;script&gt; block that relies on any&#x000A;# of these dependencies, use the JS variable `window.$LABinst`.&#x000A;# Example (using jQuery to handle when DOM is ready):&#x000A;&lt;script&gt;&#x000A;window.$LABinst(function(){&#x000A; console.log('JS dependencies are ready');&#x000A; $(function(){&#x000A; console.log('DOM is ready');&#x000A; });&#x000A;});&#x000A;&lt;/script&gt;</pre>
147
222
  </div>
148
223
  <div class='source'>
149
- <a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false">
224
+ <a class='source-toggle' href='#' onclick="toggleCode('M000031-source'); return false">
150
225
  [show source]
151
226
  </a>
152
- <pre id='M000028-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 189</span>&#x000A;189: <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;190: <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;191: &#x000A;192: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;193: <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;194: &#x000A;195: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;196: <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;197: <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;198: &#x000A;199: <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;200: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;201: &#x000A;202: <span class="ruby-identifier">html</span> = []&#x000A;203: <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;204: <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;205: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;206: <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;207: <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;208: <span class="ruby-identifier">html</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>, <span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)&#x000A;209: <span class="ruby-keyword kw">end</span>&#x000A;210: &#x000A;211: <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;212: &#x000A;213: <span class="ruby-identifier">html</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">options</span>]))&#x000A;214: <span class="ruby-identifier">html</span> = <span class="ruby-identifier">html</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;215: <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;216: <span class="ruby-keyword kw">end</span>&#x000A;217: &#x000A;218: <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;219: <span class="ruby-identifier">html</span>&#x000A;220: <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-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>
153
228
  </div>
154
229
  </div>
155
230
  </div>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Sat, 02 Apr 2011 23:06:30 -0400
1
+ Fri, 06 May 2011 12:24:38 -0400
@@ -31,13 +31,31 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Sat Apr 02 23:06:23 -0400 2011</span>
34
+ <span class='datetime'>Fri May 06 12:23:46 -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.0 (2011-05-06)</h2>
42
+ <ul>
43
+ <li>FEATURE: Added Rails 3 support.
44
+
45
+ </li>
46
+ <li>FEATURE: Added support for loading JavaScript files via LABjs: `<%=
47
+ include_js :jquery, :bundles => %[plugins app], :loader => :lab_js %>`.
48
+ (Provides only basic LABjs support. To build custom JS logic, use the new
49
+ `:only_url` option.)
50
+
51
+ </li>
52
+ <li>FEATURE: Added support for getting asset URLs, e.g.: `<%= include_css
53
+ &#8216;foo&#8217;, :bundle => &#8216;bar&#8217;, :only_url => true %>`,
54
+ `<%= include_js :jquery, &#8216;foo&#8217;, :bundle => &#8216;bar&#8217;,
55
+ :only_url => true %>`.
56
+
57
+ </li>
58
+ </ul>
41
59
  <h2>Version 0.3.1 (2011-04-02)</h2>
42
60
  <ul>
43
61
  <li>IMPROVEMENT: Added tolerance for `.css` and `.js` extensions in assets.yml,
@@ -153,7 +171,7 @@
153
171
  <h2>Version 0.1.2 (2010-01-27)</h2>
154
172
  <ul>
155
173
  <li>IMPROVEMENT: Memoized HTML output from `include_css` and `include_js` when
156
- `<a href="../classes/AssetHat.html#M000009">AssetHat.cache?</a>` is true.
174
+ `<a href="../classes/AssetHat.html#M000011">AssetHat.cache?</a>` is true.
157
175
 
158
176
  </li>
159
177
  </ul>
@@ -31,7 +31,7 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Mon Nov 15 10:51:10 -0500 2010</span>
34
+ <span class='datetime'>Wed Dec 08 14:49:40 -0500 2010</span>
35
35
  </div>
36
36
  </div>
37
37
  <div id='content'>
@@ -31,7 +31,7 @@
31
31
  </div>
32
32
  <div class='last-update'>
33
33
  Last Update:
34
- <span class='datetime'>Wed Dec 08 14:43:30 -0500 2010</span>
34
+ <span class='datetime'>Sun Apr 24 13:42:43 -0400 2011</span>
35
35
  </div>
36
36
  </div>
37
37
  <div id='content'>
@@ -44,16 +44,18 @@
44
44
  <p>
45
45
  With Rails&#8217; default asset caching, CSS and JS are concatenated (not
46
46
  even minified) at runtime when that bundle is first requested. Not good
47
- enough. <a href="../classes/AssetHat.html">AssetHat</a> can automatically:
47
+ enough. To make your pages load faster, <a
48
+ href="../classes/AssetHat.html">AssetHat</a> can automatically:
48
49
  </p>
49
50
  <ul>
50
- <li>Easily <b>minify</b> and <b>bundle</b> CSS and JS on deploy to reduce file
51
- sizes and HTTP requests.
51
+ <li>Easily <b>minify</b> and <b>bundle</b> CSS and JS to reduce file sizes and
52
+ HTTP requests. Do this on deploy, and avoid any performance hit at runtime.
52
53
 
53
54
  </li>
54
- <li>Load popular <b>third-party JS</b> (like jQuery and Prototype) from <a
55
+ <li>Load popular <b>third-party JS</b> (like jQuery, YUI, and Ext JS) from <a
55
56
  href="http://code.google.com/apis/ajaxlibs/">Google's CDN</a> when in
56
- production, or from localhost in development.
57
+ production, or from localhost in development. It&#8217;s as simple as
58
+ <tt>&lt;%= include_js :jquery %&gt;</tt> to load straight from Google.
57
59
 
58
60
  </li>
59
61
  <li>Force image URLs in your CSS to use <b>CDN subdomains</b> (including SSL
@@ -71,11 +73,18 @@
71
73
  </p>
72
74
  <pre>&lt;%= include_css :bundle =&gt; 'application' %&gt;&#x000A;&lt;%= include_js :jquery, :bundles =&gt; ['plugins', 'common'] %&gt;</pre>
73
75
  <p>
74
- Which turns into:
76
+ Which expands into:
75
77
  </p>
76
78
  <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>
77
79
  <p>
78
- And this in your deploy script:
80
+ 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.
84
+ </p>
85
+ <p>
86
+ Add this to your deploy script, and your CSS/JS will be optimized
87
+ automatically:
79
88
  </p>
80
89
  <pre>rake asset_hat:minify</pre>
81
90
  <p>
@@ -88,12 +97,26 @@
88
97
  history</a>.
89
98
  </p>
90
99
  <h2>Installation</h2>
100
+ <ul>
101
+ <li>Rails 3.x:
102
+
91
103
  <ol>
92
- <li>Configure the gem:
104
+ <li>Add to your app&#8217;s Gemfile: <tt>gem 'asset_hat', '0.x.x'</tt>
105
+
106
+ </li>
107
+ <li>Command-line: <tt>bundle install</tt>
108
+
109
+ </li>
110
+ </ol>
111
+ </li>
112
+ <li>Rails 2.3.x:
113
+
114
+ <ol>
115
+ <li>Add the gem:
93
116
 
94
117
  <ul>
95
- <li>If you&#8217;re using Rails 3 and/or <a
96
- href="http://github.com/carlhuda/bundler">Bundler 0.9+</a>:
118
+ <li>If you&#8217;re using <a href="http://github.com/carlhuda/bundler">Bundler
119
+ 0.9+</a>:
97
120
 
98
121
  <ol>
99
122
  <li>Add to your app&#8217;s Gemfile: <tt>gem 'asset_hat', '0.x.x'</tt>
@@ -104,7 +127,7 @@
104
127
  </li>
105
128
  </ol>
106
129
  </li>
107
- <li>If you&#8217;re using Rails 2.x&#8217;s <tt>config.gem</tt>:
130
+ <li>If you&#8217;re using Rails 2.3.x&#8217;s <tt>config.gem</tt>:
108
131
 
109
132
  <ol>
110
133
  <li>Add to your app&#8217;s <tt>config/environment.rb</tt>: <tt>config.gem
@@ -122,8 +145,16 @@
122
145
 
123
146
  </li>
124
147
  </ol>
125
- <h2>Configuration</h2>
148
+ </li>
149
+ </ul>
150
+ <h2>Quick start &amp; configuration</h2>
126
151
  <ol>
152
+ <li>In all of your layouts and views, change <tt>stylesheet_link_tag</tt> to
153
+ <tt>include_css</tt>, and change <tt>javascript_include_tag</tt> to
154
+ <tt>include_js</tt>. (Don&#8217;t worry, these helpers use the same
155
+ arguments as Rails&#8217; helpers. Nothing will break.)
156
+
157
+ </li>
127
158
  <li>Create the default config file:
128
159
 
129
160
  <pre>rake asset_hat:config</pre>
@@ -132,7 +163,16 @@
132
163
  your CSS/JS bundles according to that file&#8217;s example.
133
164
 
134
165
  </li>
135
- <li>Minify your bundles:
166
+ <li>In your layouts and views, switch to the new bundles. For example, if you
167
+ originally had this:
168
+
169
+ <pre>&lt;%# app/views/layouts/application.html.erb: %&gt;&#x000A;&lt;%= stylesheet_include_tag 'reset', 'application' %&gt;</pre>
170
+ <p>
171
+ Then you&#8217;ll now have:
172
+ </p>
173
+ <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
+ </li>
175
+ <li>Add this to your deployment script:
136
176
 
137
177
  <pre>rake asset_hat:minify</pre>
138
178
  <p>
@@ -141,15 +181,11 @@
141
181
  and cache-busting commit IDs to image URLs in your CSS.
142
182
  </p>
143
183
  <p>
144
- Bundles are created as new files in <tt>public/stylesheets/bundles/</tt>
145
- and <tt>public/javascripts/bundles/</tt>. Your original CSS/JS files remain
146
- untouched.
184
+ Any previously minified bundles are overwritten; your original CSS/JS files
185
+ remain untouched. Bundles are created as new files in
186
+ <tt>public/stylesheets/bundles/</tt> and
187
+ <tt>public/javascripts/bundles/</tt>.
147
188
  </p>
148
- </li>
149
- <li>Set your deployment script to run <tt>rake asset_hat:minify</tt> after
150
- deploying your latest CSS/JS. This overwrites previously minified bundles,
151
- and leaves your original CSS/JS files untouched.
152
-
153
189
  </li>
154
190
  </ol>
155
191
  <h3>Advanced configuration</h3>
@@ -157,7 +193,13 @@
157
193
  If you manage deployments with <a
158
194
  href="http://www.capify.org/">Capistrano</a>, see the gem&#8217;s packaged
159
195
  example at <tt><a
160
- href="lib/asset_hat/capistrano_rb.html">lib/asset_hat/capistrano.rb</a></tt>.
196
+ href="https://github.com/mintdigital/asset_hat/blob/master/lib/asset_hat/capistrano.rb">lib/asset_hat/capistrano.rb</a></tt>.
197
+ </p>
198
+ <p>
199
+ If your stack uses <a href="http://unicorn.bogomips.org/">Unicorn</a>,
200
+ you&#8217;ll want to configure it so that assets&#8217; commit IDs are
201
+ precached only once. See the gem&#8217;s packaged example at <tt><a
202
+ href="https://github.com/mintdigital/asset_hat/blob/master/lib/asset_hat/unicorn.rb">lib/asset_hat/unicorn.rb</a></tt>.
161
203
  </p>
162
204
  <p>
163
205
  If you want shorter output during deployments, you can use `rake
@@ -185,13 +227,13 @@
185
227
  or other external source. The following example configures jQuery and
186
228
  jQuery UI for use throughout the app:
187
229
 
188
- <pre>js:&#x000A; vendors:&#x000A; jquery:&#x000A; version: 1.4.4&#x000A; jquery_ui:&#x000A; version: 1.8.5&#x000A; remote_url: http://cdn.example.com/js/jquery-ui-1.8.5.min.js&#x000A; remote_ssl_url: https://cdn-ssl.example.com/js/jquery-ui-1.8.5.min.js</pre>
230
+ <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>
189
231
  <p>
190
232
  Configuration keys per vendor:
191
233
  </p>
192
234
  <ul>
193
235
  <li><tt>version</tt>: Sets the default version across the app. In the example
194
- above, <tt>&lt;%= include_js :jquery %&gt;</tt> uses version 1.4.4 by
236
+ above, <tt>&lt;%= include_js :jquery %&gt;</tt> uses version 1.5.2 by
195
237
  default. You can override this for special layouts/views with <tt>&lt;%=
196
238
  include_js :jquery, :version =&gt; '1.3.2' %&gt;</tt>.
197
239
 
@@ -277,14 +319,28 @@
277
319
  When including multiple bundles at once, this yields one
278
320
  <tt>&lt;link&gt;</tt> or <tt>&lt;script&gt;</tt> element per bundle.
279
321
  </p>
322
+ <h3>Bundle tips</h3>
280
323
  <p>
281
- You may want to use multiple bundles to separate plugins (rarely changed)
282
- from application code (frequently changed). If all code is in one huge
283
- bundle, then whenever there&#8217;s a change, browsers have to re-download
284
- the whole bundle. By using multiple bundles based on update frequency,
285
- browsers cache the rarely updated code, and only re-download the frequently
286
- updated code.
324
+ Don&#8217;t go overboard with huge bundles:
287
325
  </p>
326
+ <ul>
327
+ <li>Mobile browsers may not cache CSS/JS files that are too large, regardless
328
+ of gzipping. Check the latest specs for each mobile browser you support.
329
+
330
+ </li>
331
+ <li>You might want to put plugins (rarely changed) in one bundle, and
332
+ application code (frequently changed) in another bundle. This way, when the
333
+ app code changes, the browser re-downloads only the new app code, and uses
334
+ the cached plugin code.
335
+
336
+ </li>
337
+ <li>Regardless of code-change frequency, it&#8217;s sometimes faster to split a
338
+ 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
340
+ situation.
341
+
342
+ </li>
343
+ </ul>
288
344
  <h2><a href="http://www.youtube.com/watch?v=V30tyaXv6EI">What is best in AssetHat?</a></h2>
289
345
  <ul>
290
346
  <li>To crush your assets;