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.
- data/HISTORY +13 -14
- data/README.rdoc +171 -0
- data/Rakefile +24 -2
- data/VERSION.yml +3 -3
- data/app/helpers/asset_hat_helper.rb +67 -61
- data/asset_hat.gemspec +42 -8
- data/doc/classes/AssetHat/CSS/Engines.html +118 -0
- data/doc/classes/AssetHat/CSS.html +194 -0
- data/doc/classes/AssetHat/JS/Engines.html +122 -0
- data/doc/classes/AssetHat/JS/Vendors.html +110 -0
- data/doc/classes/AssetHat/JS.html +151 -0
- data/doc/classes/AssetHat.html +446 -0
- data/doc/classes/AssetHatHelper.html +161 -0
- data/doc/created.rid +1 -0
- data/doc/files/HISTORY.html +116 -0
- data/doc/files/LICENSE.html +76 -0
- data/doc/files/README_rdoc.html +234 -0
- data/doc/files/app/helpers/asset_hat_helper_rb.html +55 -0
- data/doc/files/lib/asset_hat/capistrano_rb.html +49 -0
- data/doc/files/lib/asset_hat/css_rb.html +57 -0
- data/doc/files/lib/asset_hat/js/vendors_rb.html +49 -0
- data/doc/files/lib/asset_hat/js_rb.html +57 -0
- data/doc/files/lib/asset_hat/tasks/css_rb.html +49 -0
- data/doc/files/lib/asset_hat/tasks/js_rb.html +49 -0
- data/doc/files/lib/asset_hat/tasks_rb.html +58 -0
- data/doc/files/lib/asset_hat/vcs_rb.html +49 -0
- data/doc/files/lib/asset_hat/version_rb.html +49 -0
- data/doc/files/lib/asset_hat_rb.html +49 -0
- data/doc/fr_class_index.html +23 -0
- data/doc/fr_file_index.html +33 -0
- data/doc/fr_method_index.html +4455 -0
- data/doc/index.html +15 -0
- data/doc/rdoc-style.css +328 -0
- data/lib/asset_hat/capistrano.rb +14 -0
- data/lib/asset_hat/css.rb +40 -10
- data/lib/asset_hat/js/vendors.rb +85 -0
- data/lib/asset_hat/js.rb +28 -29
- data/lib/asset_hat/tasks/css.rb +151 -0
- data/lib/asset_hat/tasks/js.rb +100 -0
- data/lib/asset_hat/tasks.rb +4 -272
- data/lib/asset_hat/vcs.rb +23 -20
- data/lib/asset_hat/version.rb +2 -0
- data/lib/asset_hat.rb +94 -19
- data/tasks/asset_hat.rake +1 -1
- data/test/asset_hat_helper_test.rb +63 -9
- data/test/test_helper.rb +5 -1
- metadata +94 -26
- data/README.markdown +0 -154
data/lib/asset_hat.rb
CHANGED
@@ -2,19 +2,66 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'asset_hat', x)
|
3
3
|
end
|
4
4
|
|
5
|
+
# Your assets are covered.
|
6
|
+
#
|
7
|
+
# With Rails' default asset caching, CSS and JS are concatenated (not even
|
8
|
+
# minified) the first time that bundle is requested. Not good enough. AssetHat
|
9
|
+
# can automatically:
|
10
|
+
#
|
11
|
+
# * Easily *minify* and *bundle* CSS and JS on deploy to reduce file sizes and
|
12
|
+
# HTTP requests.
|
13
|
+
# * Load popular <strong>third-party JS</strong> (like jQuery and Prototype)
|
14
|
+
# from {<strong>Google's CDN</strong>}[http://code.google.com/apis/ajaxlibs/]
|
15
|
+
# when in production, or from localhost in development.
|
16
|
+
# * Force image URLs in your CSS to use <strong>CDN subdomains</strong>, not
|
17
|
+
# just the current host.
|
18
|
+
# * Add an image's last Git[http://git-scm.com/] commit ID to its CSS URLs to
|
19
|
+
# <strong>bust browser caches</strong> (e.g.,
|
20
|
+
# <code>/images/foo.png?ab12cd34e</code>).
|
21
|
+
#
|
22
|
+
# After setup, you can use these in your layouts and views:
|
23
|
+
#
|
24
|
+
# <%= include_css :bundle => 'application' %>
|
25
|
+
# # => <link href="/stylesheets/bundles/application.min.css"
|
26
|
+
# # media="screen,projection" rel="stylesheet" type="text/css" />
|
27
|
+
#
|
28
|
+
# <%= include_js :bundles => ['plugins', 'common'] %>
|
29
|
+
# # => <script src="/javascripts/bundles/plugins.min.js"
|
30
|
+
# # type="text/javascript"></script>
|
31
|
+
# # <script src="/javascripts/bundles/common.min.js"
|
32
|
+
# # type="text/javascript"></script>
|
33
|
+
#
|
34
|
+
# And this in your deploy script:
|
35
|
+
#
|
36
|
+
# rake asset_hat:minify
|
37
|
+
#
|
38
|
+
# See README.rdoc for more.
|
5
39
|
module AssetHat
|
6
|
-
RAILS_ROOT
|
7
|
-
|
8
|
-
|
9
|
-
|
40
|
+
RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT) #:nodoc:
|
41
|
+
|
42
|
+
# Types of supported assets; currently <code>[:css, :js]</code>.
|
43
|
+
TYPES = [:css, :js]
|
44
|
+
|
45
|
+
# Base directory in which all assets are kept, e.g., 'public/'.
|
46
|
+
ASSETS_DIR = defined?(Rails.public_path) ? Rails.public_path : 'public'
|
47
|
+
|
48
|
+
# Directory in which all stylesheets are kept, e.g., 'public/stylesheets/'.
|
10
49
|
STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets"
|
50
|
+
|
51
|
+
# Directory in which all JavaScripts are kept, e.g., 'public/javascripts/'.
|
52
|
+
JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts"
|
53
|
+
|
54
|
+
# Relative path for the config file.
|
11
55
|
RELATIVE_CONFIG_FILEPATH = File.join('config', 'assets.yml')
|
56
|
+
|
57
|
+
# Absolute path for the config file.
|
12
58
|
CONFIG_FILEPATH = File.join(RAILS_ROOT, RELATIVE_CONFIG_FILEPATH)
|
13
59
|
|
14
60
|
class << self
|
15
|
-
attr_accessor :config, :asset_exists, :html_cache
|
61
|
+
attr_accessor :config, :asset_exists, :html_cache #:nodoc:
|
16
62
|
end
|
17
63
|
|
64
|
+
# Nested-hash version of <code>config/assets.yml</code>.
|
18
65
|
def self.config
|
19
66
|
if !cache? || @config.blank?
|
20
67
|
@config = YAML.load(File.open(CONFIG_FILEPATH, 'r'))
|
@@ -22,6 +69,9 @@ module AssetHat
|
|
22
69
|
@config
|
23
70
|
end
|
24
71
|
|
72
|
+
# Argument: <code>:css</code> or <code>:js</code>
|
73
|
+
#
|
74
|
+
# Returns the path to the directory where CSS or JS files are stored.
|
25
75
|
def self.assets_dir(type)
|
26
76
|
case type.to_sym
|
27
77
|
when :css ; STYLESHEETS_DIR
|
@@ -30,6 +80,15 @@ module AssetHat
|
|
30
80
|
end
|
31
81
|
end
|
32
82
|
|
83
|
+
# Returns true if the specified asset exists in the file system:
|
84
|
+
#
|
85
|
+
# AssetHat.asset_exists?('application', :css)
|
86
|
+
# # => true if /public/stylesheets/application.css exists
|
87
|
+
# AssetHat.asset_exists?('some-plugin', :js)
|
88
|
+
# # => true if /public/javascripts/some-plugin.js exists
|
89
|
+
#
|
90
|
+
# See also <code>AssetHat::STYLESHEETS_DIR</code> and
|
91
|
+
# <code>AssetHat::JAVASCRIPTS_DIR</code>.
|
33
92
|
def self.asset_exists?(filename, type)
|
34
93
|
# Process arguments
|
35
94
|
type = type.to_sym
|
@@ -48,20 +107,31 @@ module AssetHat
|
|
48
107
|
@asset_exists[type][filename]
|
49
108
|
end
|
50
109
|
|
110
|
+
# Returns <code>true</code> if bundles should be included as single minified
|
111
|
+
# files (e.g., in production), or <code>false</code> if bundles should be
|
112
|
+
# included as separate, unminified files (e.g., in development). To modify
|
113
|
+
# this value, set <code>config.action_controller.perform_caching = true</code>
|
114
|
+
# in your environment.
|
51
115
|
def self.cache? ; ActionController::Base.perform_caching ; end
|
52
116
|
|
117
|
+
# Returns the expected path for the minified version of an asset:
|
118
|
+
#
|
119
|
+
# AssetHat.min_filepath('public/stylesheets/bundles/application.css', 'css')
|
120
|
+
# # => 'public/stylesheets/bundles/application.min.css'
|
121
|
+
#
|
122
|
+
# See also <code>AssetHat::CSS.min_filepath</code> and
|
123
|
+
# <code>AssetHat::JS.min_filepath</code>.
|
53
124
|
def self.min_filepath(filepath, extension)
|
54
125
|
filepath.sub(/([^\.]*).#{extension}$/, "\\1.min.#{extension}")
|
55
126
|
end
|
56
127
|
|
128
|
+
# Returns the extension-less names of files in the given bundle:
|
129
|
+
#
|
130
|
+
# AssetHat.bundle_filenames('application', :css)
|
131
|
+
# # => ['reset', 'application', 'clearfix']
|
132
|
+
# AssetHat.bundle_filenames('non-existent-file', :css)
|
133
|
+
# # => nil
|
57
134
|
def self.bundle_filenames(bundle, type)
|
58
|
-
# Usage:
|
59
|
-
#
|
60
|
-
# AssetHat.bundle_filenames('application', :css)
|
61
|
-
# # => ['reset', 'application', 'clearfix']
|
62
|
-
# AssetHat.bundle_filenames('non-existent-file', :css)
|
63
|
-
# # => nil
|
64
|
-
|
65
135
|
# Process arguments
|
66
136
|
unless TYPES.include?(type.to_sym)
|
67
137
|
raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
|
@@ -71,14 +141,15 @@ module AssetHat
|
|
71
141
|
self.config[type.to_s]['bundles'][bundle] rescue nil
|
72
142
|
end
|
73
143
|
|
144
|
+
# Returns the full paths of files in the given bundle:
|
145
|
+
#
|
146
|
+
# AssetHat.bundle_filenames('application', :css)
|
147
|
+
# # => ['/path/to/app/public/stylesheets/reset.css',
|
148
|
+
# '/path/to/app/public/stylesheets/application.css',
|
149
|
+
# '/path/to/app/public/stylesheets/clearfix.css']
|
150
|
+
# AssetHat.bundle_filenames('non-existent-file', :css)
|
151
|
+
# # => nil
|
74
152
|
def self.bundle_filepaths(bundle, type)
|
75
|
-
# Usage:
|
76
|
-
#
|
77
|
-
# AssetHat.bundle_filenames('application', :css)
|
78
|
-
# # => ['reset', 'application', 'clearfix']
|
79
|
-
# AssetHat.bundle_filenames('non-existent-file', :css)
|
80
|
-
# # => nil
|
81
|
-
|
82
153
|
# Process arguments
|
83
154
|
unless TYPES.include?(type.to_sym)
|
84
155
|
raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
|
@@ -91,4 +162,8 @@ module AssetHat
|
|
91
162
|
filenames.map { |fn| File.join(dir, "#{fn}.#{type}") } : nil
|
92
163
|
end
|
93
164
|
|
165
|
+
def self.clear_html_cache
|
166
|
+
html_cache = {}
|
167
|
+
end
|
168
|
+
|
94
169
|
end
|
data/tasks/asset_hat.rake
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'asset_hat/tasks'
|
@@ -124,20 +124,74 @@ class AssetHatHelperTest < ActionView::TestCase
|
|
124
124
|
assert_equal js_tag("jquery.some-plugin.min.js?#{@commit_id}"), output
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
127
|
+
context 'with vendors' do
|
128
|
+
should 'know where to find each vendor file' do
|
129
|
+
AssetHat::JS::VENDORS.each do |vendor|
|
130
|
+
assert include_js(vendor, :cache => true).present?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
should 'include jQuery and jQuery UI' do
|
135
|
+
flexmock(AssetHat).should_receive(:config => @original_config)
|
136
|
+
[:jquery, :jquery_ui].each do |vendor|
|
137
|
+
output = include_js(vendor, :cache => true)
|
138
|
+
assert_equal js_tag("#{vendor.to_s.dasherize}.min.js?#{@commit_id}"), output
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
should 'include Prototype and script.aculo.us' do
|
143
|
+
[:prototype, :scriptaculous].each do |vendor|
|
144
|
+
output = include_js(vendor, :cache => true)
|
145
|
+
assert_equal js_tag("#{vendor}.js?#{@commit_id}"), output
|
146
|
+
# N.B.: Including only the regular, not minified, version
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end # context 'with vendor JS'
|
150
|
+
|
151
|
+
should 'include jQuery by version via helper option' do
|
152
|
+
version = '1.4.1'
|
136
153
|
output = include_js(:jquery, :version => version, :cache => true)
|
137
154
|
assert_equal(
|
138
155
|
js_tag("jquery-#{version}.min.js?#{@commit_id}"), output)
|
139
156
|
end
|
140
157
|
|
158
|
+
context 'with a mock config' do
|
159
|
+
setup do
|
160
|
+
version = '1.4.1'
|
161
|
+
config = AssetHat.config
|
162
|
+
config['js']['vendors'] = {
|
163
|
+
'jquery' => {
|
164
|
+
'version' => version,
|
165
|
+
'remote_url' => 'http://example.com/cdn/jquery.min.js'
|
166
|
+
}
|
167
|
+
}
|
168
|
+
flexmock(AssetHat).should_receive(:config => config)
|
169
|
+
end
|
170
|
+
|
171
|
+
should 'include jQuery by version via config file' do
|
172
|
+
version = AssetHat.config['js']['vendors']['jquery']['version']
|
173
|
+
assert_equal(
|
174
|
+
js_tag("jquery-#{version}.min.js?#{@commit_id}"),
|
175
|
+
include_js(:jquery, :cache => true)
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'with remote requests' do
|
180
|
+
setup do
|
181
|
+
flexmock(ActionController::Base).should_receive(
|
182
|
+
:consider_all_requests_local => false)
|
183
|
+
end
|
184
|
+
|
185
|
+
should 'use specified remote URL for jQuery' do
|
186
|
+
src = AssetHat.config['js']['vendors']['jquery']['remote_url']
|
187
|
+
assert_equal(
|
188
|
+
%Q{<script src="#{src}" type="text/javascript"></script>},
|
189
|
+
include_js(:jquery, :cache => true)
|
190
|
+
)
|
191
|
+
end
|
192
|
+
end # context 'with remote requests'
|
193
|
+
end # context 'with a mock config'
|
194
|
+
|
141
195
|
should 'include multiple files by name' do
|
142
196
|
flexmock(AssetHat).should_receive(:asset_exists?).and_return(true)
|
143
197
|
expected = %w[foo jquery.bar].map do |source|
|
data/test/test_helper.rb
CHANGED
@@ -22,10 +22,14 @@ unless defined?(Rails)
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
@original_config = AssetHat.config
|
26
|
+
# Use this when FlexMock refuses to teardown automatically. (Yes,
|
27
|
+
# this is ugly.)
|
28
|
+
|
25
29
|
class ActionView::TestCase
|
26
30
|
teardown :clear_html_cache
|
27
31
|
|
28
32
|
def clear_html_cache
|
29
|
-
AssetHat.
|
33
|
+
AssetHat.clear_html_cache
|
30
34
|
end
|
31
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_hat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Ron DeVera
|
@@ -10,49 +15,79 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2010-
|
18
|
+
date: 2010-06-10 00:00:00 -04:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
18
|
-
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
name: flexmock
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
25
|
requirements:
|
22
26
|
- - ">="
|
23
27
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 8
|
31
|
+
- 6
|
32
|
+
version: 0.8.6
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
26
35
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
36
|
+
name: hanna
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 1
|
45
|
+
- 12
|
46
|
+
version: 0.1.12
|
28
47
|
type: :development
|
29
|
-
|
30
|
-
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: shoulda
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
31
53
|
requirements:
|
32
54
|
- - ">="
|
33
55
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
56
|
+
segments:
|
57
|
+
- 2
|
58
|
+
- 10
|
59
|
+
- 2
|
60
|
+
version: 2.10.2
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
36
63
|
- !ruby/object:Gem::Dependency
|
37
64
|
name: cssmin
|
38
|
-
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
41
67
|
requirements:
|
42
68
|
- - ">="
|
43
69
|
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 0
|
73
|
+
- 2
|
44
74
|
version: 1.0.2
|
45
|
-
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
46
77
|
- !ruby/object:Gem::Dependency
|
47
78
|
name: jsmin
|
48
|
-
|
49
|
-
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
51
81
|
requirements:
|
52
82
|
- - ">="
|
53
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 1
|
86
|
+
- 0
|
87
|
+
- 1
|
54
88
|
version: 1.0.1
|
55
|
-
|
89
|
+
type: :runtime
|
90
|
+
version_requirements: *id005
|
56
91
|
description: Minify, bundle, and optimize CSS/JS assets.
|
57
92
|
email: ronald.devera@gmail.com
|
58
93
|
executables: []
|
@@ -61,21 +96,52 @@ extensions: []
|
|
61
96
|
|
62
97
|
extra_rdoc_files:
|
63
98
|
- LICENSE
|
64
|
-
- README.
|
99
|
+
- README.rdoc
|
65
100
|
files:
|
66
101
|
- .gitignore
|
67
102
|
- HISTORY
|
68
103
|
- LICENSE
|
69
|
-
- README.
|
104
|
+
- README.rdoc
|
70
105
|
- Rakefile
|
71
106
|
- VERSION.yml
|
72
107
|
- app/helpers/asset_hat_helper.rb
|
73
108
|
- asset_hat.gemspec
|
74
109
|
- config/assets.yml
|
110
|
+
- doc/classes/AssetHat.html
|
111
|
+
- doc/classes/AssetHat/CSS.html
|
112
|
+
- doc/classes/AssetHat/CSS/Engines.html
|
113
|
+
- doc/classes/AssetHat/JS.html
|
114
|
+
- doc/classes/AssetHat/JS/Engines.html
|
115
|
+
- doc/classes/AssetHat/JS/Vendors.html
|
116
|
+
- doc/classes/AssetHatHelper.html
|
117
|
+
- doc/created.rid
|
118
|
+
- doc/files/HISTORY.html
|
119
|
+
- doc/files/LICENSE.html
|
120
|
+
- doc/files/README_rdoc.html
|
121
|
+
- doc/files/app/helpers/asset_hat_helper_rb.html
|
122
|
+
- doc/files/lib/asset_hat/capistrano_rb.html
|
123
|
+
- doc/files/lib/asset_hat/css_rb.html
|
124
|
+
- doc/files/lib/asset_hat/js/vendors_rb.html
|
125
|
+
- doc/files/lib/asset_hat/js_rb.html
|
126
|
+
- doc/files/lib/asset_hat/tasks/css_rb.html
|
127
|
+
- doc/files/lib/asset_hat/tasks/js_rb.html
|
128
|
+
- doc/files/lib/asset_hat/tasks_rb.html
|
129
|
+
- doc/files/lib/asset_hat/vcs_rb.html
|
130
|
+
- doc/files/lib/asset_hat/version_rb.html
|
131
|
+
- doc/files/lib/asset_hat_rb.html
|
132
|
+
- doc/fr_class_index.html
|
133
|
+
- doc/fr_file_index.html
|
134
|
+
- doc/fr_method_index.html
|
135
|
+
- doc/index.html
|
136
|
+
- doc/rdoc-style.css
|
75
137
|
- lib/asset_hat.rb
|
138
|
+
- lib/asset_hat/capistrano.rb
|
76
139
|
- lib/asset_hat/css.rb
|
77
140
|
- lib/asset_hat/js.rb
|
141
|
+
- lib/asset_hat/js/vendors.rb
|
78
142
|
- lib/asset_hat/tasks.rb
|
143
|
+
- lib/asset_hat/tasks/css.rb
|
144
|
+
- lib/asset_hat/tasks/js.rb
|
79
145
|
- lib/asset_hat/vcs.rb
|
80
146
|
- lib/asset_hat/version.rb
|
81
147
|
- public/javascripts/bundles/js-bundle-1.min.js
|
@@ -120,18 +186,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
186
|
requirements:
|
121
187
|
- - ">="
|
122
188
|
- !ruby/object:Gem::Version
|
189
|
+
segments:
|
190
|
+
- 0
|
123
191
|
version: "0"
|
124
|
-
version:
|
125
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
193
|
requirements:
|
127
194
|
- - ">="
|
128
195
|
- !ruby/object:Gem::Version
|
196
|
+
segments:
|
197
|
+
- 0
|
129
198
|
version: "0"
|
130
|
-
version:
|
131
199
|
requirements: []
|
132
200
|
|
133
201
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.3.
|
202
|
+
rubygems_version: 1.3.6
|
135
203
|
signing_key:
|
136
204
|
specification_version: 3
|
137
205
|
summary: Your assets are covered.
|
data/README.markdown
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
AssetHat
|
2
|
-
========
|
3
|
-
Your assets are covered.
|
4
|
-
|
5
|
-
* Minify CSS and JS with one command. (Can be done on deploy instead of
|
6
|
-
at runtime.)
|
7
|
-
* Bundle CSS and JS to reduce HTTP requests.
|
8
|
-
* Reuse CSS and JS bundles across layouts without repetition.
|
9
|
-
* Bust image caches by changing CSS URLs whenever an image is modified.
|
10
|
-
* Force image URLs in your CSS to use CDN subdomains, not just the current
|
11
|
-
host.
|
12
|
-
|
13
|
-
After setup, you can use these in your layouts and views:
|
14
|
-
|
15
|
-
include_css :bundle => 'application'
|
16
|
-
# => <link href="/stylesheets/bundles/application.min.css"
|
17
|
-
# media="screen,projection" rel="stylesheet" type="text/css" />
|
18
|
-
|
19
|
-
include_js :bundles => ['plugins', 'common']
|
20
|
-
# => <script src="/javascripts/bundles/plugins.min.js"
|
21
|
-
# type="text/javascript"></script>
|
22
|
-
# <script src="/javascripts/bundles/common.min.js"
|
23
|
-
# type="text/javascript"></script>
|
24
|
-
|
25
|
-
And this in your deploy script:
|
26
|
-
|
27
|
-
rake asset_hat:minify
|
28
|
-
|
29
|
-
Works with Rails 2.3.4 and above.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Installation
|
34
|
-
------------
|
35
|
-
|
36
|
-
1. Install the gem:
|
37
|
-
|
38
|
-
gem install asset_hat
|
39
|
-
|
40
|
-
2. Configure the gem:
|
41
|
-
|
42
|
-
* Using [Bundler](http://github.com/wycats/bundler):
|
43
|
-
|
44
|
-
1. Add to your app's Gemfile: `gem 'asset_hat', '0.x.x'`
|
45
|
-
|
46
|
-
2. Command-line: `gem bundle`
|
47
|
-
|
48
|
-
* Using Rails' `config.gem`, add to your app's `config/environment.rb`:
|
49
|
-
|
50
|
-
`config.gem 'asset_hat', :version => '0.x.x'`
|
51
|
-
|
52
|
-
3. In your app, create `lib/tasks/asset_hat.rake` with the following contents:
|
53
|
-
|
54
|
-
begin
|
55
|
-
require 'asset_hat/tasks'
|
56
|
-
rescue LoadError
|
57
|
-
puts "Could not load AssetHat tasks: 'asset_hat' not found."
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Configuration
|
63
|
-
-------------
|
64
|
-
|
65
|
-
1. Create the default config file:
|
66
|
-
|
67
|
-
rake asset_hat:config
|
68
|
-
|
69
|
-
2. In your app, open the new config file at `config/assets.yml`, and set up
|
70
|
-
your CSS/JS bundles according to that file's example.
|
71
|
-
|
72
|
-
3. Minify your bundles:
|
73
|
-
|
74
|
-
rake asset_hat:minify
|
75
|
-
|
76
|
-
This minifies all of the CSS/JS files listed in `config/assets.yml`,
|
77
|
-
concatenates the minified code into bundle files, and adds CDN asset hosts
|
78
|
-
and cache-busting commit IDs to image URLs in your CSS.
|
79
|
-
|
80
|
-
Bundles are created as new files in `public/stylesheets/bundles/` and
|
81
|
-
`public/javascripts/bundles/`. Your original CSS/JS files remain intact.
|
82
|
-
|
83
|
-
4. Set your deployment script to run `rake asset_hat:minify` after deploying
|
84
|
-
your latest CSS/JS. This overwrites previously minified bundles, and
|
85
|
-
leaves your original CSS/JS files intact.
|
86
|
-
|
87
|
-
### Advanced configuration ###
|
88
|
-
|
89
|
-
Additional settings are supported in `config/assets.yml`:
|
90
|
-
|
91
|
-
* `engine`: Indicates how CSS and JS are minified; omit this setting to use
|
92
|
-
the defaults. If the default engines cause problems by minifying too
|
93
|
-
strongly, try switching each to `weak`. The `weak` engines are much safer,
|
94
|
-
but don't save as many bytes.
|
95
|
-
|
96
|
-
* `vendors`: Currently only allows for setting the jQuery version number:
|
97
|
-
|
98
|
-
js:
|
99
|
-
vendors:
|
100
|
-
jquery:
|
101
|
-
version: 1.4
|
102
|
-
|
103
|
-
In the future, this will be used for configuring the retrieval of other
|
104
|
-
third-party code.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
Usage
|
109
|
-
-----
|
110
|
-
|
111
|
-
In your layouts and views, instead of these:
|
112
|
-
|
113
|
-
<%= stylesheet_link_tag 'reset', 'application', 'clearfix',
|
114
|
-
:media => 'screen,projection',
|
115
|
-
:cache => 'bundles/application' %>
|
116
|
-
<%= javascript_include_tag 'plugin-1', 'plugin-2', 'plugin-3',
|
117
|
-
:cache => 'bundles/application' %>
|
118
|
-
|
119
|
-
**Use these:**
|
120
|
-
|
121
|
-
<%= include_css :bundle => 'application' %>
|
122
|
-
<%= include_js :bundle => 'application' %>
|
123
|
-
|
124
|
-
These turn into:
|
125
|
-
|
126
|
-
<link href="/stylesheets/bundles/application.min.css"
|
127
|
-
media="screen,projection" rel="stylesheet" type="text/css" />
|
128
|
-
<script src="/javascripts/bundles/application.min.js"
|
129
|
-
type="text/javascript"></script>
|
130
|
-
|
131
|
-
If your environment has `config.action_controller.perform_caching` set to
|
132
|
-
`true` (e.g., in production), the layout/view will include minified bundle
|
133
|
-
files. Otherwise, the separate, unminified files will be included, based on
|
134
|
-
the bundle contents you define in `config/assets.yml`.
|
135
|
-
|
136
|
-
### Advanced usage ###
|
137
|
-
|
138
|
-
You can also include single files as expected:
|
139
|
-
|
140
|
-
<%= include_css 'reset', 'application' %>
|
141
|
-
<%= include_js 'plugin.min', 'application' %>
|
142
|
-
|
143
|
-
Or include multiple bundles at once:
|
144
|
-
|
145
|
-
<%= include_js :bundles => %w[plugins common] %>
|
146
|
-
|
147
|
-
When including multiple bundles at once, this yields one `<link>` or
|
148
|
-
`<script>` element per bundle.
|
149
|
-
|
150
|
-
You may want to use multiple bundles to separate plugins (rarely changed) from
|
151
|
-
application code (frequently changed). If all code is in one huge bundle, then
|
152
|
-
whenever there's a change, browsers have to re-download the whole bundle. By
|
153
|
-
using multiple bundles based on change frequency, browsers cache the rarely
|
154
|
-
changed code, and only re-download the frequently changed code.
|