asset_hat 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/HISTORY +13 -14
  2. data/README.rdoc +171 -0
  3. data/Rakefile +24 -2
  4. data/VERSION.yml +3 -3
  5. data/app/helpers/asset_hat_helper.rb +67 -61
  6. data/asset_hat.gemspec +42 -8
  7. data/doc/classes/AssetHat/CSS/Engines.html +118 -0
  8. data/doc/classes/AssetHat/CSS.html +194 -0
  9. data/doc/classes/AssetHat/JS/Engines.html +122 -0
  10. data/doc/classes/AssetHat/JS/Vendors.html +110 -0
  11. data/doc/classes/AssetHat/JS.html +151 -0
  12. data/doc/classes/AssetHat.html +446 -0
  13. data/doc/classes/AssetHatHelper.html +161 -0
  14. data/doc/created.rid +1 -0
  15. data/doc/files/HISTORY.html +116 -0
  16. data/doc/files/LICENSE.html +76 -0
  17. data/doc/files/README_rdoc.html +234 -0
  18. data/doc/files/app/helpers/asset_hat_helper_rb.html +55 -0
  19. data/doc/files/lib/asset_hat/capistrano_rb.html +49 -0
  20. data/doc/files/lib/asset_hat/css_rb.html +57 -0
  21. data/doc/files/lib/asset_hat/js/vendors_rb.html +49 -0
  22. data/doc/files/lib/asset_hat/js_rb.html +57 -0
  23. data/doc/files/lib/asset_hat/tasks/css_rb.html +49 -0
  24. data/doc/files/lib/asset_hat/tasks/js_rb.html +49 -0
  25. data/doc/files/lib/asset_hat/tasks_rb.html +58 -0
  26. data/doc/files/lib/asset_hat/vcs_rb.html +49 -0
  27. data/doc/files/lib/asset_hat/version_rb.html +49 -0
  28. data/doc/files/lib/asset_hat_rb.html +49 -0
  29. data/doc/fr_class_index.html +23 -0
  30. data/doc/fr_file_index.html +33 -0
  31. data/doc/fr_method_index.html +4455 -0
  32. data/doc/index.html +15 -0
  33. data/doc/rdoc-style.css +328 -0
  34. data/lib/asset_hat/capistrano.rb +14 -0
  35. data/lib/asset_hat/css.rb +40 -10
  36. data/lib/asset_hat/js/vendors.rb +85 -0
  37. data/lib/asset_hat/js.rb +28 -29
  38. data/lib/asset_hat/tasks/css.rb +151 -0
  39. data/lib/asset_hat/tasks/js.rb +100 -0
  40. data/lib/asset_hat/tasks.rb +4 -272
  41. data/lib/asset_hat/vcs.rb +23 -20
  42. data/lib/asset_hat/version.rb +2 -0
  43. data/lib/asset_hat.rb +94 -19
  44. data/tasks/asset_hat.rake +1 -1
  45. data/test/asset_hat_helper_test.rb +63 -9
  46. data/test/test_helper.rb +5 -1
  47. metadata +94 -26
  48. data/README.markdown +0 -154
data/doc/index.html ADDED
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
2
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
+ <head>
4
+ <title>AssetHat</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ </head>
7
+ <frameset border='1' bordercolor='gray' cols='20%, *' frameborder='1'>
8
+ <frameset rows='15%, 35%, 50%'>
9
+ <frame name='Files' src='fr_file_index.html' title='Files'></frame>
10
+ <frame name='Classes' src='fr_class_index.html'></frame>
11
+ <frame name='Methods' src='fr_method_index.html'></frame>
12
+ </frameset>
13
+ <frame name='docwin' src='files/README_rdoc.html'></frame>
14
+ </frameset>
15
+ </html>
@@ -0,0 +1,328 @@
1
+ html, body {
2
+ height: 100%; }
3
+
4
+ body {
5
+ font-family: Lucida Grande, Verdana, Arial, Helvetica, sans-serif;
6
+ font-size: 90%;
7
+ margin: 0;
8
+ padding: 0;
9
+ background: white;
10
+ color: black; }
11
+
12
+ #wrapper {
13
+ min-height: 100%;
14
+ height: auto !important;
15
+ height: 100%;
16
+ margin: 0 auto -43px; }
17
+
18
+ #footer-push {
19
+ height: 43px; }
20
+
21
+ div.header, #footer {
22
+ background: #eee; }
23
+
24
+ #footer {
25
+ border-top: 1px solid silver;
26
+ margin-top: 12px;
27
+ padding: 0 2em;
28
+ line-height: 30px;
29
+ text-align: center;
30
+ font-variant: small-caps;
31
+ font-size: 95%; }
32
+
33
+ .clearing:after {
34
+ content: ".";
35
+ visibility: hidden;
36
+ height: 0;
37
+ display: block;
38
+ clear: both; }
39
+ * html .clearing {
40
+ height: 1px; }
41
+ .clearing *:first-child + html {
42
+ overflow: hidden; }
43
+
44
+ h1, h2, h3, h4, h5, h6 {
45
+ margin: 0;
46
+ font-weight: normal; }
47
+
48
+ a {
49
+ color: #0b3e71; }
50
+ a:hover {
51
+ background: #336699;
52
+ text-decoration: none;
53
+ color: #eef; }
54
+
55
+ #diagram img {
56
+ border: 0; }
57
+
58
+ #description a, .method .description a, .header a {
59
+ color: #336699; }
60
+ #description a:hover, .method .description a:hover, .header a:hover {
61
+ color: #eee; }
62
+ #description h1 a, #description h2 a, #description h3 a, #description h4 a, #description h5 a, #description h6 a, .method .description h1 a, .method .description h2 a, .method .description h3 a, .method .description h4 a, .method .description h5 a, .method .description h6 a, .header h1 a, .header h2 a, .header h3 a, .header h4 a, .header h5 a, .header h6 a {
63
+ color: #0b3e71; }
64
+
65
+ ol {
66
+ margin: 0;
67
+ padding: 0;
68
+ list-style: none; }
69
+ ol li {
70
+ margin-left: 0;
71
+ white-space: nowrap; }
72
+ ol li.other {
73
+ display: none; }
74
+
75
+ ol.expanded li.other {
76
+ display: list-item; }
77
+
78
+ table {
79
+ margin-bottom: 1em;
80
+ font-size: 1em;
81
+ border-collapse: collapse; }
82
+ table td, table th {
83
+ padding: .4em .8em; }
84
+ table thead {
85
+ background-color: #e8e8e8; }
86
+ table thead th {
87
+ font-variant: small-caps;
88
+ color: #666666; }
89
+ table tr {
90
+ border-bottom: 1px solid silver; }
91
+
92
+ #index a.show, div.header a.show {
93
+ text-decoration: underline;
94
+ font-style: italic;
95
+ color: #666666; }
96
+ #index a.show:after, div.header a.show:after {
97
+ content: " ..."; }
98
+ #index a.show:hover, div.header a.show:hover {
99
+ color: black;
100
+ background: #ffe; }
101
+
102
+ #index {
103
+ font: 85%/1.2 Arial, Helvetica, sans-serif; }
104
+ #index a {
105
+ text-decoration: none; }
106
+ #index h1 {
107
+ padding: .2em .5em .1em;
108
+ background: #ccc;
109
+ font: small-caps 1.2em Georgia, serif;
110
+ color: #333;
111
+ border-bottom: 1px solid gray; }
112
+ #index form {
113
+ margin: 0;
114
+ padding: 0; }
115
+ #index form input {
116
+ margin: .4em 3px 0 .4em;
117
+ width: 80%; }
118
+ #index form #search.untouched {
119
+ color: #777777; }
120
+ #index form .clear_button {
121
+ -moz-border-radius: 7px;
122
+ -webkit-border-radius: 7px;
123
+ background: #AAA;
124
+ color: white;
125
+ padding: 0 5px 1px 5px;
126
+ cursor: pointer; }
127
+ #index ol {
128
+ padding: .4em .5em; }
129
+ #index ol li {
130
+ white-space: nowrap; }
131
+ #index #index-entries li a {
132
+ padding: 1px 2px; }
133
+ #index #index-entries.classes {
134
+ font-size: 1.1em; }
135
+ #index #index-entries.classes ol {
136
+ padding: 0; }
137
+ #index #index-entries.classes span.nodoc {
138
+ display: none; }
139
+ #index #index-entries.classes span.nodoc, #index #index-entries.classes a {
140
+ font-weight: bold; }
141
+ #index #index-entries.classes .parent {
142
+ font-weight: normal; }
143
+ #index #index-entries.methods li, #index #search-results.methods li {
144
+ margin-bottom: 0.2em; }
145
+ #index #index-entries.methods li a .method_name, #index #search-results.methods li a .method_name {
146
+ margin-right: 0.25em; }
147
+ #index #index-entries.methods li a .module_name, #index #search-results.methods li a .module_name {
148
+ color: #666666; }
149
+ #index #index-entries.methods li a:hover .module_name, #index #search-results.methods li a:hover .module_name {
150
+ color: #ddd; }
151
+
152
+ #attribute-list .context-item-name {
153
+ font-weight: bold; }
154
+
155
+ div.header {
156
+ font-size: 80%;
157
+ padding: .5em 2%;
158
+ font-family: Arial, Helvetica, sans-serif;
159
+ border-bottom: 1px solid silver; }
160
+ div.header .name {
161
+ font-size: 1.6em;
162
+ font-family: Georgia, serif; }
163
+ div.header .name .type {
164
+ color: #666666;
165
+ font-size: 80%;
166
+ font-variant: small-caps; }
167
+ div.header h1.name {
168
+ font-size: 2.2em; }
169
+ div.header .paths, div.header .last-update, div.header .parent {
170
+ color: #666666; }
171
+ div.header .last-update .datetime {
172
+ color: #484848; }
173
+ div.header .parent {
174
+ margin-top: .3em; }
175
+ div.header .parent strong {
176
+ font-weight: normal;
177
+ color: #484848; }
178
+
179
+ #content {
180
+ padding: 12px 2%; }
181
+ div.class #content {
182
+ position: relative;
183
+ width: 72%; }
184
+ #content pre, #content .method .synopsis {
185
+ font: 14px Monaco, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; }
186
+ #content pre {
187
+ color: black;
188
+ background: #eee;
189
+ border: 1px solid silver;
190
+ padding: .5em .8em;
191
+ overflow: auto; }
192
+ #content p code, #content p tt, #content li code, #content li tt, #content dl code, #content dl tt {
193
+ font: 14px Monaco, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
194
+ background: #ffffe3;
195
+ padding: 2px 3px;
196
+ line-height: 1.4; }
197
+ #content h1 code, #content h1 tt, #content h2 code, #content h2 tt, #content h3 code, #content h3 tt, #content h4 code, #content h4 tt, #content h5 code, #content h5 tt, #content h6 code, #content h6 tt {
198
+ font-size: 1.1em; }
199
+ #content #text {
200
+ position: relative; }
201
+ #content #description p {
202
+ margin-top: .5em; }
203
+ #content #description h1, #content #description h2, #content #description h3, #content #description h4, #content #description h5, #content #description h6 {
204
+ font-family: Georgia, serif; }
205
+ #content #description h1 {
206
+ font-size: 2.2em;
207
+ margin-bottom: .2em;
208
+ border-bottom: 3px double #d8d8d8;
209
+ padding-bottom: .1em; }
210
+ #content #description h2 {
211
+ font-size: 1.8em;
212
+ color: #0e3062;
213
+ margin: .8em 0 .3em 0; }
214
+ #content #description h3 {
215
+ font-size: 1.6em;
216
+ margin: .8em 0 .3em 0;
217
+ color: #666666; }
218
+ #content #description h4 {
219
+ font-size: 1.4em;
220
+ margin: .8em 0 .3em 0; }
221
+ #content #description h5 {
222
+ font-size: 1.2em;
223
+ margin: .8em 0 .3em 0;
224
+ color: #0e3062; }
225
+ #content #description h6 {
226
+ font-size: 1.0em;
227
+ margin: .8em 0 .3em 0;
228
+ color: #666666; }
229
+ #content #description ul, #content #description ol, #content .method .description ul, #content .method .description ol {
230
+ margin: .8em 0;
231
+ padding-left: 1.5em; }
232
+ #content #description ol, #content .method .description ol {
233
+ list-style: decimal; }
234
+ #content #description ol li, #content .method .description ol li {
235
+ white-space: normal; }
236
+
237
+ #method-list {
238
+ position: absolute;
239
+ top: 0px;
240
+ right: -33%;
241
+ width: 28%;
242
+ background: #eee;
243
+ border: 1px solid silver;
244
+ padding: .4em 1%;
245
+ overflow: hidden; }
246
+ #method-list h2 {
247
+ font-size: 1.3em; }
248
+ #method-list h3 {
249
+ font-variant: small-caps;
250
+ text-transform: capitalize;
251
+ font-family: Georgia, serif;
252
+ color: #666;
253
+ font-size: 1.1em; }
254
+ #method-list ol {
255
+ padding: 0 0 .5em .5em; }
256
+
257
+ #context {
258
+ border-top: 1px dashed silver;
259
+ margin-top: 1em;
260
+ margin-bottom: 1em; }
261
+
262
+ #context h2, #section h2 {
263
+ font: small-caps 1.2em Georgia, serif;
264
+ color: #444;
265
+ margin: 1em 0 .2em 0; }
266
+
267
+ #methods .method {
268
+ border: 1px solid silver;
269
+ margin-top: .5em;
270
+ background: #eee; }
271
+ #methods .method .synopsis {
272
+ color: black;
273
+ background: silver;
274
+ padding: .2em 1em; }
275
+ #methods .method .synopsis .name {
276
+ font-weight: bold; }
277
+ #methods .method .synopsis a {
278
+ text-decoration: none; }
279
+ #methods .method .description {
280
+ padding: 0 1em; }
281
+ #methods .method .description pre {
282
+ background: #f8f8f8; }
283
+ #methods .method .source {
284
+ margin: .5em 0; }
285
+ #methods .method .source-toggle {
286
+ font-size: 85%;
287
+ margin-left: 1em; }
288
+ #methods .public-class {
289
+ background: #ffffe4; }
290
+ #methods .public-instance .synopsis {
291
+ color: #eee;
292
+ background: #336699; }
293
+
294
+ #content .method .source pre {
295
+ background: #262626;
296
+ color: #ffdead;
297
+ margin: 1em;
298
+ padding: 0.5em;
299
+ border: 1px dashed #999;
300
+ overflow: auto; }
301
+ #content .method .source pre .ruby-constant {
302
+ color: #7fffd4;
303
+ background: transparent; }
304
+ #content .method .source pre .ruby-keyword {
305
+ color: #00ffff;
306
+ background: transparent; }
307
+ #content .method .source pre .ruby-ivar {
308
+ color: #eedd82;
309
+ background: transparent; }
310
+ #content .method .source pre .ruby-operator {
311
+ color: #00ffee;
312
+ background: transparent; }
313
+ #content .method .source pre .ruby-identifier {
314
+ color: #ffdead;
315
+ background: transparent; }
316
+ #content .method .source pre .ruby-node {
317
+ color: #ffa07a;
318
+ background: transparent; }
319
+ #content .method .source pre .ruby-comment {
320
+ color: #b22222;
321
+ font-weight: bold;
322
+ background: transparent; }
323
+ #content .method .source pre .ruby-regexp {
324
+ color: #ffa07a;
325
+ background: transparent; }
326
+ #content .method .source pre .ruby-value {
327
+ color: #7fffd4;
328
+ background: transparent; }
@@ -0,0 +1,14 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ after 'deploy:update_code', 'deploy:asset_hat:minify'
3
+
4
+ namespace :deploy do
5
+ namespace :asset_hat do
6
+ desc 'Minify all CSS/JS with Asset Hat'
7
+ task :minify, :roles => :assets, :except => {:no_release => true} do
8
+ rake = fetch(:rake, "rake")
9
+ env = fetch(:environment, fetch(:rails_env, "production"))
10
+ run "cd #{current_path} ; #{rake} RAILS_ENV=#{env} asset_hat:minify"
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/asset_hat/css.rb CHANGED
@@ -1,15 +1,25 @@
1
1
  require 'cssmin'
2
- # - http://github.com/rgrove/cssmin
3
- # - http://gemcutter.org/gems/cssmin
4
2
 
5
3
  module AssetHat
4
+ # Methods for minifying and optimizing CSS.
6
5
  module CSS
6
+ # A list of supported minification
7
+ # <a href=CSS/Engines.html>engine</a> names.
7
8
  ENGINES = [:weak, :cssmin]
8
9
 
10
+ # Returns the expected path for the minified version of a CSS asset:
11
+ #
12
+ # AssetHat::CSS.min_filepath('public/stylesheets/bundles/application.css')
13
+ # # => 'public/stylesheets/bundles/application.min.css'
9
14
  def self.min_filepath(filepath)
10
15
  AssetHat.min_filepath(filepath, 'css')
11
16
  end
12
17
 
18
+ # Accepts a string of CSS, and returns that CSS minified. Options:
19
+ #
20
+ # [engine] Default is <code>:cssmin</code>; see
21
+ # <a href=CSS/Engines.html#method-c-cssmin>Engines.cssmin</a>.
22
+ # Allowed values are in ENGINES.
13
23
  def self.minify(input_string, options={})
14
24
  options.reverse_merge!(:engine => :cssmin)
15
25
 
@@ -24,14 +34,12 @@ module AssetHat
24
34
  AssetHat::CSS::Engines.send(engine, input_string)
25
35
  end
26
36
 
27
- # def self.add_asset_mtimes(css)
28
- # css.gsub(/url[\s]*\((\/(images|htc)\/[^)]+)\)/) do |match|
29
- # src = $1
30
- # mtime = File.mtime(File.join(Rails.public_path, src))
31
- # "url(#{src}?#{mtime.to_i})"
32
- # end
33
- # end
34
-
37
+ # Given a string containing CSS, appends each referenced asset's last
38
+ # commit ID to its URL, e.g.,
39
+ # <code>background: url(/images/foo.png?ab12cd34e)</code>. This enables
40
+ # cache busting: If the user's browser has cached a copy of foo.png from a
41
+ # previous deployment, this new URL forces the browser to ignore that
42
+ # cache and request the latest version.
35
43
  def self.add_asset_commit_ids(css)
36
44
  css.gsub(/url[\s]*\((\/(images|htc)\/[^)]+)\)/) do |match|
37
45
  src = $1
@@ -47,6 +55,18 @@ module AssetHat
47
55
  end
48
56
  end
49
57
 
58
+ # Arguments:
59
+ #
60
+ # - A string containing CSS;
61
+ # - A string containing the app's asset host, e.g.,
62
+ # 'http\://assets%d.example.com'. This value is typically taken from
63
+ # <code>config.action_controller.asset_host</code> in
64
+ # the app's <code>config/environments/production.rb</code>.
65
+ #
66
+ # An asset host is added to every asset URL in the CSS, e.g.,
67
+ # <code>background: url(http\://assets2.example.com/images/foo.png)</code>;
68
+ # if <code>%d</code> in the asset host, it is replaced with an arbitrary
69
+ # number in 0-3, inclusive.
50
70
  def self.add_asset_hosts(css, asset_host)
51
71
  return if asset_host.blank?
52
72
  css.gsub(/url[\s]*\((\/(images|htc)\/[^)]+)\)/) do |match|
@@ -55,7 +75,11 @@ module AssetHat
55
75
  end
56
76
  end
57
77
 
78
+ # Swappable CSS minification engines.
58
79
  module Engines
80
+ # Barebones CSS minification engine that only strips whitespace from the
81
+ # start and end of every line, including linebreaks. For safety, doesn't
82
+ # attempt to parse the CSS itself.
59
83
  def self.weak(input_string)
60
84
  input = StringIO.new(input_string)
61
85
  output = StringIO.new
@@ -72,6 +96,12 @@ module AssetHat
72
96
  output.read
73
97
  end
74
98
 
99
+ # CSS minification engine that simply uses the CSSMin gem, a Ruby port
100
+ # of Lecomte's YUI Compressor and Schlueter's PHP cssmin.
101
+ #
102
+ # Sources:
103
+ # - http://github.com/rgrove/cssmin
104
+ # - http://rubygems.org/gems/cssmin
75
105
  def self.cssmin(input_string)
76
106
  CSSMin.minify(input_string)
77
107
  end
@@ -0,0 +1,85 @@
1
+ module AssetHat
2
+ module JS
3
+ # For working with supported 3rd-party JavaScript
4
+ # plugin/framework/library vendors.
5
+ module Vendors
6
+ # A list of supported 3rd-party JavaScript plugin/vendor names.
7
+ VENDORS = [
8
+ :jquery, :jquery_ui,
9
+ :prototype, :scriptaculous,
10
+ :mootools,
11
+ :dojo,
12
+ :swfobject,
13
+ :yui,
14
+ :ext_core
15
+ ]
16
+
17
+ # Accepts an item from VENDORS, and returns the URL at which that vendor
18
+ # asset can be found. The URL is either local (relative) or external
19
+ # depending on the environment configuration. Options:
20
+ #
21
+ # [version] The vendor version, e.g., '1.4.0' for jQuery 1.4. By
22
+ # default, each vendor version is taken from
23
+ # <code>config/assets.yml</code>; use this option to override
24
+ # the configuration.
25
+ def self.source_for(vendor, options={})
26
+ vendor_config =
27
+ AssetHat.config['js']['vendors'][vendor.to_s] rescue nil
28
+ use_local = ActionController::Base.consider_all_requests_local
29
+ version = options[:version] || vendor_config['version'] rescue nil
30
+
31
+ unless use_local
32
+ src = vendor_config['remote_url'] rescue nil
33
+ end
34
+
35
+ if src.blank?
36
+ case vendor
37
+ when :jquery
38
+ src = use_local || version.blank? ?
39
+ "#{['jquery', version].compact.join('-')}.min.js" :
40
+ "http://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"
41
+ when :jquery_ui
42
+ src = use_local || version.blank? ?
43
+ "#{['jquery-ui', version].compact.join('-')}.min.js" :
44
+ "http://ajax.googleapis.com/ajax/libs/jqueryui/#{version}/jquery-ui.min.js"
45
+ when :prototype
46
+ # Prototype currently doesn't provide an official minified version.
47
+ src = use_local || version.blank? ?
48
+ "#{['prototype', version].compact.join('-')}.js" :
49
+ "http://ajax.googleapis.com/ajax/libs/prototype/#{version}/prototype.js"
50
+ when :scriptaculous
51
+ # script.aculo.us currently doesn't provide an official minified version.
52
+ src = use_local || version.blank? ?
53
+ "#{['scriptaculous', version].compact.join('-')}.js" :
54
+ "http://ajax.googleapis.com/ajax/libs/scriptaculous/#{version}/scriptaculous.js"
55
+ when :mootools
56
+ src = use_local || version.blank? ?
57
+ "#{['mootools', version].compact.join('-')}.min.js" :
58
+ "http://ajax.googleapis.com/ajax/libs/mootools/#{version}/mootools-yui-compressed.js"
59
+ when :dojo
60
+ src = use_local || version.blank? ?
61
+ "#{['dojo', version].compact.join('-')}.min.js" :
62
+ "http://ajax.googleapis.com/ajax/libs/dojo/#{version}/dojo/dojo.xd.js"
63
+ when :swfobject
64
+ src = use_local || version.blank? ?
65
+ "#{['swfobject', version].compact.join('-')}.min.js" :
66
+ "http://ajax.googleapis.com/ajax/libs/swfobject/#{version}/swfobject.js"
67
+ when :yui
68
+ src = use_local || version.blank? ?
69
+ "#{['yui', version].compact.join('-')}.min.js" :
70
+ "http://ajax.googleapis.com/ajax/libs/yui/#{version}/build/yuiloader/yuiloader-min.js"
71
+ when :ext_core
72
+ src = use_local || version.blank? ?
73
+ "#{['ext_core', version].compact.join('-')}.min.js" :
74
+ "http://ajax.googleapis.com/ajax/libs/ext-core/#{version}/ext-core.js"
75
+ else nil # TODO: Write to log
76
+ end
77
+ end
78
+
79
+ src
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
data/lib/asset_hat/js.rb CHANGED
@@ -1,17 +1,30 @@
1
1
  require 'jsmin'
2
- # - http://github.com/rgrove/jsmin
3
- # - http://gemcutter.org/gems/jsmin
2
+ require File.join(File.dirname(__FILE__), 'js', 'vendors')
4
3
 
5
4
  module AssetHat
5
+ # Methods for minifying JavaScript.
6
6
  module JS
7
+ # A list of supported minification
8
+ # <a href=JS/Engines.html>engine</a> names.
7
9
  ENGINES = [:weak, :jsmin]
8
- VENDORS = [:jquery]
9
- # TODO: Support jQuery UI, Prototype, MooTools, etc.
10
10
 
11
+ # A list of supported
12
+ # <a href=JS/Vendors.html>3rd-party JavaScript plugin/vendor</a> names.
13
+ VENDORS = Vendors::VENDORS
14
+
15
+ # Returns the expected path for the minified version of a JS asset:
16
+ #
17
+ # AssetHat::JS.min_filepath('public/javascripts/bundles/application.js')
18
+ # # => 'public/javascripts/bundles/application.min.js'
11
19
  def self.min_filepath(filepath)
12
20
  AssetHat.min_filepath(filepath, 'js')
13
21
  end
14
22
 
23
+ # Accepts a string of JS, and returns that JS minified. Options:
24
+ #
25
+ # [engine] Default is <code>:jsmin</code>; see
26
+ # <a href=JS/Engines.html#method-c-jsmin>Engines.jsmin</a>.
27
+ # Allowed values are in ENGINES.
15
28
  def self.minify(input_string, options={})
16
29
  options.reverse_merge!(:engine => :jsmin)
17
30
 
@@ -26,7 +39,12 @@ module AssetHat
26
39
  AssetHat::JS::Engines.send(engine, input_string)
27
40
  end
28
41
 
42
+ # Swappable JavaScript minification engines.
29
43
  module Engines
44
+ # Barebones JavaScript minification engine that:
45
+ # - Skips leading/trailing whitespace for each line, excluding line
46
+ # breaks; and
47
+ # - Removes one-line comments that had no actual code on that line.
30
48
  def self.weak(input_string)
31
49
  input = StringIO.new(input_string)
32
50
  output = StringIO.new
@@ -52,36 +70,17 @@ module AssetHat
52
70
  output.read
53
71
  end
54
72
 
73
+ # JavaScript minification engine that simply uses the JSMin gem, a Ruby
74
+ # port of Crockford's JSMin.
75
+ #
76
+ # Sources:
77
+ # - http://github.com/rgrove/jsmin
78
+ # - http://rubygems.org/gems/jsmin
55
79
  def self.jsmin(input_string)
56
80
  JSMin.minify(input_string)
57
81
  end
58
82
  end # module Engines
59
83
 
60
- module Vendors
61
- JQUERY_DEFAULT_VERSION = '1.4'
62
-
63
- def self.source_for(vendor, options={})
64
- version = options[:version]
65
- if version.blank?
66
- version = begin
67
- AssetHat.config['js']['vendors'][vendor.to_s]['version']
68
- rescue
69
- AssetHat::JS::Vendors.const_get(
70
- :"#{vendor.to_s.upcase}_DEFAULT_VERSION")
71
- end
72
- end
73
-
74
- case vendor
75
- when :jquery
76
- src = ActionController::Base.consider_all_requests_local ?
77
- "jquery-#{version}.min.js" :
78
- "http://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"
79
- else nil
80
- end
81
- src
82
- end
83
- end # module Vendors
84
-
85
84
  end
86
85
 
87
86
  end