faucet_pipeline_rails 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 +150 -0
- data/Rakefile +15 -0
- data/lib/faucet_pipeline_rails/compute_asset_path.rb +25 -0
- data/lib/faucet_pipeline_rails/manifest.rb +36 -0
- data/lib/faucet_pipeline_rails/railtie.rb +9 -0
- data/lib/faucet_pipeline_rails/version.rb +3 -0
- data/lib/faucet_pipeline_rails.rb +5 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97fec74f079066619428bd49d015d7dc04e57e25
|
4
|
+
data.tar.gz: 646f3f335aad7fa900059c818801e31877e68874
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e3b46db5330ea021dfded2c0803232ce05ff4bb6c34dcd6ec156fc79a347aa68e98481ee6ad217ab306507b5da2ef2ee1e04606610f80286d1f4f18ffdbaa9f
|
7
|
+
data.tar.gz: c0494053c41fc8d4d4799ed93f37eb78f446d857f4c8a37e909db3c18c656f4a9fdab6f17161d9f59e84a6b5e117df5fba4681fed67ddec3a354c0b5a1e49ad0
|
data/README.md
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
# Use Rails with faucet-pipeline [![Build Status](https://travis-ci.org/faucet-pipeline/faucet_pipeline_rails.svg)](https://travis-ci.org/faucet-pipeline/faucet_pipeline_rails)
|
2
|
+
|
3
|
+
Instead of using the built-in asset pipeline of Rails, use
|
4
|
+
[`faucet-pipeline`](https://github.com/faucet-pipeline/faucet-pipeline). This
|
5
|
+
gem enables the required integration with Rails.
|
6
|
+
|
7
|
+
Why is an integration like that required? `faucet-pipeline` modifies the names
|
8
|
+
of the generated files depending on their content (by adding a hash of the file
|
9
|
+
to the name), Rails will not be able to find the files on its own. You still
|
10
|
+
want to be able to use the helpers you are used to like `stylesheet_link_tag`
|
11
|
+
or `image_tag`, and they should put out the correct URL for the desired asset.
|
12
|
+
This technique is referred to as *cache busting*.
|
13
|
+
|
14
|
+
So let's say you have a JavaScript file called `application.js` (for example in
|
15
|
+
`app/assets/javascripts`) and `faucet-pipeline` generates a file called
|
16
|
+
`application-03118e77692b637cfc0f55bb27fef087.js` (for example in
|
17
|
+
`public/assets/javascripts`) from that file. When you use `stylesheet_link_tag
|
18
|
+
'application'`, you expect that the resulting HTML points to the file
|
19
|
+
containing the hash in its filename. To do that, `faucet-pipeline` generates a
|
20
|
+
manifest files for each type of asset. In this case, it needs to generate a
|
21
|
+
file called `javascript.json` in `public/assets/manifests` (to change this, see
|
22
|
+
the Configuration section). The file should look like this:
|
23
|
+
|
24
|
+
```json
|
25
|
+
{
|
26
|
+
"application.js": "/assets/javascripts/application-03118e77692b637cfc0f55bb27fef087.js"
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
And that's it. This gem will take care of the rest. The resulting HTML will look like this:
|
31
|
+
|
32
|
+
```html
|
33
|
+
<!-- ... -->
|
34
|
+
<script src="/assets/javascripts/application-03118e77692b637cfc0f55bb27fef087.js" data-turbolinks-track="reload"></script>
|
35
|
+
<!-- ... -->
|
36
|
+
```
|
37
|
+
|
38
|
+
The types supported by this gem are:
|
39
|
+
|
40
|
+
* `stylesheet`
|
41
|
+
* `javascript`
|
42
|
+
* `image`
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
Add this line to your application's Gemfile:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'faucet_pipeline_rails'
|
50
|
+
```
|
51
|
+
|
52
|
+
And then execute:
|
53
|
+
|
54
|
+
```
|
55
|
+
$ bundle
|
56
|
+
```
|
57
|
+
|
58
|
+
Or install it yourself as:
|
59
|
+
|
60
|
+
```
|
61
|
+
$ gem install faucet_pipeline_rails
|
62
|
+
```
|
63
|
+
|
64
|
+
## Configuration
|
65
|
+
|
66
|
+
By default this gem assumes that your manifest files can be found in
|
67
|
+
`public/assets/manifests`. This is a nice starting point for a `faucet.config.js`:
|
68
|
+
|
69
|
+
```js
|
70
|
+
let jsConfig = {
|
71
|
+
manifest: {
|
72
|
+
file: "public/assets/manifests/javascript.json",
|
73
|
+
baseURI: (bundlePath, baseName) => `/assets/javascripts/${baseName}`
|
74
|
+
},
|
75
|
+
bundles: [{
|
76
|
+
entryPoint: "./app/assets/javascripts/application.js",
|
77
|
+
target: "public/assets/javascripts/application.js",
|
78
|
+
externals: {}
|
79
|
+
}]
|
80
|
+
};
|
81
|
+
|
82
|
+
let sassConfig = {
|
83
|
+
manifest: {
|
84
|
+
file: "public/assets/manifests/stylesheet.json",
|
85
|
+
baseURI: (bundlePath, baseName) => `/assets/stylesheets/${baseName}`
|
86
|
+
},
|
87
|
+
assets: [
|
88
|
+
"public/assets/manifests/static.json"
|
89
|
+
],
|
90
|
+
prefixes: {
|
91
|
+
browsers: [ "last 2 versions" ]
|
92
|
+
},
|
93
|
+
bundles: [{
|
94
|
+
entryPoint: "app/assets/stylesheets/application.scss",
|
95
|
+
target: "public/assets/stylesheets/application.css"
|
96
|
+
}]
|
97
|
+
};
|
98
|
+
|
99
|
+
let staticConfig = {
|
100
|
+
manifest: {
|
101
|
+
file: "public/assets/manifests/static.json",
|
102
|
+
baseURI: (bundlePath, baseName) => `/assets/static/${baseName}`
|
103
|
+
},
|
104
|
+
bundles: [{
|
105
|
+
source: "app/assets/images",
|
106
|
+
target: "public/assets/static"
|
107
|
+
}]
|
108
|
+
}
|
109
|
+
|
110
|
+
module.exports = {
|
111
|
+
js: jsConfig,
|
112
|
+
sass: sassConfig,
|
113
|
+
static: staticConfig,
|
114
|
+
watchDirs: ["app/assets"]
|
115
|
+
};
|
116
|
+
```
|
117
|
+
|
118
|
+
You can change the path to the manifest fiels that with the following
|
119
|
+
configuration:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
config.x.faucet_pipeline.manifests_path = File.join("my", "own", "manifests", "path")
|
123
|
+
```
|
124
|
+
|
125
|
+
The `manifests_path` is relative to your Rails Root.
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can
|
130
|
+
also run `bin/console` for an interactive prompt that will allow you to
|
131
|
+
experiment.
|
132
|
+
|
133
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
134
|
+
release a new version, update the version number in `version.rb`, and then run
|
135
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
136
|
+
git commits and tags, and push the `.gem` file to
|
137
|
+
[rubygems.org](https://rubygems.org).
|
138
|
+
|
139
|
+
## Contributing
|
140
|
+
|
141
|
+
Bug reports and pull requests are welcome on GitHub at
|
142
|
+
https://github.com/faucet-pipeline/faucet_pipeline_rails. This project is
|
143
|
+
intended to be a safe, welcoming space for collaboration, and contributors are
|
144
|
+
expected to adhere to the [Contributor
|
145
|
+
Covenant](http://contributor-covenant.org) code of conduct.
|
146
|
+
|
147
|
+
## License
|
148
|
+
|
149
|
+
The gem is available as open source under the terms of the [MIT
|
150
|
+
License](http://opensource.org/licenses/MIT).
|
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,25 @@
|
|
1
|
+
require "faucet_pipeline_rails/manifest"
|
2
|
+
|
3
|
+
module FaucetPipelineRails
|
4
|
+
module ComputeAssetPath
|
5
|
+
MANIFEST_FOR_TYPE = {
|
6
|
+
image: "static",
|
7
|
+
stylesheet: "stylesheet",
|
8
|
+
javascript: "javascript"
|
9
|
+
}
|
10
|
+
|
11
|
+
def compute_asset_path(source, options = {})
|
12
|
+
if MANIFEST_FOR_TYPE.has_key? options[:type]
|
13
|
+
manifest = Manifest.new(manifests_path, MANIFEST_FOR_TYPE[options[:type]])
|
14
|
+
manifest.fetch(source)
|
15
|
+
else
|
16
|
+
source
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def manifests_path
|
21
|
+
Rails.configuration.x.faucet_pipeline.manifests_path ||
|
22
|
+
File.join("public", "assets", "manifests")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FaucetPipelineRails
|
2
|
+
class Manifest
|
3
|
+
def initialize(manifests_path, type)
|
4
|
+
@manifests_path = manifests_path
|
5
|
+
@type = type
|
6
|
+
end
|
7
|
+
|
8
|
+
def fetch(asset_name)
|
9
|
+
parsed_manifest.fetch(asset_name)
|
10
|
+
rescue KeyError
|
11
|
+
raise "The asset '#{asset_name}' of type '#{@type}' was not in the manifest"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parsed_manifest
|
17
|
+
JSON.parse(unparsed_manifest)
|
18
|
+
rescue JSON::ParserError
|
19
|
+
raise "The manifest file '#{manifest_path}' is invalid JSON"
|
20
|
+
end
|
21
|
+
|
22
|
+
def unparsed_manifest
|
23
|
+
File.read(full_manifest_path)
|
24
|
+
rescue Errno::ENOENT
|
25
|
+
raise "The manifest file '#{manifest_path}' is missing"
|
26
|
+
end
|
27
|
+
|
28
|
+
def full_manifest_path
|
29
|
+
File.join(Rails.root, manifest_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def manifest_path
|
33
|
+
File.join(@manifests_path, "#{@type}.json")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faucet_pipeline_rails
|
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: 2017-11-06 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: 4.2.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.10
|
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.51.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.51.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 12.2.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.2.1
|
55
|
+
description: Instead of using the build-in asset pipeline of Rails, use faucet-pipeline.
|
56
|
+
This gem enables the required integration with Rails.
|
57
|
+
email:
|
58
|
+
- lucas.dohmen@innoq.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/faucet_pipeline_rails.rb
|
66
|
+
- lib/faucet_pipeline_rails/compute_asset_path.rb
|
67
|
+
- lib/faucet_pipeline_rails/manifest.rb
|
68
|
+
- lib/faucet_pipeline_rails/railtie.rb
|
69
|
+
- lib/faucet_pipeline_rails/version.rb
|
70
|
+
homepage: https://github.com/faucet-pipeline/faucet_pipeline_rails
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.13
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Use Rails with faucet-pipeline
|
94
|
+
test_files: []
|