js-asset_paths 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/README.md +7 -0
- data/app/assets/javascripts/js-asset_paths.js.erb +2 -3
- data/lib/js-asset_paths.rb +1 -0
- data/lib/js_asset_paths/engine.rb +1 -8
- data/lib/js_asset_paths/generator.rb +14 -6
- data/lib/js_asset_paths/version.rb +1 -1
- data/test/lib/engine_test.rb +1 -1
- data/test/test_helper.rb +3 -3
- metadata +4 -3
- data/lib/js-asset_paths.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a8b16107134c1e0b52a13ae7486cdee81de7d5f
|
4
|
+
data.tar.gz: db8c79b3d5f0cb92d747d16d9b53335a9e6fdac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d39f9cecf5fdbf369b701c523942aa4e4334723b2de5242e6afafb8483fcbe2c176fb44c82b96d16314b10ed8e56447847ecace67b62cca24af792cfb0c6307
|
7
|
+
data.tar.gz: a3c3f9f7b9e9eaae55cad05582a5727ce2d7149f2477a8b4dfb0a16de89f3399a755b4460b1617b525f891f2fa91a472cbe6a51e209291b361bda2d24c962472
|
data/.gitignore
CHANGED
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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(
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
|
data/test/lib/engine_test.rb
CHANGED
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
|
-
|
7
|
-
|
8
|
-
require 'rails/
|
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.
|
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:
|
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.
|
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.
|
data/lib/js-asset_paths.rb
DELETED