js-asset_paths 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebeb8b606a8f0080286c8de55e3f01314ebd9487
4
- data.tar.gz: 005facfb1ba090038d722ce33cc99072988ffed8
3
+ metadata.gz: 2a8b16107134c1e0b52a13ae7486cdee81de7d5f
4
+ data.tar.gz: db8c79b3d5f0cb92d747d16d9b53335a9e6fdac7
5
5
  SHA512:
6
- metadata.gz: 274161cbd659ca3221239f6c35d45a26320a75dd8283fa7b2e80c38a927b136a1e650ad8c8b00560427752bf099fe12c893cee933c2656eb90767dbeefaa84cd
7
- data.tar.gz: f5f00570e02ce9def3aeb1e7ccf7b7d8e180a15922bcb8b109cdf1bf3dbfeb739b35c2d8c0cbe14e1342d0bfc4bd485765858befc47b4845942d401e2d6a8231
6
+ metadata.gz: 8d39f9cecf5fdbf369b701c523942aa4e4334723b2de5242e6afafb8483fcbe2c176fb44c82b96d16314b10ed8e56447847ecace67b62cca24af792cfb0c6307
7
+ data.tar.gz: a3c3f9f7b9e9eaae55cad05582a5727ce2d7149f2477a8b4dfb0a16de89f3399a755b4460b1617b525f891f2fa91a472cbe6a51e209291b361bda2d24c962472
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
+ log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/README.md CHANGED
@@ -18,6 +18,13 @@ Then require the js-asset_paths file in your `application.js`.
18
18
  */
19
19
  ```
20
20
 
21
+ Ensure that your `config/environments/production.rb` has the following:
22
+ ```ruby
23
+ config.assets.compile = true
24
+ ```
25
+ (This avoids a `NoMethodError: undefined method each_file for nil:NilClass` when
26
+ precompiling your assets upon deployment.)
27
+
21
28
  ## Usage
22
29
 
23
30
  A global object called `PathHelper` will be created with the following methods:
@@ -49,9 +49,8 @@ var PathHelper = (function(definitions) {
49
49
 
50
50
  if (definitions[key]) {
51
51
  return definitions[key];
52
- }
53
- else {
54
- throw "Unknown asset '" + key + "'";
52
+ } else {
53
+ throw "Unknown asset '" + key + "'. If you created it recently, you may need to restart Rails.";
55
54
  }
56
55
  }
57
56
  })(<%= JsAssetPaths::Generator.generate! %>);
@@ -0,0 +1 @@
1
+ lib/js_asset_paths.rb
@@ -5,14 +5,7 @@ module JsAssetPaths
5
5
  isolate_namespace(JsAssetPaths)
6
6
 
7
7
  initializer('js-assets_paths.compile', after: 'sprockets.environment') do |application|
8
- application.assets.register_preprocessor('application/javascript', :'js-assets_path.compile') do |context, data|
9
- if context.logical_path == JS_ASSET_PATHS_FILE
10
- JsAssetPaths::Generator.environment = application
11
- JsAssetPaths::Generator.context = context
12
- end
13
-
14
- data
15
- end
8
+ JsAssetPaths::Generator.environment = application
16
9
  end
17
10
  end
18
11
  end
@@ -1,6 +1,6 @@
1
1
  module JsAssetPaths
2
2
  class Generator
3
- cattr_accessor :environment, :context
3
+ cattr_accessor :environment
4
4
 
5
5
  def self.generate!
6
6
  asset_hash.to_json
@@ -8,11 +8,14 @@ module JsAssetPaths
8
8
 
9
9
  private
10
10
 
11
+ # Note: In sprockets 2, `each_file` yields a `Pathname`. In 3,
12
+ # it yields a string. This method supports both.
11
13
  def self.asset_hash
12
14
  assets.each_file.each_with_object({}) do |filepath, memo|
13
- relative_path = filepath.relative_path_from(base_asset_path)
15
+ path = ::Pathname.new(filepath.to_s)
16
+ relative_path = path.relative_path_from(base_asset_path)
14
17
 
15
- memo[relative_path] = output_path(filepath) if local?(relative_path)
18
+ memo[relative_path] = output_path(path) if local?(relative_path)
16
19
  end
17
20
  end
18
21
 
@@ -21,10 +24,15 @@ module JsAssetPaths
21
24
  end
22
25
 
23
26
  def self.output_path(filepath)
24
- if context.digest_assets?
25
- "#{filepath.basename(filepath.extname)}-#{assets.file_digest(filepath)}#{filepath.extname}"
26
- else
27
+ case ::Rails.application.config.assets.digest
28
+ when true
29
+ # Convert the byte string into hexadecimal
30
+ dgst = assets.file_digest(filepath).unpack('H*')[0]
31
+ "#{filepath.basename(filepath.extname)}-#{dgst}#{filepath.extname}"
32
+ when false
27
33
  filepath.basename.to_s
34
+ else
35
+ raise "Expected ::Rails.application.config.assets.digest to be boolean"
28
36
  end
29
37
  end
30
38
 
@@ -1,3 +1,3 @@
1
1
  module JsAssetPaths
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../test_helper'
2
2
 
3
3
  describe JsAssetPaths::Engine do
4
- it 'should do something' do
4
+ it 'should not break the whole app' do
5
5
  App.initialize!
6
6
  end
7
7
  end
data/test/test_helper.rb CHANGED
@@ -3,9 +3,9 @@ require 'minitest/autorun'
3
3
  require 'pry'
4
4
 
5
5
  ENV['RAILS_ENV'] = 'test'
6
- #require File.expand_path('../dummy/config/environment.rb', __FILE__)
7
- #require 'rails/test_help'
8
- require 'rails/all'
6
+ require 'sprockets/railtie'
7
+ require 'rails/test_unit/railtie'
8
+ require 'rails/test_help'
9
9
 
10
10
  require File.expand_path('../../lib/js_asset_paths.rb', __FILE__)
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-asset_paths
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonnym
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".ruby-version"
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  requirements: []
109
110
  rubyforge_project:
110
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.6.11
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Access paths to compiled assets from in javascript.
@@ -1,3 +0,0 @@
1
- require 'js_asset_paths/version'
2
- require 'js_asset_paths/engine'
3
- require 'js_asset_paths/generator'