rails_external_asset_pipeline 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a638e36ede2466a8e61d0aaeef99d76b8ae1675
|
4
|
+
data.tar.gz: c6071f9ebd34e3abe91afe2a247cacba584b5b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2ed1c58638b1ed7d1e85d02d429dd64c8b9153fac69efb64d45cdd3c2fe297fedd63bb1980ff9dfbc1c285207b3fb8cc3441b88db4ba9ab35761d1b157f654
|
7
|
+
data.tar.gz: 509b9c120189d32f40e4abf104445ee1069700a265bb7875fbe4622c3f6d5e756f6563399854f85304902e19fee4ff0044a42b613480c0feffd2912d318c94f5
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Instead of using the built-in asset pipeline of Rails, some people want to use e
|
|
4
4
|
|
5
5
|
Why is an integration like that required? If your external asset pipeline modifies the names of the generated files depending on their content (for example by adding a hash of the file to the name), Rails will not be able to find the files on its own. You still want to be able to use the helpers you are used to like `stylesheet_link_tag` or `image_tag`, and they should put out the correct URL for the desired asset. This technique is referred to as *cache busting*.
|
6
6
|
|
7
|
-
So let's say you have a JavaScript file called `application.js` (for example in `app/assets/javascripts`) and your external asset pipeline generates a file called `application-03118e77692b637cfc0f55bb27fef087.js` (for example in `public/assets/javascripts`) from that file. When you use `stylesheet_link_tag 'application'`, you expect that the resulting HTML points to the file containing the hash in its filename. To do that, your pipeline needs to generate manifest files for each type of asset. In this case, it needs to generate a file called `javascript.json` in `public/assets/manifests
|
7
|
+
So let's say you have a JavaScript file called `application.js` (for example in `app/assets/javascripts`) and your external asset pipeline generates a file called `application-03118e77692b637cfc0f55bb27fef087.js` (for example in `public/assets/javascripts`) from that file. When you use `stylesheet_link_tag 'application'`, you expect that the resulting HTML points to the file containing the hash in its filename. To do that, your pipeline needs to generate manifest files for each type of asset. In this case, it needs to generate a file called `javascript.json` in `public/assets/manifests` (to change this, see the Configuration section). The file should look like this:
|
8
8
|
|
9
9
|
```json
|
10
10
|
{
|
@@ -25,7 +25,6 @@ The types supported by this gem are:
|
|
25
25
|
* `stylesheet`
|
26
26
|
* `javascript`
|
27
27
|
* `image`
|
28
|
-
* `font`
|
29
28
|
|
30
29
|
You can find an example of using this gem in Rails 5 with an external Node.js pipeline [here](https://github.com/moonglum/rails-5-and-node-asset-pipeline).
|
31
30
|
|
@@ -49,6 +48,16 @@ Or install it yourself as:
|
|
49
48
|
$ gem install rails_external_asset_pipeline
|
50
49
|
```
|
51
50
|
|
51
|
+
## Configuration
|
52
|
+
|
53
|
+
By default this gem assumes that your manifest files can be found in `public/assets/manifests`. You can change that with the following configuration:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
config.x.rails_external_asset_pipeline.manifests_path = File.join("my", "own", "manifests", "path")
|
57
|
+
```
|
58
|
+
|
59
|
+
The `manifests_path` is relative to your Rails Root.
|
60
|
+
|
52
61
|
## Development
|
53
62
|
|
54
63
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -6,11 +6,16 @@ module RailsExternalAssetPipeline
|
|
6
6
|
|
7
7
|
def compute_asset_path(source, options = {})
|
8
8
|
if TYPES_WITH_MANIFEST.include? options[:type]
|
9
|
-
manifest = Manifest.new(options[:type])
|
9
|
+
manifest = Manifest.new(manifests_path, options[:type])
|
10
10
|
manifest.fetch(source)
|
11
11
|
else
|
12
12
|
source
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
def manifests_path
|
17
|
+
Rails.configuration.x.rails_external_asset_pipeline.manifests_path ||
|
18
|
+
File.join("public", "assets", "manifests")
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module RailsExternalAssetPipeline
|
2
2
|
class Manifest
|
3
|
-
def initialize(type)
|
3
|
+
def initialize(manifests_path, type)
|
4
|
+
@manifests_path = manifests_path
|
4
5
|
@type = type
|
5
6
|
end
|
6
7
|
|
@@ -15,21 +16,21 @@ module RailsExternalAssetPipeline
|
|
15
16
|
def parsed_manifest
|
16
17
|
JSON.parse(unparsed_manifest)
|
17
18
|
rescue JSON::ParserError
|
18
|
-
raise "The manifest file '#{
|
19
|
+
raise "The manifest file '#{manifest_path}' is invalid JSON"
|
19
20
|
end
|
20
21
|
|
21
22
|
def unparsed_manifest
|
22
|
-
File.read(
|
23
|
+
File.read(full_manifest_path)
|
23
24
|
rescue Errno::ENOENT
|
24
|
-
raise "The manifest file '#{
|
25
|
+
raise "The manifest file '#{manifest_path}' is missing"
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
-
File.join(Rails.root,
|
28
|
+
def full_manifest_path
|
29
|
+
File.join(Rails.root, manifest_path)
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
File.join(
|
32
|
+
def manifest_path
|
33
|
+
File.join(@manifests_path, "#{@type}.json")
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_external_asset_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Dohmen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.2.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.2.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.41.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 11.2.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 11.2.2
|
41
55
|
description: Instead of using the build-inn asset pipeline of Rails, some people want
|
42
56
|
to use external asset pipelines – written in Node.js for example. This gem enables
|
43
57
|
the required integration with Rails.
|