js-asset_paths 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/js-asset_paths.rb +3 -0
- data/lib/js_asset_paths.rb +1 -3
- data/test/lib/engine_test.rb +2 -3
- data/test/lib/generator_test.rb +38 -0
- metadata +59 -22
- data/.gitignore +0 -3
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -50
- data/Rakefile +0 -12
- data/app/assets/javascripts/js-asset_paths.js.erb +0 -56
- data/js_asset_paths.gemspec +0 -25
- data/lib/js-asset_paths.rb +0 -1
- data/lib/js_asset_paths/engine.rb +0 -11
- data/lib/js_asset_paths/generator.rb +0 -47
- data/lib/js_asset_paths/version.rb +0 -3
- data/test/test_helper.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bee2521a4dad14596ce59b2a0597b6a159c5a15e
|
4
|
+
data.tar.gz: '0548e3a8a80f9781e0ff5fccf31768e20cafbb56'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8140423734516659326e33d0bb26f7531af8c02280bca55f70769a08d8e1638c69dcca3220a720ee0004d8441761962c47bc59d2ee9199048447684aad350dd1
|
7
|
+
data.tar.gz: 969d26221667f92fe1f89686763e6409ce5fc88455b94025f5c4d16406b362307a5cc08b211ab994c6f064490e5847413a14039d5225d0ae672bf4004a5c6c74
|
data/lib/js_asset_paths.rb
CHANGED
data/test/lib/engine_test.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'execjs'
|
2
|
+
require_relative '../test_helper'
|
3
|
+
|
4
|
+
describe JsAssetPaths::Generator do
|
5
|
+
before do
|
6
|
+
App.initialize! unless App.initialized?
|
7
|
+
|
8
|
+
JsAssetPaths::Generator.environment = Rails.application
|
9
|
+
@output = JsAssetPaths::Generator.generate!
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is idempotent' do
|
13
|
+
assert_equal @output, JsAssetPaths::Generator.generate!
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'output is a string' do
|
17
|
+
assert_kind_of String, @output
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'output evaluates as valid javascript' do
|
21
|
+
ExecJS.eval(@output)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'output evaluates to a hash' do
|
25
|
+
assert_kind_of Hash, ExecJS.eval(@output)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'output has corresponding key and value pairs' do
|
29
|
+
map = ExecJS.eval(@output)
|
30
|
+
|
31
|
+
map.each do |key, value|
|
32
|
+
file = key.split('/').second
|
33
|
+
name, _, ext = file.rpartition('.')
|
34
|
+
|
35
|
+
assert_match /#{name}-[0-9,a-z]{64}.#{ext}/, value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Sonny Michaud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,28 +48,70 @@ dependencies:
|
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '12'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
67
|
version: '0'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
|
-
- - "
|
72
|
+
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
74
|
version: '0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
76
|
+
name: appraisal
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
|
-
- - "
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.2'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: execjs
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.7'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.7'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: therubyracer
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
60
108
|
- !ruby/object:Gem::Version
|
61
109
|
version: '0'
|
62
110
|
type: :development
|
63
111
|
prerelease: false
|
64
112
|
version_requirements: !ruby/object:Gem::Requirement
|
65
113
|
requirements:
|
66
|
-
- - "
|
114
|
+
- - "~>"
|
67
115
|
- !ruby/object:Gem::Version
|
68
116
|
version: '0'
|
69
117
|
description: Access paths to compiled assets from in javascript.
|
@@ -73,22 +121,11 @@ executables: []
|
|
73
121
|
extensions: []
|
74
122
|
extra_rdoc_files: []
|
75
123
|
files:
|
76
|
-
- ".gitignore"
|
77
|
-
- ".ruby-version"
|
78
|
-
- Gemfile
|
79
|
-
- LICENSE.txt
|
80
|
-
- README.md
|
81
|
-
- Rakefile
|
82
|
-
- app/assets/javascripts/js-asset_paths.js.erb
|
83
|
-
- js_asset_paths.gemspec
|
84
124
|
- lib/js-asset_paths.rb
|
85
125
|
- lib/js_asset_paths.rb
|
86
|
-
- lib/js_asset_paths/engine.rb
|
87
|
-
- lib/js_asset_paths/generator.rb
|
88
|
-
- lib/js_asset_paths/version.rb
|
89
126
|
- test/lib/engine_test.rb
|
90
|
-
- test/
|
91
|
-
homepage:
|
127
|
+
- test/lib/generator_test.rb
|
128
|
+
homepage: https://github.com/sonnym/js-asset_paths
|
92
129
|
licenses:
|
93
130
|
- MIT
|
94
131
|
metadata: {}
|
@@ -114,4 +151,4 @@ specification_version: 4
|
|
114
151
|
summary: Access paths to compiled assets from in javascript.
|
115
152
|
test_files:
|
116
153
|
- test/lib/engine_test.rb
|
117
|
-
- test/
|
154
|
+
- test/lib/generator_test.rb
|
data/.gitignore
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.4.1
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 sonnym
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# JS Asset Paths
|
2
|
-
|
3
|
-
Inspired by [js-routes](https://github.com/railsware/js-routes), JS Asset Paths makes the helper methods found in [ActionView::Helpers::AssetUrlHelper](http://rubydoc.info/docs/rails/ActionView/Helpers/AssetUrlHelper) available to the client.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'js-asset_paths'
|
11
|
-
```
|
12
|
-
|
13
|
-
Then require the js-asset_paths file in your `application.js`.
|
14
|
-
|
15
|
-
``` js
|
16
|
-
/*
|
17
|
-
= require js-asset_paths
|
18
|
-
*/
|
19
|
-
```
|
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
|
-
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
A global object called `PathHelper` will be created with the following methods:
|
31
|
-
|
32
|
-
- assetPath(source[, options])
|
33
|
-
- fontPath(source)
|
34
|
-
- imagePath(source)
|
35
|
-
- javascriptPath(source)
|
36
|
-
- stylesheetPath(source)
|
37
|
-
|
38
|
-
These functions operate in the same manner as their server-side counterparts.
|
39
|
-
|
40
|
-
## Explanation
|
41
|
-
|
42
|
-
JS Asset Paths inspects the configuration options for the current environment and determines whether or not a digest will be appended to the pathname of asset files. An object correlating the truncated asset path with the actual path to the asset on the server is stored in the generated javascript and referenced during each call.
|
43
|
-
|
44
|
-
## Contributing
|
45
|
-
|
46
|
-
1. Fork it
|
47
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
-
5. Create new Pull Request
|
data/Rakefile
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
<%# encoding: utf-8 %>
|
2
|
-
|
3
|
-
var PathHelper = (function(definitions) {
|
4
|
-
var assetExtensions = <%= ActionView::Helpers::AssetUrlHelper::ASSET_EXTENSIONS.to_json %>;
|
5
|
-
var assetPublicDirectories = <%= ActionView::Helpers::AssetUrlHelper::ASSET_PUBLIC_DIRECTORIES.to_json %>;
|
6
|
-
|
7
|
-
return {
|
8
|
-
assetPath: function(source, opts) {
|
9
|
-
return [prefix(source), filename(source, opts)].join("/");
|
10
|
-
},
|
11
|
-
|
12
|
-
fontPath: function(source) {
|
13
|
-
return this.assetPath(source, { type: "font" });
|
14
|
-
},
|
15
|
-
|
16
|
-
imagePath: function(source) {
|
17
|
-
return this.assetPath(source, { type: "image" });
|
18
|
-
},
|
19
|
-
|
20
|
-
javascriptPath: function(source) {
|
21
|
-
return this.assetPath(source, { type: "javascript" });
|
22
|
-
},
|
23
|
-
|
24
|
-
stylesheetPath: function(source) {
|
25
|
-
return this.assetPath(source, { type: "stylesheet" });
|
26
|
-
},
|
27
|
-
};
|
28
|
-
|
29
|
-
function prefix(path) {
|
30
|
-
var prefix = path.split("/");
|
31
|
-
|
32
|
-
prefix.pop();
|
33
|
-
prefix.shift();
|
34
|
-
prefix.unshift("assets");
|
35
|
-
|
36
|
-
return prefix.join("/");
|
37
|
-
}
|
38
|
-
|
39
|
-
function filename(source, opts) {
|
40
|
-
var key = source;
|
41
|
-
|
42
|
-
if (opts && opts.type) {
|
43
|
-
key = [assetPublicDirectories[opts.type], key].join("/");
|
44
|
-
|
45
|
-
if (source.split(".").length === 1) {
|
46
|
-
key = [key, assetExtensions[opts.type]].join(".");
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
if (definitions[key]) {
|
51
|
-
return definitions[key];
|
52
|
-
} else {
|
53
|
-
throw "Unknown asset '" + key + "'. If you created it recently, you may need to restart Rails.";
|
54
|
-
}
|
55
|
-
}
|
56
|
-
})(<%= JsAssetPaths::Generator.generate! %>);
|
data/js_asset_paths.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'js_asset_paths/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'js-asset_paths'
|
8
|
-
spec.version = JsAssetPaths::VERSION
|
9
|
-
spec.authors = ['sonnym']
|
10
|
-
spec.email = ['michaud.sonny@gmail.com']
|
11
|
-
spec.description = 'Access paths to compiled assets from in javascript.'
|
12
|
-
spec.summary = spec.description
|
13
|
-
spec.homepage = ''
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ['lib']
|
20
|
-
|
21
|
-
spec.add_runtime_dependency(%q<rails>, ['>= 4.0'])
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
-
spec.add_development_dependency 'rake'
|
24
|
-
spec.add_development_dependency 'pry'
|
25
|
-
end
|
data/lib/js-asset_paths.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
lib/js_asset_paths.rb
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module JsAssetPaths
|
2
|
-
class Engine < Rails::Engine
|
3
|
-
JS_ASSET_PATHS_FILE = 'js-asset_paths'
|
4
|
-
|
5
|
-
isolate_namespace(JsAssetPaths)
|
6
|
-
|
7
|
-
initializer('js-assets_paths.compile', after: 'sprockets.environment') do |application|
|
8
|
-
JsAssetPaths::Generator.environment = application
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module JsAssetPaths
|
2
|
-
class Generator
|
3
|
-
cattr_accessor :environment
|
4
|
-
|
5
|
-
def self.generate!
|
6
|
-
asset_hash.to_json
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
# Note: In sprockets 2, `each_file` yields a `Pathname`. In 3,
|
12
|
-
# it yields a string. This method supports both.
|
13
|
-
def self.asset_hash
|
14
|
-
assets.each_file.each_with_object({}) do |filepath, memo|
|
15
|
-
path = ::Pathname.new(filepath.to_s)
|
16
|
-
relative_path = path.relative_path_from(base_asset_path)
|
17
|
-
|
18
|
-
memo[relative_path] = output_path(path) if local?(relative_path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.base_asset_path
|
23
|
-
@base_asset_path || Rails.root.join('app', 'assets')
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.output_path(filepath)
|
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
|
33
|
-
filepath.basename.to_s
|
34
|
-
else
|
35
|
-
raise "Expected ::Rails.application.config.assets.digest to be boolean"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.assets
|
40
|
-
environment.assets
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.local?(filepath)
|
44
|
-
!(filepath.to_s =~ /\.\.\//)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
ENV['RAILS_ENV'] = 'test'
|
6
|
-
require 'sprockets/railtie'
|
7
|
-
require 'rails/test_unit/railtie'
|
8
|
-
require 'rails/test_help'
|
9
|
-
|
10
|
-
require File.expand_path('../../lib/js_asset_paths.rb', __FILE__)
|
11
|
-
|
12
|
-
class App < Rails::Application
|
13
|
-
config.eager_load = true
|
14
|
-
|
15
|
-
config.assets.enabled = true
|
16
|
-
config.assets.initialize_on_precompile = true
|
17
|
-
end
|