turbo-sprockets-rails3 0.1.17 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -32,7 +32,7 @@ Warning: Don't add this gem to the `:assets` group. It must be available in the
32
32
 
33
33
  Run `bundle` to install the gem, and you're done!
34
34
 
35
- Test it out by running `rake assets:precompile`. When it's finished, your `public/assets/manifest.yml` file should include a `:source_digests` hash for your assets.
35
+ Test it out by running `rake assets:precompile`. When it's finished, you should see a new file at `public/assets/sources_manifest.yml`, which includes the source fingerprints for your assets.
36
36
 
37
37
  Go on, run `rake assets:precompile` again, and it should be a whole lot faster than before.
38
38
 
@@ -42,13 +42,7 @@ Enjoy your lightning fast deploys!
42
42
 
43
43
  ### [asset_sync](https://github.com/rumblelabs/asset_sync)
44
44
 
45
- Fully compatible. Just don't use the experimental `AssetSync.config.manifest = true` configuration option until
46
- [my asset_sync patch](https://github.com/rumblelabs/asset_sync/pull/110) has been merged. Alternatively, you can use my patched `asset_sync` with the following line in your `Gemfile`:
47
-
48
- ```ruby
49
- gem "asset_sync", :github => "ndbroadbent/asset_sync", :branch => "new_manifest_support"
50
- ```
51
-
45
+ Fully compatible.
52
46
 
53
47
  ### [wicked_pdf](https://github.com/mileszs/wicked_pdf)
54
48
 
@@ -11,10 +11,10 @@ module Sprockets
11
11
  @env = env
12
12
  @target = target
13
13
  @paths = paths
14
- @digest_files = options.fetch(:digest_files, {})
14
+ @digests = options.fetch(:digests, {})
15
15
 
16
- # Parse digests from digest_files hash
17
- @asset_digests = Hash[*@digest_files.map {|file, digest_file|
16
+ # Parse digests from digests hash
17
+ @asset_digests = Hash[*@digests.map {|file, digest_file|
18
18
  [file, digest_file[DIGEST_REGEX, 1]]
19
19
  }.flatten]
20
20
  end
@@ -32,7 +32,7 @@ module Sprockets
32
32
  end
33
33
  next unless compile_path?(logical_path)
34
34
 
35
- if digest_path = @digest_files[logical_path]
35
+ if digest_path = @digests[logical_path]
36
36
  abs_digest_path = "#{@target}/#{digest_path}"
37
37
  abs_logical_path = "#{@target}/#{logical_path}"
38
38
 
@@ -1,5 +1,4 @@
1
1
  require 'sprockets/railtie'
2
- require 'sprockets/helpers'
3
2
 
4
3
  module Sprockets
5
4
  # Assets
@@ -7,7 +6,7 @@ module Sprockets
7
6
  autoload :AssetWithDependencies, "sprockets/asset_with_dependencies"
8
7
  end
9
8
 
10
- Dir[File.expand_path('../turbo-sprockets/sprockets_overrides/**/*.rb', __FILE__)].each do |f|
9
+ Dir[File.expand_path('../turbo-sprockets/sprockets_overrides/*.rb', __FILE__)].each do |f|
11
10
  require f
12
11
  end
13
12
 
@@ -13,18 +13,11 @@ module TurboSprockets
13
13
  initializer "turbo-sprockets.environment", :after => "sprockets.environment", :group => :all do |app|
14
14
  config = app.config
15
15
 
16
- if config.assets.manifest
17
- manifest_path = File.join(config.assets.manifest, "manifest.yml")
18
- else
19
- manifest_path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml")
20
- end
21
-
22
- if File.exist?(manifest_path)
23
- manifest = YAML.load_file(manifest_path)
24
- # Set both digest keys for backwards compatibility
25
- config.assets.digests = config.assets.digest_files = manifest[:digest_files] || {}
26
- config.assets.source_digests = manifest[:source_digests] || {}
27
- end
16
+ manifest_dir = config.assets.manifest || File.join(Rails.public_path, config.assets.prefix)
17
+ digests_manifest = File.join(manifest_dir, "manifest.yml")
18
+ sources_manifest = File.join(manifest_dir, "sources_manifest.yml")
19
+ config.assets.digests = (File.exist?(digests_manifest) && YAML.load_file(digests_manifest)) || {}
20
+ config.assets.source_digests = (File.exist?(sources_manifest) && YAML.load_file(sources_manifest)) || {}
28
21
  end
29
22
  end
30
- end
23
+ end
@@ -17,9 +17,9 @@ if defined?(Sprockets::StaticCompiler)
17
17
  @zip_files = options.delete(:zip_files) || /\.(?:css|html|js|svg|txt|xml)$/
18
18
 
19
19
  @current_source_digests = options.fetch(:source_digests, {})
20
- @current_digest_files = options.fetch(:digest_files, {})
20
+ @current_digests = options.fetch(:digests, {})
21
21
 
22
- @digest_files = {}
22
+ @digests = {}
23
23
  @source_digests = {}
24
24
  end
25
25
 
@@ -38,19 +38,21 @@ if defined?(Sprockets::StaticCompiler)
38
38
  @source_digests[logical_path] = asset.digest
39
39
 
40
40
  # Recompile if digest has changed or compiled digest file is missing
41
- current_digest_file = @current_digest_files[logical_path]
41
+ current_digest_file = @current_digests[logical_path]
42
42
 
43
43
  if @source_digests[logical_path] != @current_source_digests[logical_path] ||
44
44
  !(current_digest_file && File.exists?("#{@target}/#{current_digest_file}"))
45
45
 
46
46
  if asset = env.find_asset(logical_path)
47
- @digest_files[logical_path] = write_asset(asset)
47
+ @digests[logical_path] = write_asset(asset)
48
+ # Update current_digests with new hash, for future assets to reference
49
+ @current_digests[logical_path] = asset.digest_path
48
50
  end
49
51
 
50
52
  else
51
53
  # Set asset file from manifest.yml
52
- digest_file = @current_digest_files[logical_path]
53
- @digest_files[logical_path] = digest_file
54
+ digest_file = @current_digests[logical_path]
55
+ @digests[logical_path] = digest_file
54
56
 
55
57
  env.logger.debug "Not compiling #{logical_path}, sources digest has not changed " <<
56
58
  "(#{@source_digests[logical_path][0...7]})"
@@ -62,22 +64,32 @@ if defined?(Sprockets::StaticCompiler)
62
64
  # otherwise YAML dumps other string encodings as !binary
63
65
  if RUBY_VERSION.to_f >= 1.9
64
66
  @source_digests = encode_hash_as_utf8 @source_digests
65
- @digest_files = encode_hash_as_utf8 @digest_files
67
+ @digests = encode_hash_as_utf8 @digests
66
68
  end
67
69
 
68
70
  if @manifest
69
- write_manifest(:source_digests => @source_digests, :digest_files => @digest_files)
71
+ write_manifest(@digests, @source_digests)
70
72
  end
71
73
 
72
74
  # Store digests in Rails config. (Important if non-digest is run after primary)
73
75
  config = ::Rails.application.config
74
- config.assets.digest_files = @digest_files
76
+ config.assets.digests = @digests
75
77
  config.assets.source_digests = @source_digests
76
78
 
77
79
  elapsed_time = ((Time.now.to_f - start_time) * 1000).to_i
78
80
  env.logger.debug "Processed #{'non-' unless @digest}digest assets in #{elapsed_time}ms"
79
81
  end
80
82
 
83
+ def write_manifest(digests, source_digests)
84
+ FileUtils.mkdir_p(@manifest_path)
85
+ File.open("#{@manifest_path}/manifest.yml", 'wb') do |f|
86
+ YAML.dump(digests, f)
87
+ end
88
+ File.open("#{@manifest_path}/sources_manifest.yml", 'wb') do |f|
89
+ YAML.dump(source_digests, f)
90
+ end
91
+ end
92
+
81
93
  private
82
94
 
83
95
  def encode_hash_as_utf8(hash)
@@ -54,8 +54,8 @@ namespace :assets do
54
54
  config = Rails.application.config
55
55
  config.assets.compile = true
56
56
  config.assets.clean_after_precompile = false if config.assets.clean_after_precompile.nil?
57
- config.assets.digest = digest unless digest.nil?
58
- config.assets.digest_files ||= {}
57
+ config.assets.digest = digest unless digest.nil?
58
+ config.assets.digests ||= {}
59
59
  config.assets.source_digests ||= {}
60
60
 
61
61
  env = Rails.application.assets
@@ -65,16 +65,16 @@ namespace :assets do
65
65
  # present, then generate non-digest assets from existing assets.
66
66
  # It is assumed that `assets:precompile:nondigest` won't be run manually
67
67
  # if assets have been previously compiled with digests.
68
- if !config.assets.digest && config.assets.digest_files.any?
68
+ if !config.assets.digest && config.assets.digests.any?
69
69
  generator = Sprockets::StaticNonDigestGenerator.new(env, target, config.assets.precompile,
70
- :digest_files => config.assets.digest_files)
70
+ :digests => config.assets.digests)
71
71
  generator.generate
72
72
  else
73
73
  compiler = Sprockets::StaticCompiler.new(env, target, config.assets.precompile,
74
74
  :digest => config.assets.digest,
75
75
  :manifest => digest.nil?,
76
76
  :manifest_path => config.assets.manifest,
77
- :digest_files => config.assets.digest_files,
77
+ :digests => config.assets.digests,
78
78
  :source_digests => config.assets.source_digests
79
79
  )
80
80
  compiler.compile
@@ -1,3 +1,3 @@
1
1
  module TurboSprockets
2
- VERSION = "0.1.17"
2
+ VERSION = "0.2.0"
3
3
  end
data/test/assets_test.rb CHANGED
@@ -153,14 +153,14 @@ module ApplicationTests
153
153
  precompile!
154
154
  manifest = "#{app_path}/public/assets/manifest.yml"
155
155
 
156
- digests = YAML.load_file(manifest)
157
- digest_files, source_digests = digests[:digest_files], digests[:source_digests]
156
+ digests = YAML.load_file("#{app_path}/public/assets/manifest.yml")
157
+ sources = YAML.load_file("#{app_path}/public/assets/sources_manifest.yml")
158
158
 
159
- assert_match(/application-([0-z]+)\.js/, digest_files["application.js"])
160
- assert_match(/application-([0-z]+)\.css/, digest_files["application.css"])
159
+ assert_match(/application-([0-z]+)\.js/, digests["application.js"])
160
+ assert_match(/application-([0-z]+)\.css/, digests["application.css"])
161
161
 
162
- assert_match(/[0-z]+/, source_digests["application.js"])
163
- assert_match(/[0-z]+/, source_digests["application.css"])
162
+ assert_match(/[0-z]+/, sources["application.js"])
163
+ assert_match(/[0-z]+/, sources["application.css"])
164
164
  end
165
165
 
166
166
  test "the manifest file should be saved by default in the same assets folder" do
@@ -172,8 +172,8 @@ module ApplicationTests
172
172
  precompile!
173
173
 
174
174
  manifest = "#{app_path}/public/x/manifest.yml"
175
- digest_files = YAML.load_file(manifest)[:digest_files]
176
- assert_match(/application-([0-z]+)\.js/, digest_files["application.js"])
175
+ digests = YAML.load_file(manifest)
176
+ assert_match(/application-([0-z]+)\.js/, digests["application.js"])
177
177
  end
178
178
 
179
179
  test "precompile does not append asset digests when config.assets.digest is false" do
@@ -188,9 +188,9 @@ module ApplicationTests
188
188
 
189
189
  manifest = "#{app_path}/public/assets/manifest.yml"
190
190
 
191
- digest_files = YAML.load_file(manifest)[:digest_files]
192
- assert_equal "application.js", digest_files["application.js"]
193
- assert_equal "application.css", digest_files["application.css"]
191
+ digests = YAML.load_file(manifest)
192
+ assert_equal "application.js", digests["application.js"]
193
+ assert_equal "application.css", digests["application.css"]
194
194
  end
195
195
 
196
196
  test "assets do not require any assets group gem when manifest file is present" do
@@ -201,8 +201,8 @@ module ApplicationTests
201
201
  precompile!
202
202
 
203
203
  manifest = "#{app_path}/public/assets/manifest.yml"
204
- digest_files = YAML.load_file(manifest)[:digest_files]
205
- asset_path = digest_files["application.js"]
204
+ digests = YAML.load_file(manifest)
205
+ asset_path = digests["application.js"]
206
206
 
207
207
  require "#{app_path}/config/environment"
208
208
 
@@ -240,7 +240,7 @@ module ApplicationTests
240
240
  test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
241
241
  app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
242
242
  add_to_config "config.assets.compile = false"
243
- add_to_config "config.assets.digest_files = false"
243
+ add_to_config "config.assets.digests = false"
244
244
 
245
245
  app_file "config/routes.rb", <<-RUBY
246
246
  AppTemplate::Application.routes.draw do
@@ -289,9 +289,9 @@ module ApplicationTests
289
289
  app_file "app/assets/images/rails.png", "image changed"
290
290
 
291
291
  precompile!
292
- digest_files = YAML.load_file(manifest)[:digest_files]
292
+ digests = YAML.load_file(manifest)
293
293
 
294
- assert_not_equal asset_path, digest_files["application.css"]
294
+ assert_not_equal asset_path, digests["application.css"]
295
295
  end
296
296
 
297
297
  test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do
@@ -1,7 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/sprockets_helpers_abstract_unit")
2
2
  require 'sprockets'
3
3
  require 'sprockets/helpers/rails_helper'
4
- require 'turbo-sprockets/sprockets_overrides/helpers/rails_helper'
5
4
  require 'mocha'
6
5
 
7
6
  class SprocketsHelperTest < ActionView::TestCase
@@ -355,7 +354,7 @@ class SprocketsHelperTest < ActionView::TestCase
355
354
  end
356
355
 
357
356
  test "precedence of `config.digest = false` over manifest.yml asset digests" do
358
- Rails.application.config.assets.digest_files = {'logo.png' => 'logo-d1g3st.png'}
357
+ Rails.application.config.assets.digests = {'logo.png' => 'logo-d1g3st.png'}
359
358
  @config.assets.digest = false
360
359
 
361
360
  assert_equal '/assets/logo.png',
@@ -1,7 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/sprockets_helpers_abstract_unit")
2
2
  require 'sprockets'
3
3
  require 'sprockets/helpers/rails_helper'
4
- require 'turbo-sprockets/sprockets_overrides/helpers/rails_helper'
5
4
  require 'mocha'
6
5
 
7
6
  class SprocketsHelperWithRoutesTest < ActionView::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-sprockets-rails3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -54,7 +54,6 @@ files:
54
54
  - lib/turbo-sprockets/version.rb
55
55
  - lib/turbo-sprockets/tasks/assets.rake
56
56
  - lib/turbo-sprockets/railtie.rb
57
- - lib/turbo-sprockets/sprockets_overrides/helpers/rails_helper.rb
58
57
  - lib/turbo-sprockets/sprockets_overrides/static_compiler.rb
59
58
  - lib/turbo-sprockets/sprockets_overrides/base.rb
60
59
  - lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb
@@ -1,42 +0,0 @@
1
- require 'sprockets/helpers/rails_helper'
2
-
3
- module Sprockets
4
- module Helpers
5
- module RailsHelper
6
- def asset_paths
7
- @asset_paths ||= begin
8
- paths = RailsHelper::AssetPaths.new(config, controller)
9
- paths.asset_environment = asset_environment
10
- paths.digest_files = digest_files
11
- paths.compile_assets = compile_assets?
12
- paths.digest_assets = digest_assets?
13
- paths
14
- end
15
- end
16
-
17
- AssetPaths.class_eval do
18
- attr_accessor :digest_files
19
-
20
- def digest_for(logical_path)
21
- if digest_assets && digest_files && (digest = digest_files[logical_path])
22
- return digest
23
- end
24
-
25
- if compile_assets
26
- if digest_assets && asset = asset_environment[logical_path]
27
- return asset.digest_path
28
- end
29
- return logical_path
30
- else
31
- raise AssetPaths::AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
32
- end
33
- end
34
- end
35
-
36
- private
37
- def digest_files
38
- Rails.application.config.assets.digest_files
39
- end
40
- end
41
- end
42
- end