asset_hat 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,6 +1,11 @@
1
1
  HISTORY
2
2
  =======
3
3
 
4
+ Version 0.1.2 (2010-01-27)
5
+ --------------------------
6
+ * Memoized HTML output from `include_css` and `include_js` when
7
+ `AssetHat.cache?` is true.
8
+
4
9
  Version 0.1.1 (2010-01-20)
5
10
  --------------------------
6
11
  * Rewrote `AssetHat::VERSION` to be based on `VERSION.yml`.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 1
3
- :major: 0
4
2
  :minor: 1
3
+ :patch: 2
4
+ :major: 0
5
5
  :build:
@@ -115,7 +115,18 @@ module AssetHatHelper
115
115
  # <link href="/stylesheets/clearfix.min.css" ... />
116
116
 
117
117
  return if args.blank?
118
- include_assets :css, *args
118
+
119
+ AssetHat.html_cache ||= {}
120
+ AssetHat.html_cache[:css] ||= {}
121
+ cache_key = args.inspect
122
+
123
+ if !AssetHat.cache? || AssetHat.html_cache[:css][cache_key].blank?
124
+ # Generate HTML and write to cache
125
+ html = AssetHat.html_cache[:css][cache_key] = include_assets(:css, *args)
126
+ end
127
+
128
+ html ||= AssetHat.html_cache[:css][cache_key]
129
+ html
119
130
  end
120
131
 
121
132
  def include_js(*args)
@@ -154,18 +165,31 @@ module AssetHatHelper
154
165
  # <script src="/javascripts/jquery.json.min.js" ...></script>
155
166
 
156
167
  return if args.blank?
157
- html = []
158
- options = args.extract_options!
159
168
 
160
- included_vendors = (args & AssetHat::JS::VENDORS)
161
- included_vendors.each do |vendor|
162
- args.delete vendor
163
- source = AssetHat::JS::Vendors.source_for(vendor, options.slice(:version))
164
- html << include_assets(:js, source, :cache => true)
169
+ AssetHat.html_cache ||= {}
170
+ AssetHat.html_cache[:js] ||= {}
171
+ cache_key = args.inspect
172
+
173
+ if !AssetHat.cache? || AssetHat.html_cache[:js][cache_key].blank?
174
+ # Generate HTML and write to cache
175
+
176
+ html = []
177
+ options = args.extract_options!
178
+
179
+ included_vendors = (args & AssetHat::JS::VENDORS)
180
+ included_vendors.each do |vendor|
181
+ args.delete vendor
182
+ src = AssetHat::JS::Vendors.source_for(vendor, options.slice(:version))
183
+ html << include_assets(:js, src, :cache => true)
184
+ end
185
+
186
+ html << include_assets(:js, *(args + [options]))
187
+ html = html.join("\n").strip
188
+ AssetHat.html_cache[:js][cache_key] = html
165
189
  end
166
190
 
167
- html << include_assets(:js, *(args + [options]))
168
- html.join("\n").strip
191
+ html ||= AssetHat.html_cache[:js][cache_key]
192
+ html
169
193
  end
170
194
 
171
195
  end
data/asset_hat.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{asset_hat}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ron DeVera", "Mint Digital"]
12
- s.date = %q{2010-01-20}
12
+ s.date = %q{2010-01-27}
13
13
  s.description = %q{Minify, bundle, and optimize CSS/JS assets.}
14
14
  s.email = %q{ronald.devera@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/asset_hat.rb CHANGED
@@ -10,6 +10,10 @@ module AssetHat
10
10
  STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets"
11
11
  CONFIG_FILEPATH = File.join(RAILS_ROOT, 'config', 'assets.yml')
12
12
 
13
+ class << self
14
+ attr_accessor :html_cache
15
+ end
16
+
13
17
  def self.config
14
18
  @@config ||= YAML.load(File.open(CONFIG_FILEPATH, 'r'))
15
19
  end
data/test/test_helper.rb CHANGED
@@ -21,3 +21,11 @@ unless defined?(Rails)
21
21
  end
22
22
  end
23
23
  end
24
+
25
+ class ActionView::TestCase
26
+ teardown :clear_html_cache
27
+
28
+ def clear_html_cache
29
+ AssetHat.html_cache = {}
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_hat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron DeVera
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-20 00:00:00 -05:00
13
+ date: 2010-01-27 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency