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.
Files changed (46) hide show
  1. data/HISTORY +38 -19
  2. data/README.rdoc +99 -41
  3. data/Rakefile +17 -10
  4. data/VERSION.yml +3 -3
  5. data/app/helpers/asset_hat_helper.rb +40 -20
  6. data/asset_hat.gemspec +105 -101
  7. data/doc/classes/AssetHat.html +173 -59
  8. data/doc/classes/AssetHat/CSS.html +35 -26
  9. data/doc/classes/AssetHat/CSS/Engines.html +13 -12
  10. data/doc/classes/AssetHat/JS.html +11 -11
  11. data/doc/classes/AssetHat/JS/Engines.html +10 -10
  12. data/doc/classes/AssetHat/JS/Vendors.html +9 -5
  13. data/doc/classes/AssetHatHelper.html +18 -14
  14. data/doc/created.rid +1 -1
  15. data/doc/files/HISTORY.html +66 -24
  16. data/doc/files/LICENSE.html +1 -1
  17. data/doc/files/README_rdoc.html +112 -37
  18. data/doc/files/app/helpers/asset_hat_helper_rb.html +1 -1
  19. data/doc/files/lib/asset_hat/capistrano_rb.html +1 -1
  20. data/doc/files/lib/asset_hat/css_rb.html +1 -1
  21. data/doc/files/lib/asset_hat/js/vendors_rb.html +1 -1
  22. data/doc/files/lib/asset_hat/js_rb.html +1 -1
  23. data/doc/files/lib/asset_hat/tasks/css_rb.html +1 -1
  24. data/doc/files/lib/asset_hat/tasks/js_rb.html +1 -1
  25. data/doc/files/lib/asset_hat/tasks_rb.html +1 -1
  26. data/doc/files/lib/asset_hat/vcs_rb.html +1 -1
  27. data/doc/files/lib/asset_hat/version_rb.html +1 -1
  28. data/doc/files/lib/asset_hat_rb.html +1 -1
  29. data/doc/fr_method_index.html +54 -46
  30. data/lib/asset_hat.rb +100 -16
  31. data/lib/asset_hat/capistrano.rb +4 -3
  32. data/lib/asset_hat/css.rb +69 -20
  33. data/lib/asset_hat/js.rb +2 -2
  34. data/lib/asset_hat/js/vendors.rb +14 -10
  35. data/lib/asset_hat/tasks.rb +22 -3
  36. data/lib/asset_hat/tasks/css.rb +118 -74
  37. data/lib/asset_hat/tasks/js.rb +79 -35
  38. data/lib/asset_hat/vcs.rb +19 -0
  39. data/public/stylesheets/bundles/ssl/css-bundle-1.min.css +3 -0
  40. data/public/stylesheets/bundles/ssl/css-bundle-2.min.css +3 -0
  41. data/public/stylesheets/bundles/ssl/css-bundle-3.min.css +3 -0
  42. data/rails/init.rb +1 -16
  43. data/test/asset_hat_helper_test.rb +172 -28
  44. data/test/asset_hat_test.rb +167 -25
  45. metadata +54 -21
  46. data/.gitignore +0 -2
data/HISTORY CHANGED
@@ -1,40 +1,59 @@
1
1
  = HISTORY
2
2
 
3
+ * FEATURE: Added ERb support in `config/assets.yml`.
4
+ * FEATURE: Added support for auto-creating SSL versions of every stylesheet.
5
+ * FEATURE: Added support for loading remote JS via SSL. Includes loading
6
+ popular JS from `https://ajax.googleapis.com` or your own CDN.
7
+ * FEATURE: Added support for `FORMAT=long|short|dot` flags for
8
+ `rake asset_hat:minify`. Useful for shortening output from deployment
9
+ scripts.
10
+ * FEATURE: Added support for absolute paths in `config/assets.yml`. Allows
11
+ pointing to assets directly inside `public/`.
12
+ * FEATURE: Added `asset_hat:minify:css` and `asset_hat:minify:js` Rake task
13
+ aliases.
14
+ * IMPROVEMENT: Updated default CSS minification engine to remove rules that
15
+ have empty declaration blocks.
16
+ * IMPROVEMENT: Stopped pre-caching asset commit IDs when launching console.
17
+ * IMPROVEMENT: Added support for single/double quotation marks in `url()` CSS
18
+ when adding asset hosts and cache busters
19
+ * FIX: Fixed adding asset commit IDs to URLs containing "?" in stylesheets.
20
+
3
21
  == Version 0.2.1 (2010-07-21)
4
- * Added WebFont Loader to supported JS vendors.
5
- * Stopped adding asset hosts to `url(/htc/...)` URLs because IE 6, by default,
6
- refuses to run .htc files from other domains, including CDN subdomains.
22
+ * FEATURE: Added WebFont Loader to supported JS vendors.
23
+ * FIX: Stopped adding asset hosts to `url(/htc/...)` URLs because IE 6, by
24
+ default, refuses to run .htc files from other domains, including CDN
25
+ subdomains.
7
26
 
8
27
  == Version 0.2.0 (2010-06-10)
9
- * Added support for loading many more JS vendors from Google's CDN, including
10
- Prototype, MooTools, and SWFObject.
11
- * Cleaned up existing docs, and added complete RDoc documentation.
12
- * Added example integration script for Capistrano deployments.
28
+ * FEATURE: Added support for loading many more JS vendors from Google's CDN,
29
+ including Prototype, MooTools, and SWFObject.
30
+ * FEATURE: Cleaned up existing docs, and added complete RDoc documentation.
31
+ * FEATURE: Added example integration script for Capistrano deployments.
13
32
 
14
33
  == Version 0.1.5 (2010-03-11)
15
- * Fixed fetching asset commit IDs in some environments. The bug was possibly
16
- caused by older versions of Git, which fail to read logs properly when given
17
- absolute paths, rather than relative paths.
18
- * Stopped app tests from running twice in some environments.
34
+ * FIX: Fixed fetching asset commit IDs in some environments. The bug was
35
+ possibly caused by older versions of Git, which fail to read logs properly
36
+ when given absolute paths, rather than relative paths.
37
+ * FIX: Stopped app tests from running twice in some environments.
19
38
 
20
39
  == Version 0.1.4 (2010-03-03)
21
- * Fixed config filepaths in `asset_hat:config` task.
40
+ * FIX: Fixed config filepaths in `asset_hat:config` task.
22
41
 
23
42
  == Version 0.1.3 (2010-03-03)
24
- * Allowed adding commit IDs and asset hosts to `url(/htc/...)` URLs (e.g.,
25
- `/htc/iepngfix.htc`) in CSS, not just images.
26
- * Changed `AssetHat.config` to memoize only if `cache?` is true. In
43
+ * FIX: Allowed adding commit IDs and asset hosts to `url(/htc/...)` URLs
44
+ (e.g., `/htc/iepngfix.htc`) in CSS, not just images.
45
+ * FIX: Changed `AssetHat.config` to memoize only if `cache?` is true. In
27
46
  development environments, this means the config file will be reread with
28
47
  every request.
29
48
 
30
49
  == Version 0.1.2 (2010-01-27)
31
- * Memoized HTML output from `include_css` and `include_js` when
50
+ * IMPROVEMENT: Memoized HTML output from `include_css` and `include_js` when
32
51
  `AssetHat.cache?` is true.
33
52
 
34
53
  == Version 0.1.1 (2010-01-20)
35
- * Rewrote `AssetHat::VERSION` to be based on `VERSION.yml`.
36
- * Prefixed `AssetHat::CONFIG_FILEPATH` with `RAILS_ROOT`, which fixes ability
37
- to run an app's individual test files.
54
+ * FIX: Rewrote `AssetHat::VERSION` to be based on `VERSION.yml`.
55
+ * FIX: Prefixed `AssetHat::CONFIG_FILEPATH` with `RAILS_ROOT`, which fixes
56
+ ability to run an app's individual test files.
38
57
 
39
58
  == Version 0.1.0 (2010-01-19)
40
59
  * Initial release.
data/README.rdoc CHANGED
@@ -8,56 +8,59 @@ AssetHat can automatically:
8
8
 
9
9
  * Easily *minify* and *bundle* CSS and JS on deploy to reduce file sizes and
10
10
  HTTP requests.
11
- * Load popular <strong>third-party JS</strong> (like jQuery and Prototype)
12
- from {<strong>Google's CDN</strong>}[http://code.google.com/apis/ajaxlibs/]
11
+ * Load popular <b>third-party JS</b> (like jQuery and Prototype)
12
+ from {<b>Google's CDN</b>}[http://code.google.com/apis/ajaxlibs/]
13
13
  when in production, or from localhost in development.
14
- * Force image URLs in your CSS to use <strong>CDN subdomains</strong>, not
15
- just the current host.
14
+ * Force image URLs in your CSS to use <b>CDN subdomains</b>
15
+ (including SSL support), not just the current host.
16
16
  * Add an image's last Git[http://git-scm.com/] commit ID to its CSS URLs to
17
- <strong>bust browser caches</strong> (e.g.,
18
- <code>/images/foo.png?ab12cd34e</code>).
17
+ <b>bust browser caches</b> (e.g.,
18
+ <code>/images/foo.png?ab12cd3</code>).
19
19
 
20
- After setup, you can use these in your layouts and views:
20
+ After setup, you can use this in your layouts and views:
21
21
 
22
22
  <%= include_css :bundle => 'application' %>
23
- # => <link href="/stylesheets/bundles/application.min.css"
24
- # media="screen,projection" rel="stylesheet" type="text/css" />
23
+ <%= include_js :jquery, :bundles => ['plugins', 'common'] %>
25
24
 
26
- <%= include_js :bundles => ['plugins', 'common'] %>
27
- # => <script src="/javascripts/bundles/plugins.min.js"
28
- # type="text/javascript"></script>
29
- # <script src="/javascripts/bundles/common.min.js"
30
- # type="text/javascript"></script>
25
+ Which turns into:
26
+
27
+ <link href="/stylesheets/bundles/application.min.css"
28
+ media="screen,projection" rel="stylesheet" type="text/css" />
29
+ <script src="/javascripts/jquery-1.x.x.min.js"
30
+ type="text/javascript"></script>
31
+ <!-- In production, jQuery loads from Google's CDN instead. -->
32
+ <script src="/javascripts/bundles/plugins.min.js"
33
+ type="text/javascript"></script>
34
+ <script src="/javascripts/bundles/common.min.js"
35
+ type="text/javascript"></script>
31
36
 
32
37
  And this in your deploy script:
33
38
 
34
39
  rake asset_hat:minify
35
40
 
36
- Tested with Rails 2.3.x.
41
+ Tested with Rails 2.3.x. For the gritty details, check the
42
+ {complete docs}[http://mintdigital.github.com/asset_hat/doc/] and
43
+ {change history}[http://mintdigital.github.com/asset_hat/doc/files/HISTORY.html].
37
44
 
38
45
 
39
46
 
40
47
  == Installation
41
48
 
42
- 1. Install the gem:
49
+ 1. Configure the gem:
43
50
 
44
- gem install asset_hat
45
-
46
- 2. Configure the gem:
47
-
48
- * If you're using {Bundler 0.9+}[http://github.com/carlhuda/bundler]:
51
+ * If you're using Rails 3 and/or
52
+ {Bundler 0.9+}[http://github.com/carlhuda/bundler]:
49
53
 
50
54
  1. Add to your app's Gemfile: <code>gem 'asset_hat', '0.x.x'</code>
51
55
  2. Command-line: <code>bundle install</code>
52
56
 
53
- * If you're using Rails' <code>config.gem</code>, add to your app's
54
- <code>config/environment.rb</code>:
55
-
56
- config.gem 'asset_hat', :version => '0.x.x'
57
+ * If you're using Rails 2.x's <code>config.gem</code>:
57
58
 
58
- 3. Add to your app's Rakefile:
59
+ 1. Add to your app's <code>config/environment.rb</code>:
60
+ <code>config.gem 'asset_hat', :version => '0.x.x'</code>
61
+ 2. Command-line: <code>gem install asset_hat</code>
59
62
 
60
- require 'asset_hat/tasks'
63
+ 2. Add to your app's Rakefile: <code>require 'asset_hat/tasks'</code>
61
64
 
62
65
 
63
66
 
@@ -82,17 +85,21 @@ Tested with Rails 2.3.x.
82
85
  Bundles are created as new files in
83
86
  <code>public/stylesheets/bundles/</code> and
84
87
  <code>public/javascripts/bundles/</code>. Your original CSS/JS files
85
- remain intact.
88
+ remain untouched.
86
89
 
87
90
  4. Set your deployment script to run <code>rake asset_hat:minify</code> after
88
91
  deploying your latest CSS/JS. This overwrites previously minified bundles,
89
- and leaves your original CSS/JS files intact.
92
+ and leaves your original CSS/JS files untouched.
90
93
 
91
94
  === Advanced configuration
92
95
 
93
96
  If you manage deployments with Capistrano[http://www.capify.org/], see the
94
97
  gem's packaged example at <code>lib/asset_hat/capistrano.rb</code>.
95
98
 
99
+ If you want shorter output during deployments, you can use
100
+ `rake asset_hat:minify FORMAT=short` (one output line per bundle) or
101
+ `FORMAT=dot` (one output line total) in your deploy script.
102
+
96
103
  Additional settings are supported in <code>config/assets.yml</code>:
97
104
 
98
105
  * <code>engine</code>: Indicates how CSS and JS are minified; omit this
@@ -102,26 +109,64 @@ Additional settings are supported in <code>config/assets.yml</code>:
102
109
  rgrove/jsmin[http://github.com/rgrove/jsmin] (a Ruby port of Crockford's
103
110
  JSMin).
104
111
 
105
- If the default engines cause problems by minifying too
106
- strongly, try switching each to <code>weak</code>. The <code>weak</code>
107
- engines are much safer, but don't save as many bytes.
112
+ If you'd prefer to have slightly more readable code for debugging purposes,
113
+ you can switch both the CSS and JS engines to <code>weak</code>. However,
114
+ the <code>weak</code> engines don't save as many bytes.
108
115
 
109
- * <code>vendors</code>: Currently only allows for setting the jQuery version
110
- number:
116
+ * <code>vendors</code>: Configures third-party JS that's loaded from a CDN or
117
+ other external source. The following example configures jQuery and jQuery UI
118
+ for use throughout the app:
111
119
 
112
120
  js:
113
121
  vendors:
114
122
  jquery:
115
- version: 1.4
123
+ version: 1.4.4
124
+ jquery_ui:
125
+ version: 1.8.5
126
+ remote_url: http://cdn.example.com/js/jquery-ui-1.8.5.min.js
127
+ remote_ssl_url: https://cdn-ssl.example.com/js/jquery-ui-1.8.5.min.js
128
+
129
+ Configuration keys per vendor:
116
130
 
117
- In the future, this will be used for configuring the retrieval of other
118
- third-party code.
131
+ * <code>version</code>: Sets the default version across the app. In the
132
+ example above, <code><%= include_js :jquery %></code> uses version 1.4.4
133
+ by default. You can override this for special layouts/views with
134
+ <code><%= include_js :jquery, :version => '1.3.2' %></code>.
135
+ * <code>remote_url</code>, <code>remote_ssl_url</code>: By default, vendor
136
+ JS will load from {Google's CDN}[http://code.google.com/apis/ajaxlibs/]
137
+ in production (or any environment where
138
+ <code>config.action_controller.consider_all_requests_local</code> is set
139
+ to <code>true</code>). If the original request to your app used SSL, the
140
+ vendor JS will also load from Google's CDN via SSL. If you prefer to use a
141
+ different CDN, specify its SSL/non-SSL URLs, and the appropriate URL will
142
+ be used per request.
143
+
144
+ A full list of supported vendors is in the AssetHat::JS::Vendors module.
145
+
146
+ === SSL configuration
147
+
148
+ When you request a page via SSL, some browsers (euphemism for "IE") show
149
+ errors if any assets -- stylesheets, JS files, images -- are served _without_
150
+ SSL.
151
+
152
+ AssetHat plays well with SSL pages that load assets from a CDN. Put this in
153
+ <code>config/environments/production.rb</code> or similar:
154
+
155
+ config.action_controller.asset_host = Proc.new do |source, request|
156
+ "#{request.protocol}cdn#{source.hash % 4}.example.com"
157
+ # => 'http://cdn0.example.com', 'https://cdn1.example.com', etc.
158
+ end
159
+
160
+ This switches to a different CDN URL if the request used SSL. When you run
161
+ <code>rake asset_hat:minify</code> at deploy time, AssetHat detects this
162
+ configuration, and generates special SSL versions of each stylesheet that also
163
+ load images from CDN via SSL. (Non-SSL pages still get non-SSL stylesheets.)
119
164
 
120
165
 
121
166
 
122
167
  == Usage
123
168
 
124
- In your layouts and views, instead of these:
169
+ In your layouts and views, <b>instead of these</b>:
125
170
 
126
171
  <%= stylesheet_link_tag 'reset', 'application', 'clearfix',
127
172
  :media => 'screen,projection',
@@ -129,7 +174,7 @@ In your layouts and views, instead of these:
129
174
  <%= javascript_include_tag 'plugin-1', 'plugin-2', 'plugin-3',
130
175
  :cache => 'bundles/application' %>
131
176
 
132
- <strong>Use these:</strong>
177
+ <b>Use these:</b>
133
178
 
134
179
  <%= include_css :bundle => 'application' %>
135
180
  <%= include_js :bundle => 'application' %>
@@ -150,6 +195,11 @@ minified bundle files. Otherwise, the separate, unminified files will be
150
195
  included, based on the bundle contents you define in
151
196
  <code>config/assets.yml</code>.
152
197
 
198
+ If your environment has <code>config.action_controller.asset_host</code>
199
+ pointing to a CDN, your CSS/JS files will load from there. If your
200
+ configuration supports using the CDN via SSL (see the section "SSL
201
+ configuration"), SSL requests will also load CSS/JS files via SSL.
202
+
153
203
  === Advanced usage
154
204
 
155
205
  You can also include single files as expected:
@@ -167,5 +217,13 @@ When including multiple bundles at once, this yields one
167
217
  You may want to use multiple bundles to separate plugins (rarely changed) from
168
218
  application code (frequently changed). If all code is in one huge bundle, then
169
219
  whenever there's a change, browsers have to re-download the whole bundle. By
170
- using multiple bundles based on change frequency, browsers cache the rarely
171
- changed code, and only re-download the frequently changed code.
220
+ using multiple bundles based on update frequency, browsers cache the rarely
221
+ updated code, and only re-download the frequently updated code.
222
+
223
+
224
+
225
+ == {What is best in AssetHat?}[http://www.youtube.com/watch?v=V30tyaXv6EI]
226
+
227
+ * To crush your assets;
228
+ * See them bundled before you; and
229
+ * Hear no more lamentation about slow page loads.
data/Rakefile CHANGED
@@ -5,19 +5,26 @@ require 'hanna/rdoctask'
5
5
  begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gemspec|
8
- gemspec.name = %q{asset_hat}
9
- gemspec.summary = %q{Your assets are covered.}
10
- gemspec.description = %q{Minify, bundle, and optimize CSS/JS assets.}
11
- gemspec.homepage = %q{http://github.com/mintdigital/asset_hat}
8
+ gemspec.name = 'asset_hat'
9
+ gemspec.summary = 'Your assets are covered.'
10
+ gemspec.description = %{
11
+ Minifies, bundles, and optimizes CSS/JS assets ahead of time (e.g., on
12
+ deploy), not at runtime. Loads popular JS frameworks (like jQuery and
13
+ Prototype) from localhost in development, and auto-switches to Google's
14
+ CDN in production. Can rewrite stylesheets to use CDN hosts (not just
15
+ your web server) and cache-busting hashes for updated images.
16
+ }.strip.gsub(/\s+/, ' ')
17
+ gemspec.homepage = 'http://github.com/mintdigital/asset_hat'
12
18
 
13
19
  gemspec.authors = ['Ron DeVera', 'Mint Digital']
14
- gemspec.email = %q{ronald.devera@gmail.com}
20
+ gemspec.email = 'hello@rondevera.com'
15
21
 
16
- gemspec.add_development_dependency 'flexmock', '>= 0.8.6'
17
- gemspec.add_development_dependency 'hanna', '>= 0.1.12'
18
- gemspec.add_development_dependency 'shoulda', '>= 2.10.2'
19
- gemspec.add_runtime_dependency 'cssmin', '>= 1.0.2'
20
- gemspec.add_runtime_dependency 'jsmin', '>= 1.0.1'
22
+ gemspec.add_development_dependency 'flexmock', '~> 0.8.6'
23
+ gemspec.add_development_dependency 'hanna', '~> 0.1.12'
24
+ gemspec.add_development_dependency 'jeweler', '~> 1.4.0'
25
+ gemspec.add_development_dependency 'shoulda', '~> 2.10.2'
26
+ gemspec.add_runtime_dependency 'cssmin', '~> 1.0.2'
27
+ gemspec.add_runtime_dependency 'jsmin', '~> 1.0.1'
21
28
  end
22
29
  Jeweler::GemcutterTasks.new
23
30
  rescue LoadError
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 1
4
- :build:
2
+ :minor: 3
3
+ :patch: 0
4
+ :build:
5
5
  :major: 0
@@ -19,10 +19,7 @@ module AssetHatHelper
19
19
  return
20
20
  end
21
21
 
22
- options = args.extract_options!
23
- options.symbolize_keys!
24
- options.reverse_merge!(:media => 'screen,projection') if type == :css
25
-
22
+ options = args.extract_options!.symbolize_keys
26
23
  filenames = []
27
24
  sources = [] # The URLs that are ultimately included via HTML
28
25
  source_commit_ids = {} # Last commit ID for each source
@@ -36,7 +33,10 @@ module AssetHatHelper
36
33
  bundles = [options.delete(:bundle), options.delete(:bundles)].
37
34
  flatten.reject(&:blank?)
38
35
  if use_caching
39
- sources += bundles.map { |b| "bundles/#{b}.min.#{type}" }
36
+ sources += bundles.map do |bundle|
37
+ File.join(AssetHat.bundles_dir(options.slice(:ssl)),
38
+ "#{bundle}.min.#{type}")
39
+ end
40
40
  else
41
41
  config = AssetHat.config
42
42
  filenames = bundles.map { |b| AssetHat.bundle_filenames(b, type) }.
@@ -46,6 +46,7 @@ module AssetHatHelper
46
46
  filenames = args
47
47
  end
48
48
 
49
+ # Add extensions if needed, using minified file if it already exists
49
50
  filenames.each do |filename|
50
51
  if filename.match(/\.#{type}$/)
51
52
  sources << filename
@@ -69,9 +70,11 @@ module AssetHatHelper
69
70
  sources.map! do |src|
70
71
  if src =~ %r{^http(s?)://} || src =~ %r{^//}
71
72
  # Absolute URL; do nothing
72
- elsif src =~ /^bundles\//
73
+ elsif src =~ /^#{AssetHat.bundles_dir}\//
73
74
  # Get commit ID of bundle file with most recently committed update
74
- bundle = src.match(/^bundles\/(.*)\.min\.#{type}$/)[1]
75
+ bundle = src.
76
+ match(/^#{AssetHat.bundles_dir}\/(ssl\/)?(.*)\.min\.#{type}$/).
77
+ to_a.last
75
78
  commit_id = AssetHat.last_bundle_commit_id(bundle, type)
76
79
  else
77
80
  # Get commit ID of file's most recently committed update
@@ -86,12 +89,11 @@ module AssetHatHelper
86
89
  end
87
90
 
88
91
  # Build output HTML
92
+ options.delete :ssl
89
93
  sources.map do |src|
90
94
  case type
91
- when :css
92
- stylesheet_link_tag(src, options)
93
- when :js
94
- javascript_include_tag(src, options)
95
+ when :css ; stylesheet_link_tag(src, options)
96
+ when :js ; javascript_include_tag(src, options)
95
97
  else nil
96
98
  end
97
99
  end.join("\n")
@@ -119,16 +121,27 @@ module AssetHatHelper
119
121
  # => <link href="/stylesheets/reset.min.css" ... />
120
122
  # <link href="/stylesheets/application.min.css" ... />
121
123
  # <link href="/stylesheets/clearfix.min.css" ... />
124
+ #
125
+ # Include a stylesheet with extra media types:
126
+ # include_css 'mobile', :media => 'handheld,screen,projection'
127
+ # => <link href="/stylesheets/mobile.min.css"
128
+ # media="handheld,screen,projection" ... />
122
129
  def include_css(*args)
123
130
  return if args.blank?
124
131
 
125
132
  AssetHat.html_cache ||= {}
126
133
  AssetHat.html_cache[:css] ||= {}
127
- cache_key = args.inspect
134
+
135
+ options = args.extract_options!
136
+ options.symbolize_keys!.reverse_merge!(
137
+ :media => 'screen,projection', :ssl => controller.request.ssl?)
138
+ cache_key = (args + [options]).inspect
128
139
 
129
140
  if !AssetHat.cache? || AssetHat.html_cache[:css][cache_key].blank?
130
141
  # Generate HTML and write to cache
131
- html = AssetHat.html_cache[:css][cache_key] = include_assets(:css, *args)
142
+ options[:ssl] &&= AssetHat.ssl_asset_host_differs?
143
+ html = AssetHat.html_cache[:css][cache_key] =
144
+ include_assets(:css, *(args + [options]))
132
145
  end
133
146
 
134
147
  html ||= AssetHat.html_cache[:css][cache_key]
@@ -148,15 +161,18 @@ module AssetHatHelper
148
161
  # => <script src="/javascripts/application.js" type="text/javascript"></script>
149
162
  #
150
163
  # Include jQuery:
151
- # include_js :jquery # Development/test environment
164
+ # # Development/test environment:
165
+ # include_js :jquery
152
166
  # => <script src="/javascripts/jquery-VERSION.min.js" ...></script>
153
- # include_js :jquery # Staging/production environment
167
+ #
168
+ # # Staging/production environment:
169
+ # include_js :jquery
154
170
  # => <script src="http://ajax.googleapis.com/.../jquery.min.js" ...></script>
155
171
  # # Set jQuery versions either in `config/assets.yml`, or by using
156
172
  # # `include_js :jquery, :version => '1.4'`.
157
173
  #
158
174
  # Include a bundle of JS files (i.e., a concatenated set of files;
159
- # configure in config/assets.yml):
175
+ # configure in <code>config/assets.yml</code>):
160
176
  # include_js :bundle => 'application'
161
177
  # => <script src="/javascripts/bundles/application.min.js" ...></script>
162
178
  #
@@ -175,21 +191,25 @@ module AssetHatHelper
175
191
 
176
192
  AssetHat.html_cache ||= {}
177
193
  AssetHat.html_cache[:js] ||= {}
178
- cache_key = args.inspect
194
+
195
+ options = args.extract_options!
196
+ options.symbolize_keys!.reverse_merge!(:ssl => controller.request.ssl?)
197
+ cache_key = (args + [options]).inspect
179
198
 
180
199
  if !AssetHat.cache? || AssetHat.html_cache[:js][cache_key].blank?
181
200
  # Generate HTML and write to cache
182
201
 
183
202
  html = []
184
- options = args.extract_options!
185
-
186
203
  included_vendors = (args & AssetHat::JS::VENDORS)
187
204
  included_vendors.each do |vendor|
188
205
  args.delete vendor
189
- src = AssetHat::JS::Vendors.source_for(vendor, options.slice(:version))
206
+ src = AssetHat::JS::Vendors.source_for(
207
+ vendor, options.slice(:ssl, :version))
190
208
  html << include_assets(:js, src, :cache => true)
191
209
  end
192
210
 
211
+ options.except! :ssl, :version
212
+
193
213
  html << include_assets(:js, *(args + [options]))
194
214
  html = html.join("\n").strip
195
215
  AssetHat.html_cache[:js][cache_key] = html