rails_external_asset_pipeline 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +65 -0
- data/Rakefile +15 -0
- data/lib/rails_external_asset_pipeline.rb +5 -0
- data/lib/rails_external_asset_pipeline/compute_asset_path.rb +16 -0
- data/lib/rails_external_asset_pipeline/manifest.rb +35 -0
- data/lib/rails_external_asset_pipeline/railtie.rb +9 -0
- data/lib/rails_external_asset_pipeline/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 316fb38e35719f17288367d71ef42998d7672f25
|
4
|
+
data.tar.gz: 2562d4d3ef5d073463d87ccb6060ce79c3c03c14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77601b11f160da63a9af5b4d5f29d81666a787bc74616486bd8d00d2a53fbbda33047d38f55dafce6838b0488b9de632d22cc1c03ada291b80b037938157a401
|
7
|
+
data.tar.gz: c01ebd79a52326fa588f20073a9e2407797d3d6a28aa6be20cac91f803c32e0456e679a2f098748f8b1089309f3ae0529a58e2610d905f38f2a726f2273e6eb2
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Use Rails with an external asset pipeline [![Build Status](https://travis-ci.org/fejo-dk/rails_external_asset_pipeline.svg)](https://travis-ci.org/fejo-dk/rails_external_asset_pipeline)
|
2
|
+
|
3
|
+
Instead of using the built-in asset pipeline of Rails, some people want to use external asset pipelines – written in Node.js for example. This gem enables the required integration with Rails.
|
4
|
+
|
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
|
+
|
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`. The file should look like this:
|
8
|
+
|
9
|
+
```json
|
10
|
+
{
|
11
|
+
"application.js": "/assets/javascripts/application-03118e77692b637cfc0f55bb27fef087.js"
|
12
|
+
}
|
13
|
+
```
|
14
|
+
|
15
|
+
And that's it. This gem will take care of the rest. The resulting HTML will look like this:
|
16
|
+
|
17
|
+
```html
|
18
|
+
<!-- ... -->
|
19
|
+
<script src="/assets/javascripts/application-03118e77692b637cfc0f55bb27fef087.js" data-turbolinks-track="reload"></script>
|
20
|
+
<!-- ... -->
|
21
|
+
```
|
22
|
+
|
23
|
+
The types supported by this gem are:
|
24
|
+
|
25
|
+
* `stylesheet`
|
26
|
+
* `javascript`
|
27
|
+
* `image`
|
28
|
+
* `font`
|
29
|
+
|
30
|
+
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
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'rails_external_asset_pipeline'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
```
|
43
|
+
$ bundle
|
44
|
+
```
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
```
|
49
|
+
$ gem install rails_external_asset_pipeline
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fejo-dk/rails_external_asset_pipeline. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
65
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "lib"
|
8
|
+
t.libs << "test"
|
9
|
+
t.pattern = "test/**/*_test.rb"
|
10
|
+
t.verbose = false
|
11
|
+
end
|
12
|
+
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: [:test]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rails_external_asset_pipeline/manifest"
|
2
|
+
|
3
|
+
module RailsExternalAssetPipeline
|
4
|
+
module ComputeAssetPath
|
5
|
+
TYPES_WITH_MANIFEST = %i(stylesheet image javascript)
|
6
|
+
|
7
|
+
def compute_asset_path(source, options = {})
|
8
|
+
if TYPES_WITH_MANIFEST.include? options[:type]
|
9
|
+
manifest = Manifest.new(options[:type])
|
10
|
+
manifest.fetch(source)
|
11
|
+
else
|
12
|
+
source
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RailsExternalAssetPipeline
|
2
|
+
class Manifest
|
3
|
+
def initialize(type)
|
4
|
+
@type = type
|
5
|
+
end
|
6
|
+
|
7
|
+
def fetch(asset_name)
|
8
|
+
parsed_manifest.fetch(asset_name)
|
9
|
+
rescue KeyError
|
10
|
+
raise "The asset '#{asset_name}' of type '#{@type}' was not in the manifest"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def parsed_manifest
|
16
|
+
JSON.parse(unparsed_manifest)
|
17
|
+
rescue JSON::ParserError
|
18
|
+
raise "The manifest file '#{asset_path}' is invalid JSON"
|
19
|
+
end
|
20
|
+
|
21
|
+
def unparsed_manifest
|
22
|
+
File.read(full_asset_path)
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
raise "The manifest file '#{asset_path}' is missing"
|
25
|
+
end
|
26
|
+
|
27
|
+
def full_asset_path
|
28
|
+
File.join(Rails.root, asset_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def asset_path
|
32
|
+
File.join("public", "assets", "manifests", "#{@type}.json")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_external_asset_pipeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Dohmen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.41.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.41.2
|
41
|
+
description: Instead of using the build-inn asset pipeline of Rails, some people want
|
42
|
+
to use external asset pipelines – written in Node.js for example. This gem enables
|
43
|
+
the required integration with Rails.
|
44
|
+
email:
|
45
|
+
- lucas.dohmen@innoq.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/rails_external_asset_pipeline.rb
|
53
|
+
- lib/rails_external_asset_pipeline/compute_asset_path.rb
|
54
|
+
- lib/rails_external_asset_pipeline/manifest.rb
|
55
|
+
- lib/rails_external_asset_pipeline/railtie.rb
|
56
|
+
- lib/rails_external_asset_pipeline/version.rb
|
57
|
+
homepage: https://github.com/fejo-dk/rails_external_asset_pipeline
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.5.1
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Use Rails with an external asset pipeline
|
81
|
+
test_files: []
|