asset_hat 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/HISTORY +6 -0
- data/LICENSE +1 -1
- data/README.rdoc +120 -23
- data/Rakefile +7 -6
- data/VERSION.yml +1 -1
- data/asset_hat.gemspec +4 -4
- data/config/assets.yml +3 -3
- data/doc/classes/AssetHat/JS/Vendors.html +1 -1
- data/doc/classes/AssetHatHelper.html +4 -4
- data/doc/created.rid +1 -1
- data/doc/files/HISTORY.html +13 -1
- data/doc/files/LICENSE.html +2 -2
- data/doc/files/README_rdoc.html +154 -54
- data/lib/asset_hat/capistrano.rb +2 -1
- data/lib/asset_hat/js/vendors.rb +1 -1
- data/lib/asset_hat/tasks.rb +1 -1
- data/lib/asset_hat/tasks/css.rb +5 -5
- data/lib/asset_hat/tasks/js.rb +3 -3
- data/lib/asset_hat_helper.rb +44 -23
- data/test/asset_hat_helper_test.rb +3 -3
- metadata +6 -6
- data/Gemfile.lock +0 -36
data/lib/asset_hat/capistrano.rb
CHANGED
@@ -7,9 +7,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
7
7
|
task :minify, :roles => :assets, :except => {:no_release => true} do
|
8
8
|
rake = fetch(:rake, "rake")
|
9
9
|
env = fetch(:environment, fetch(:rails_env, "production"))
|
10
|
-
run "cd #{
|
10
|
+
run "cd #{release_path} ; " +
|
11
11
|
"#{rake} RAILS_ENV=#{env} FORMAT=short asset_hat:minify"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
15
16
|
end
|
data/lib/asset_hat/js/vendors.rb
CHANGED
@@ -60,7 +60,7 @@ module AssetHat
|
|
60
60
|
#
|
61
61
|
# [ssl] Boolean for whether to include vendor JS via HTTPS. Defaults
|
62
62
|
# to false.
|
63
|
-
# [version] The vendor version, e.g., '1.
|
63
|
+
# [version] The vendor version, e.g., '1.6.0' for jQuery 1.6. By
|
64
64
|
# default, each vendor version is taken from
|
65
65
|
# <code>config/assets.yml</code>; use this option to override
|
66
66
|
# the configuration.
|
data/lib/asset_hat/tasks.rb
CHANGED
data/lib/asset_hat/tasks/css.rb
CHANGED
@@ -2,7 +2,7 @@ namespace :asset_hat do
|
|
2
2
|
namespace :css do
|
3
3
|
|
4
4
|
desc 'Adds commit IDs to asset URLs in CSS for cache busting'
|
5
|
-
task :add_asset_commit_ids, :filename
|
5
|
+
task :add_asset_commit_ids, [:filename] => :environment do |t, args|
|
6
6
|
if args.filename.blank?
|
7
7
|
raise 'Usage: rake asset_hat:css:' +
|
8
8
|
'add_asset_commit_ids[filename.css]' and return
|
@@ -18,7 +18,7 @@ namespace :asset_hat do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'Adds hosts to asset URLs in CSS'
|
21
|
-
task :add_asset_hosts, :filename
|
21
|
+
task :add_asset_hosts, [:filename] => :environment do |t, args|
|
22
22
|
if args.filename.blank?
|
23
23
|
raise 'Usage: rake asset_hat:css:' +
|
24
24
|
'add_asset_hosts[filename.css]' and return
|
@@ -40,7 +40,7 @@ namespace :asset_hat do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
desc 'Minifies one CSS file'
|
43
|
-
task :minify_file, :filepath
|
43
|
+
task :minify_file, [:filepath] => :environment do |t, args|
|
44
44
|
type = 'css'
|
45
45
|
|
46
46
|
if args.filepath.blank?
|
@@ -65,7 +65,7 @@ namespace :asset_hat do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
desc 'Minifies one CSS bundle'
|
68
|
-
task :minify_bundle, :bundle
|
68
|
+
task :minify_bundle, [:bundle] => :environment do |t, args|
|
69
69
|
type = 'css'
|
70
70
|
|
71
71
|
if args.bundle.blank?
|
@@ -155,7 +155,7 @@ namespace :asset_hat do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
desc 'Concatenates and minifies all CSS bundles'
|
158
|
-
task :minify, :opts
|
158
|
+
task :minify, [:opts] => :environment do |t, args|
|
159
159
|
args.with_defaults(:opts => {})
|
160
160
|
opts = args.opts.reverse_merge(:show_intro => true, :show_outro => true)
|
161
161
|
type = 'css'
|
data/lib/asset_hat/tasks/js.rb
CHANGED
@@ -2,7 +2,7 @@ namespace :asset_hat do
|
|
2
2
|
namespace :js do
|
3
3
|
|
4
4
|
desc 'Minifies one JS file'
|
5
|
-
task :minify_file, :filepath
|
5
|
+
task :minify_file, [:filepath] => :environment do |t, args|
|
6
6
|
type = 'js'
|
7
7
|
|
8
8
|
if args.filepath.blank?
|
@@ -31,7 +31,7 @@ namespace :asset_hat do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
desc 'Minifies one JS bundle'
|
34
|
-
task :minify_bundle, :bundle
|
34
|
+
task :minify_bundle, [:bundle] => :environment do |t, args|
|
35
35
|
type = 'js'
|
36
36
|
|
37
37
|
if args.bundle.blank?
|
@@ -104,7 +104,7 @@ namespace :asset_hat do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
desc 'Concatenates and minifies all JS bundles'
|
107
|
-
task :minify, :opts
|
107
|
+
task :minify, [:opts] => :environment do |t, args|
|
108
108
|
args.with_defaults(:opts => {})
|
109
109
|
opts = args.opts.reverse_merge(:show_intro => true, :show_outro => true)
|
110
110
|
type = 'js'
|
data/lib/asset_hat_helper.rb
CHANGED
@@ -103,7 +103,7 @@ module AssetHatHelper
|
|
103
103
|
else nil
|
104
104
|
end
|
105
105
|
end.join("\n")
|
106
|
-
|
106
|
+
make_html_safe html
|
107
107
|
end
|
108
108
|
|
109
109
|
end # def include_assets
|
@@ -159,15 +159,15 @@ module AssetHatHelper
|
|
159
159
|
def include_css(*args)
|
160
160
|
return if args.blank?
|
161
161
|
|
162
|
-
|
163
|
-
AssetHat.html_cache[:css] ||= {}
|
162
|
+
initialize_html_cache :css
|
164
163
|
|
165
|
-
options = args
|
166
|
-
|
167
|
-
:
|
168
|
-
|
164
|
+
options = setup_options(args,
|
165
|
+
:media => 'screen,projection',
|
166
|
+
:ssl => controller.request.ssl?
|
167
|
+
)
|
168
|
+
cache_key = setup_cache_key(args, options)
|
169
169
|
|
170
|
-
if !
|
170
|
+
if !asset_cached?(:css, cache_key)
|
171
171
|
# Generate HTML and write to cache
|
172
172
|
options[:ssl] &&= AssetHat.ssl_asset_host_differs?
|
173
173
|
html = AssetHat.html_cache[:css][cache_key] =
|
@@ -175,7 +175,7 @@ module AssetHatHelper
|
|
175
175
|
end
|
176
176
|
|
177
177
|
html ||= AssetHat.html_cache[:css][cache_key]
|
178
|
-
|
178
|
+
make_html_safe html
|
179
179
|
end
|
180
180
|
|
181
181
|
# <code>include_js</code> is a smart wrapper for Rails'
|
@@ -199,7 +199,7 @@ module AssetHatHelper
|
|
199
199
|
# include_js :jquery
|
200
200
|
# => <script src="http://ajax.googleapis.com/.../jquery.min.js" ...></script>
|
201
201
|
# # Set jQuery versions either in `config/assets.yml`, or by using
|
202
|
-
# # `include_js :jquery, :version => '1.6.
|
202
|
+
# # `include_js :jquery, :version => '1.6.1'`.
|
203
203
|
#
|
204
204
|
# Include a bundle of JS files (i.e., a concatenated set of files;
|
205
205
|
# configure in <code>config/assets.yml</code>):
|
@@ -295,24 +295,19 @@ module AssetHatHelper
|
|
295
295
|
def include_js(*args)
|
296
296
|
return if args.blank?
|
297
297
|
|
298
|
-
|
299
|
-
AssetHat.html_cache[:js] ||= {}
|
298
|
+
initialize_html_cache :js
|
300
299
|
|
301
|
-
options = args.
|
302
|
-
|
303
|
-
cache_key = (args + [options]).inspect
|
300
|
+
options = setup_options(args, :ssl => controller.request.ssl?)
|
301
|
+
cache_key = setup_cache_key(args, options)
|
304
302
|
|
305
|
-
if !
|
303
|
+
if !asset_cached?(:js, cache_key)
|
306
304
|
# Generate HTML and write to cache
|
307
305
|
|
308
306
|
htmls = []
|
309
307
|
include_assets_options = options.except(:ssl, :version)
|
310
|
-
loader = nil
|
311
308
|
|
312
|
-
|
313
|
-
|
314
|
-
include_assets_options.merge!(:only_url => true)
|
315
|
-
end
|
309
|
+
loader = options.delete(:loader)
|
310
|
+
include_assets_options.merge!(:only_url => true) if loader
|
316
311
|
|
317
312
|
# Get vendor HTML/URLs
|
318
313
|
included_vendors = (args & AssetHat::JS::VENDORS)
|
@@ -359,7 +354,7 @@ module AssetHatHelper
|
|
359
354
|
end
|
360
355
|
|
361
356
|
html ||= AssetHat.html_cache[:js][cache_key]
|
362
|
-
|
357
|
+
make_html_safe html
|
363
358
|
end
|
364
359
|
|
365
360
|
# Returns the public URL path to the given source file.
|
@@ -370,8 +365,34 @@ module AssetHatHelper
|
|
370
365
|
when :css ; stylesheet_path(source)
|
371
366
|
when :js ; javascript_path(source)
|
372
367
|
else
|
373
|
-
raise %{
|
368
|
+
raise %{
|
369
|
+
Unknown type "#{type}"; should be one of:
|
370
|
+
#{AssetHat::TYPES.join(', ')}.
|
371
|
+
}.squish!
|
374
372
|
end
|
375
373
|
end
|
376
374
|
|
375
|
+
private
|
376
|
+
|
377
|
+
def initialize_html_cache(type)
|
378
|
+
AssetHat.html_cache ||= {}
|
379
|
+
AssetHat.html_cache[type] ||= {}
|
380
|
+
end
|
381
|
+
|
382
|
+
def setup_options(args, defaults)
|
383
|
+
options = args.extract_options!
|
384
|
+
options.symbolize_keys!.reverse_merge!(defaults)
|
385
|
+
end
|
386
|
+
|
387
|
+
def setup_cache_key(args, options)
|
388
|
+
(args + [options]).inspect
|
389
|
+
end
|
390
|
+
|
391
|
+
def make_html_safe(html)
|
392
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
393
|
+
end
|
394
|
+
|
395
|
+
def asset_cached?(type, cache_key)
|
396
|
+
AssetHat.cache? && !AssetHat.html_cache[type.to_sym][cache_key].blank?
|
397
|
+
end
|
377
398
|
end
|
@@ -450,7 +450,7 @@ class AssetHatHelperTest < ActionView::TestCase
|
|
450
450
|
|
451
451
|
context 'with a mock config containing a version number' do
|
452
452
|
setup do
|
453
|
-
@vendor_version = '1.6.
|
453
|
+
@vendor_version = '1.6.1'
|
454
454
|
config = AssetHat.config
|
455
455
|
config['js']['vendors'] = {
|
456
456
|
'jquery' => {'version' => @vendor_version}
|
@@ -549,7 +549,7 @@ class AssetHatHelperTest < ActionView::TestCase
|
|
549
549
|
|
550
550
|
context 'with a mock config containing custom CDN URLs' do
|
551
551
|
setup do
|
552
|
-
@vendor_version = '1.6.
|
552
|
+
@vendor_version = '1.6.1'
|
553
553
|
config = AssetHat.config
|
554
554
|
config['js']['vendors'] = {
|
555
555
|
'jquery' => {
|
@@ -872,7 +872,7 @@ class AssetHatHelperTest < ActionView::TestCase
|
|
872
872
|
setup do
|
873
873
|
@config = AssetHat.config
|
874
874
|
@config['js']['vendors'] = {
|
875
|
-
'jquery' => {'version' => '1.6.
|
875
|
+
'jquery' => {'version' => '1.6.1'},
|
876
876
|
'lab_js' => {'version' => '1.2.0'}
|
877
877
|
}
|
878
878
|
flexmock(AssetHat).should_receive(:config => @config).by_default
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_hat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ron DeVera
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-08-08 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
version: 1.0.1
|
116
116
|
type: :runtime
|
117
117
|
version_requirements: *id006
|
118
|
-
description: Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on deploy), not at runtime. Loads popular third-party JS (like jQuery, YUI, and
|
118
|
+
description: Load CSS and JS faster. Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on deploy), not at runtime. Loads popular third-party JS (like jQuery, YUI, and Dojo) from localhost in development, and auto-switches to Google's CDN in production. Lets you switch on LABjs mode to load more scripts in parallel. Can rewrite stylesheets to use CDN hosts (not just your web server) and cache-busting hashes for updated images.
|
119
119
|
email: hello@rondevera.com
|
120
120
|
executables: []
|
121
121
|
|
@@ -125,8 +125,8 @@ extra_rdoc_files:
|
|
125
125
|
- LICENSE
|
126
126
|
- README.rdoc
|
127
127
|
files:
|
128
|
+
- .gemtest
|
128
129
|
- Gemfile
|
129
|
-
- Gemfile.lock
|
130
130
|
- HISTORY
|
131
131
|
- LICENSE
|
132
132
|
- README.rdoc
|
data/Gemfile.lock
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
asset_hat (0.4.0)
|
5
|
-
cssmin (~> 1.0.2)
|
6
|
-
jsmin (~> 1.0.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
cssmin (1.0.2)
|
12
|
-
flexmock (0.8.11)
|
13
|
-
git (1.2.5)
|
14
|
-
haml (2.2.24)
|
15
|
-
hanna (0.1.12)
|
16
|
-
haml (~> 2.2.8)
|
17
|
-
rake (~> 0.8.2)
|
18
|
-
rdoc (~> 2.3.0)
|
19
|
-
jeweler (1.5.2)
|
20
|
-
bundler (~> 1.0.0)
|
21
|
-
git (>= 1.2.5)
|
22
|
-
rake
|
23
|
-
jsmin (1.0.1)
|
24
|
-
rake (0.8.7)
|
25
|
-
rdoc (2.3.0)
|
26
|
-
shoulda (2.10.3)
|
27
|
-
|
28
|
-
PLATFORMS
|
29
|
-
ruby
|
30
|
-
|
31
|
-
DEPENDENCIES
|
32
|
-
asset_hat!
|
33
|
-
flexmock (~> 0.8.6)
|
34
|
-
hanna (~> 0.1.12)
|
35
|
-
jeweler (~> 1.5.1)
|
36
|
-
shoulda (~> 2.10.2)
|