asset_hat 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +38 -19
- data/README.rdoc +99 -41
- data/Rakefile +17 -10
- data/VERSION.yml +3 -3
- data/app/helpers/asset_hat_helper.rb +40 -20
- data/asset_hat.gemspec +105 -101
- data/doc/classes/AssetHat.html +173 -59
- data/doc/classes/AssetHat/CSS.html +35 -26
- data/doc/classes/AssetHat/CSS/Engines.html +13 -12
- data/doc/classes/AssetHat/JS.html +11 -11
- data/doc/classes/AssetHat/JS/Engines.html +10 -10
- data/doc/classes/AssetHat/JS/Vendors.html +9 -5
- data/doc/classes/AssetHatHelper.html +18 -14
- data/doc/created.rid +1 -1
- data/doc/files/HISTORY.html +66 -24
- data/doc/files/LICENSE.html +1 -1
- data/doc/files/README_rdoc.html +112 -37
- data/doc/files/app/helpers/asset_hat_helper_rb.html +1 -1
- data/doc/files/lib/asset_hat/capistrano_rb.html +1 -1
- data/doc/files/lib/asset_hat/css_rb.html +1 -1
- data/doc/files/lib/asset_hat/js/vendors_rb.html +1 -1
- data/doc/files/lib/asset_hat/js_rb.html +1 -1
- data/doc/files/lib/asset_hat/tasks/css_rb.html +1 -1
- data/doc/files/lib/asset_hat/tasks/js_rb.html +1 -1
- data/doc/files/lib/asset_hat/tasks_rb.html +1 -1
- data/doc/files/lib/asset_hat/vcs_rb.html +1 -1
- data/doc/files/lib/asset_hat/version_rb.html +1 -1
- data/doc/files/lib/asset_hat_rb.html +1 -1
- data/doc/fr_method_index.html +54 -46
- data/lib/asset_hat.rb +100 -16
- data/lib/asset_hat/capistrano.rb +4 -3
- data/lib/asset_hat/css.rb +69 -20
- data/lib/asset_hat/js.rb +2 -2
- data/lib/asset_hat/js/vendors.rb +14 -10
- data/lib/asset_hat/tasks.rb +22 -3
- data/lib/asset_hat/tasks/css.rb +118 -74
- data/lib/asset_hat/tasks/js.rb +79 -35
- data/lib/asset_hat/vcs.rb +19 -0
- data/public/stylesheets/bundles/ssl/css-bundle-1.min.css +3 -0
- data/public/stylesheets/bundles/ssl/css-bundle-2.min.css +3 -0
- data/public/stylesheets/bundles/ssl/css-bundle-3.min.css +3 -0
- data/rails/init.rb +1 -16
- data/test/asset_hat_helper_test.rb +172 -28
- data/test/asset_hat_test.rb +167 -25
- metadata +54 -21
- data/.gitignore +0 -2
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Wed,
|
1
|
+
Wed, 08 Dec 2010 12:26:28 -0500
|
data/doc/files/HISTORY.html
CHANGED
@@ -31,80 +31,122 @@
|
|
31
31
|
</div>
|
32
32
|
<div class='last-update'>
|
33
33
|
Last Update:
|
34
|
-
<span class='datetime'>
|
34
|
+
<span class='datetime'>Mon Nov 15 10:51:12 -0500 2010</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
|
+
<ul>
|
42
|
+
<li>FEATURE: Added ERb support in `config/assets.yml`.
|
43
|
+
|
44
|
+
</li>
|
45
|
+
<li>FEATURE: Added support for auto-creating SSL versions of every stylesheet.
|
46
|
+
|
47
|
+
</li>
|
48
|
+
<li>FEATURE: Added support for loading remote JS via SSL. Includes loading
|
49
|
+
popular JS from `<a
|
50
|
+
href="https://ajax.googleapis.com">ajax.googleapis.com</a>` or your own
|
51
|
+
CDN.
|
52
|
+
|
53
|
+
</li>
|
54
|
+
<li>FEATURE: Added support for `FORMAT=long|short|dot` flags for `rake
|
55
|
+
asset_hat:minify`. Useful for shortening output from deployment scripts.
|
56
|
+
|
57
|
+
</li>
|
58
|
+
<li>FEATURE: Added support for absolute paths in `config/assets.yml`. Allows
|
59
|
+
pointing to assets directly inside `public/`.
|
60
|
+
|
61
|
+
</li>
|
62
|
+
<li>FEATURE: Added `asset_hat:minify:css` and `asset_hat:minify:js` Rake task
|
63
|
+
aliases.
|
64
|
+
|
65
|
+
</li>
|
66
|
+
<li>IMPROVEMENT: Updated default CSS minification engine to remove rules that
|
67
|
+
have empty declaration blocks.
|
68
|
+
|
69
|
+
</li>
|
70
|
+
<li>IMPROVEMENT: Stopped pre-caching asset commit IDs when launching console.
|
71
|
+
|
72
|
+
</li>
|
73
|
+
<li>IMPROVEMENT: Added support for single/double quotation marks in `url()` CSS
|
74
|
+
when adding asset hosts and cache busters
|
75
|
+
|
76
|
+
</li>
|
77
|
+
<li>FIX: Fixed adding asset commit IDs to URLs containing “?” in
|
78
|
+
stylesheets.
|
79
|
+
|
80
|
+
</li>
|
81
|
+
</ul>
|
41
82
|
<h2>Version 0.2.1 (2010-07-21)</h2>
|
42
83
|
<ul>
|
43
|
-
<li>Added WebFont Loader to supported JS vendors.
|
44
|
-
|
84
|
+
<li>FEATURE: Added WebFont Loader to supported JS vendors.
|
85
|
+
|
45
86
|
</li>
|
46
|
-
<li>Stopped adding asset hosts to `url(/htc/...)` URLs because IE 6, by
|
87
|
+
<li>FIX: Stopped adding asset hosts to `url(/htc/...)` URLs because IE 6, by
|
47
88
|
default, refuses to run .htc files from other domains, including CDN
|
48
89
|
subdomains.
|
49
|
-
|
90
|
+
|
50
91
|
</li>
|
51
92
|
</ul>
|
52
93
|
<h2>Version 0.2.0 (2010-06-10)</h2>
|
53
94
|
<ul>
|
54
|
-
<li>Added support for loading many more JS vendors from Google’s
|
55
|
-
including Prototype, MooTools, and SWFObject.
|
95
|
+
<li>FEATURE: Added support for loading many more JS vendors from Google’s
|
96
|
+
CDN, including Prototype, MooTools, and SWFObject.
|
56
97
|
|
57
98
|
</li>
|
58
|
-
<li>Cleaned up existing docs, and added complete RDoc documentation.
|
99
|
+
<li>FEATURE: Cleaned up existing docs, and added complete RDoc documentation.
|
59
100
|
|
60
101
|
</li>
|
61
|
-
<li>Added example integration script for Capistrano deployments.
|
102
|
+
<li>FEATURE: Added example integration script for Capistrano deployments.
|
62
103
|
|
63
104
|
</li>
|
64
105
|
</ul>
|
65
106
|
<h2>Version 0.1.5 (2010-03-11)</h2>
|
66
107
|
<ul>
|
67
|
-
<li>Fixed fetching asset commit IDs in some environments. The bug was
|
68
|
-
caused by older versions of Git, which fail to read logs properly
|
69
|
-
given absolute paths, rather than relative paths.
|
108
|
+
<li>FIX: Fixed fetching asset commit IDs in some environments. The bug was
|
109
|
+
possibly caused by older versions of Git, which fail to read logs properly
|
110
|
+
when given absolute paths, rather than relative paths.
|
70
111
|
|
71
112
|
</li>
|
72
|
-
<li>Stopped app tests from running twice in some environments.
|
113
|
+
<li>FIX: Stopped app tests from running twice in some environments.
|
73
114
|
|
74
115
|
</li>
|
75
116
|
</ul>
|
76
117
|
<h2>Version 0.1.4 (2010-03-03)</h2>
|
77
118
|
<ul>
|
78
|
-
<li>Fixed config filepaths in `asset_hat:config` task.
|
119
|
+
<li>FIX: Fixed config filepaths in `asset_hat:config` task.
|
79
120
|
|
80
121
|
</li>
|
81
122
|
</ul>
|
82
123
|
<h2>Version 0.1.3 (2010-03-03)</h2>
|
83
124
|
<ul>
|
84
|
-
<li>Allowed adding commit IDs and asset hosts to `url(/htc/...)` URLs
|
85
|
-
`/htc/iepngfix.htc`) in CSS, not just images.
|
125
|
+
<li>FIX: Allowed adding commit IDs and asset hosts to `url(/htc/...)` URLs
|
126
|
+
(e.g., `/htc/iepngfix.htc`) in CSS, not just images.
|
86
127
|
|
87
128
|
</li>
|
88
|
-
<li>Changed `<a
|
89
|
-
|
90
|
-
|
129
|
+
<li>FIX: Changed `<a
|
130
|
+
href="../classes/AssetHat.html#M000005">AssetHat.config</a>` to memoize
|
131
|
+
only if `cache?` is true. In development environments, this means the
|
132
|
+
config file will be reread with every request.
|
91
133
|
|
92
134
|
</li>
|
93
135
|
</ul>
|
94
136
|
<h2>Version 0.1.2 (2010-01-27)</h2>
|
95
137
|
<ul>
|
96
|
-
<li>Memoized HTML output from `include_css` and `include_js` when
|
97
|
-
href="../classes/AssetHat.html#
|
138
|
+
<li>IMPROVEMENT: Memoized HTML output from `include_css` and `include_js` when
|
139
|
+
`<a href="../classes/AssetHat.html#M000009">AssetHat.cache?</a>` is true.
|
98
140
|
|
99
141
|
</li>
|
100
142
|
</ul>
|
101
143
|
<h2>Version 0.1.1 (2010-01-20)</h2>
|
102
144
|
<ul>
|
103
|
-
<li>Rewrote `AssetHat::VERSION` to be based on `VERSION.yml`.
|
145
|
+
<li>FIX: Rewrote `AssetHat::VERSION` to be based on `VERSION.yml`.
|
104
146
|
|
105
147
|
</li>
|
106
|
-
<li>Prefixed `AssetHat::CONFIG_FILEPATH` with `RAILS_ROOT`, which fixes
|
107
|
-
to run an app’s individual test files.
|
148
|
+
<li>FIX: Prefixed `AssetHat::CONFIG_FILEPATH` with `RAILS_ROOT`, which fixes
|
149
|
+
ability to run an app’s individual test files.
|
108
150
|
|
109
151
|
</li>
|
110
152
|
</ul>
|
data/doc/files/LICENSE.html
CHANGED
data/doc/files/README_rdoc.html
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
</div>
|
32
32
|
<div class='last-update'>
|
33
33
|
Last Update:
|
34
|
-
<span class='datetime'>Wed
|
34
|
+
<span class='datetime'>Wed Dec 08 12:26:25 -0500 2010</span>
|
35
35
|
</div>
|
36
36
|
</div>
|
37
37
|
<div id='content'>
|
@@ -51,43 +51,47 @@
|
|
51
51
|
sizes and HTTP requests.
|
52
52
|
|
53
53
|
</li>
|
54
|
-
<li>Load popular <
|
55
|
-
|
56
|
-
|
54
|
+
<li>Load popular <b>third-party JS</b> (like jQuery and Prototype) from <a
|
55
|
+
href="http://code.google.com/apis/ajaxlibs/">Google's CDN</a> when in
|
56
|
+
production, or from localhost in development.
|
57
57
|
|
58
58
|
</li>
|
59
|
-
<li>Force image URLs in your CSS to use <
|
60
|
-
just the current host.
|
59
|
+
<li>Force image URLs in your CSS to use <b>CDN subdomains</b> (including SSL
|
60
|
+
support), not just the current host.
|
61
61
|
|
62
62
|
</li>
|
63
63
|
<li>Add an image’s last <a href="http://git-scm.com/">Git</a> commit ID
|
64
|
-
to its CSS URLs to <
|
65
|
-
<tt>/images/foo.png?
|
64
|
+
to its CSS URLs to <b>bust browser caches</b> (e.g.,
|
65
|
+
<tt>/images/foo.png?ab12cd3</tt>).
|
66
66
|
|
67
67
|
</li>
|
68
68
|
</ul>
|
69
69
|
<p>
|
70
|
-
After setup, you can use
|
70
|
+
After setup, you can use this in your layouts and views:
|
71
71
|
</p>
|
72
|
-
<pre><%= include_css :bundle => 'application' %>

|
72
|
+
<pre><%= include_css :bundle => 'application' %>
<%= include_js :jquery, :bundles => ['plugins', 'common'] %></pre>
|
73
|
+
<p>
|
74
|
+
Which turns into:
|
75
|
+
</p>
|
76
|
+
<pre><link href="/stylesheets/bundles/application.min.css"
 media="screen,projection" rel="stylesheet" type="text/css" />
<script src="/javascripts/jquery-1.x.x.min.js"
 type="text/javascript"></script>
 <!-- In production, jQuery loads from Google's CDN instead. -->
<script src="/javascripts/bundles/plugins.min.js"
 type="text/javascript"></script>
<script src="/javascripts/bundles/common.min.js"
 type="text/javascript"></script></pre>
|
73
77
|
<p>
|
74
78
|
And this in your deploy script:
|
75
79
|
</p>
|
76
80
|
<pre>rake asset_hat:minify</pre>
|
77
81
|
<p>
|
78
|
-
Tested with Rails 2.3.x.
|
82
|
+
Tested with Rails 2.3.x. For the gritty details, check the <a
|
83
|
+
href="http://mintdigital.github.com/asset_hat/doc/">complete docs</a> and
|
84
|
+
<a
|
85
|
+
href="http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html">change
|
86
|
+
history</a>.
|
79
87
|
</p>
|
80
88
|
<h2>Installation</h2>
|
81
89
|
<ol>
|
82
|
-
<li>Install the gem:
|
83
|
-
|
84
|
-
<pre>gem install asset_hat</pre>
|
85
|
-
</li>
|
86
90
|
<li>Configure the gem:
|
87
91
|
|
88
92
|
<ul>
|
89
|
-
<li>If you’re using <a
|
90
|
-
0.9+</a>:
|
93
|
+
<li>If you’re using Rails 3 and/or <a
|
94
|
+
href="http://github.com/carlhuda/bundler">Bundler 0.9+</a>:
|
91
95
|
|
92
96
|
<ol>
|
93
97
|
<li>Add to your app’s Gemfile: <tt>gem 'asset_hat', '0.x.x'</tt>
|
@@ -98,16 +102,22 @@
|
|
98
102
|
</li>
|
99
103
|
</ol>
|
100
104
|
</li>
|
101
|
-
<li>If you’re using Rails’ <tt>config.gem</tt
|
102
|
-
app’s <tt>config/environment.rb</tt>:
|
105
|
+
<li>If you’re using Rails 2.x’s <tt>config.gem</tt>:
|
103
106
|
|
104
|
-
<
|
107
|
+
<ol>
|
108
|
+
<li>Add to your app’s <tt>config/environment.rb</tt>: <tt>config.gem
|
109
|
+
'asset_hat', :version => '0.x.x'</tt>
|
110
|
+
|
111
|
+
</li>
|
112
|
+
<li>Command-line: <tt>gem install asset_hat</tt>
|
113
|
+
|
114
|
+
</li>
|
115
|
+
</ol>
|
105
116
|
</li>
|
106
117
|
</ul>
|
107
118
|
</li>
|
108
|
-
<li>Add to your app’s Rakefile:
|
119
|
+
<li>Add to your app’s Rakefile: <tt>require 'asset_hat/tasks'</tt>
|
109
120
|
|
110
|
-
<pre>require 'asset_hat/tasks'</pre>
|
111
121
|
</li>
|
112
122
|
</ol>
|
113
123
|
<h2>Configuration</h2>
|
@@ -131,12 +141,12 @@
|
|
131
141
|
<p>
|
132
142
|
Bundles are created as new files in <tt>public/stylesheets/bundles/</tt>
|
133
143
|
and <tt>public/javascripts/bundles/</tt>. Your original CSS/JS files remain
|
134
|
-
|
144
|
+
untouched.
|
135
145
|
</p>
|
136
146
|
</li>
|
137
147
|
<li>Set your deployment script to run <tt>rake asset_hat:minify</tt> after
|
138
148
|
deploying your latest CSS/JS. This overwrites previously minified bundles,
|
139
|
-
and leaves your original CSS/JS files
|
149
|
+
and leaves your original CSS/JS files untouched.
|
140
150
|
|
141
151
|
</li>
|
142
152
|
</ol>
|
@@ -148,6 +158,11 @@
|
|
148
158
|
href="lib/asset_hat/capistrano_rb.html">lib/asset_hat/capistrano.rb</a></tt>.
|
149
159
|
</p>
|
150
160
|
<p>
|
161
|
+
If you want shorter output during deployments, you can use `rake
|
162
|
+
asset_hat:minify FORMAT=short` (one output line per bundle) or `FORMAT=dot`
|
163
|
+
(one output line total) in your deploy script.
|
164
|
+
</p>
|
165
|
+
<p>
|
151
166
|
Additional settings are supported in <tt>config/assets.yml</tt>:
|
152
167
|
</p>
|
153
168
|
<ul>
|
@@ -159,28 +174,70 @@
|
|
159
174
|
Ruby port of Crockford’s JSMin).
|
160
175
|
|
161
176
|
<p>
|
162
|
-
If
|
163
|
-
|
164
|
-
|
177
|
+
If you’d prefer to have slightly more readable code for debugging
|
178
|
+
purposes, you can switch both the CSS and JS engines to <tt>weak</tt>.
|
179
|
+
However, the <tt>weak</tt> engines don’t save as many bytes.
|
165
180
|
</p>
|
166
181
|
</li>
|
167
|
-
<li><tt>vendors</tt>:
|
168
|
-
|
182
|
+
<li><tt>vendors</tt>: Configures third-party JS that’s loaded from a CDN
|
183
|
+
or other external source. The following example configures jQuery and
|
184
|
+
jQuery UI for use throughout the app:
|
185
|
+
|
186
|
+
<pre>js:
 vendors:
 jquery:
 version: 1.4.4
 jquery_ui:
 version: 1.8.5
 remote_url: http://cdn.example.com/js/jquery-ui-1.8.5.min.js
 remote_ssl_url: https://cdn-ssl.example.com/js/jquery-ui-1.8.5.min.js</pre>
|
187
|
+
<p>
|
188
|
+
Configuration keys per vendor:
|
189
|
+
</p>
|
190
|
+
<ul>
|
191
|
+
<li><tt>version</tt>: Sets the default version across the app. In the example
|
192
|
+
above, <tt><%= include_js :jquery %></tt> uses version 1.4.4 by
|
193
|
+
default. You can override this for special layouts/views with <tt><%=
|
194
|
+
include_js :jquery, :version => '1.3.2' %></tt>.
|
195
|
+
|
196
|
+
</li>
|
197
|
+
<li><tt>remote_url</tt>, <tt>remote_ssl_url</tt>: By default, vendor JS will
|
198
|
+
load from <a href="http://code.google.com/apis/ajaxlibs/">Google's CDN</a>
|
199
|
+
in production (or any environment where
|
200
|
+
<tt>config.action_controller.consider_all_requests_local</tt> is set to
|
201
|
+
<tt>true</tt>). If the original request to your app used SSL, the vendor JS
|
202
|
+
will also load from Google’s CDN via SSL. If you prefer to use a
|
203
|
+
different CDN, specify its SSL/non-SSL URLs, and the appropriate URL will
|
204
|
+
be used per request.
|
169
205
|
|
170
|
-
|
206
|
+
</li>
|
207
|
+
</ul>
|
171
208
|
<p>
|
172
|
-
|
173
|
-
|
209
|
+
A full list of supported vendors is in the <a
|
210
|
+
href="../classes/AssetHat/JS/Vendors.html">AssetHat::JS::Vendors</a>
|
211
|
+
module.
|
174
212
|
</p>
|
175
213
|
</li>
|
176
214
|
</ul>
|
215
|
+
<h3>SSL configuration</h3>
|
216
|
+
<p>
|
217
|
+
When you request a page via SSL, some browsers (euphemism for
|
218
|
+
“IE”) show errors if any assets — stylesheets, JS files,
|
219
|
+
images — are served <em>without</em> SSL.
|
220
|
+
</p>
|
221
|
+
<p>
|
222
|
+
<a href="../classes/AssetHat.html">AssetHat</a> plays well with SSL pages
|
223
|
+
that load assets from a CDN. Put this in
|
224
|
+
<tt>config/environments/production.rb</tt> or similar:
|
225
|
+
</p>
|
226
|
+
<pre>config.action_controller.asset_host = Proc.new do |source, request|
 "#{request.protocol}cdn#{source.hash % 4}.example.com"
 # => 'http://cdn0.example.com', 'https://cdn1.example.com', etc.
end</pre>
|
227
|
+
<p>
|
228
|
+
This switches to a different CDN URL if the request used SSL. When you run
|
229
|
+
<tt>rake asset_hat:minify</tt> at deploy time, <a
|
230
|
+
href="../classes/AssetHat.html">AssetHat</a> detects this configuration,
|
231
|
+
and generates special SSL versions of each stylesheet that also load images
|
232
|
+
from CDN via SSL. (Non-SSL pages still get non-SSL stylesheets.)
|
233
|
+
</p>
|
177
234
|
<h2>Usage</h2>
|
178
235
|
<p>
|
179
|
-
In your layouts and views, instead of these
|
236
|
+
In your layouts and views, <b>instead of these</b>:
|
180
237
|
</p>
|
181
238
|
<pre><%= stylesheet_link_tag 'reset', 'application', 'clearfix',
 :media => 'screen,projection',
 :cache => 'bundles/application' %>
<%= javascript_include_tag 'plugin-1', 'plugin-2', 'plugin-3',
 :cache => 'bundles/application' %></pre>
|
182
239
|
<p>
|
183
|
-
<
|
240
|
+
<b>Use these:</b>
|
184
241
|
</p>
|
185
242
|
<pre><%= include_css :bundle => 'application' %>
<%= include_js :bundle => 'application' %></pre>
|
186
243
|
<p>
|
@@ -199,6 +256,12 @@
|
|
199
256
|
included, based on the bundle contents you define in
|
200
257
|
<tt>config/assets.yml</tt>.
|
201
258
|
</p>
|
259
|
+
<p>
|
260
|
+
If your environment has <tt>config.action_controller.asset_host</tt>
|
261
|
+
pointing to a CDN, your CSS/JS files will load from there. If your
|
262
|
+
configuration supports using the CDN via SSL (see the section “SSL
|
263
|
+
configuration”), SSL requests will also load CSS/JS files via SSL.
|
264
|
+
</p>
|
202
265
|
<h3>Advanced usage</h3>
|
203
266
|
<p>
|
204
267
|
You can also include single files as expected:
|
@@ -216,10 +279,22 @@
|
|
216
279
|
You may want to use multiple bundles to separate plugins (rarely changed)
|
217
280
|
from application code (frequently changed). If all code is in one huge
|
218
281
|
bundle, then whenever there’s a change, browsers have to re-download
|
219
|
-
the whole bundle. By using multiple bundles based on
|
220
|
-
browsers cache the rarely
|
221
|
-
|
282
|
+
the whole bundle. By using multiple bundles based on update frequency,
|
283
|
+
browsers cache the rarely updated code, and only re-download the frequently
|
284
|
+
updated code.
|
222
285
|
</p>
|
286
|
+
<h2><a href="http://www.youtube.com/watch?v=V30tyaXv6EI">What is best in AssetHat?</a></h2>
|
287
|
+
<ul>
|
288
|
+
<li>To crush your assets;
|
289
|
+
|
290
|
+
</li>
|
291
|
+
<li>See them bundled before you; and
|
292
|
+
|
293
|
+
</li>
|
294
|
+
<li>Hear no more lamentation about slow page loads.
|
295
|
+
|
296
|
+
</li>
|
297
|
+
</ul>
|
223
298
|
</div>
|
224
299
|
<div id='section'>
|
225
300
|
</div>
|