rails-assets-manifest 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +211 -0
- data/.travis.yml +37 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +87 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/rails-4-2.gemfile +9 -0
- data/gemfiles/rails-5-0.gemfile +9 -0
- data/gemfiles/rails-5-1.gemfile +9 -0
- data/gemfiles/rails-5-2.gemfile +9 -0
- data/gemfiles/rails-master.gemfile +9 -0
- data/lib/rails/assets/manifest.rb +35 -0
- data/lib/rails/assets/manifest/helper.rb +60 -0
- data/lib/rails/assets/manifest/manifest.rb +67 -0
- data/lib/rails/assets/manifest/railtie.rb +40 -0
- data/lib/rails/assets/manifest/version.rb +20 -0
- data/rails-assets-manifest.gemspec +35 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20fbdae0fd6c2a519e249839ea5d49d59cf397de3381b34554473a932abddc71
|
4
|
+
data.tar.gz: 40652e5ad01c108a0be622b689175c9f9a05c6b94042c88d89645e0a41881e70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44179030578e024114a95376ee277b130d4e6998d497eb96c7616a319a008d38ec33cf24dce8bd55410e3a687c0ad848ee5c20a9adfbf79b41384258d6b53311
|
7
|
+
data.tar.gz: 598b10ec984f8c488df4d3b7ed48409c06db220b2e85a86babcc7e42187e9380835f0140a57af523dd7d35848205a3c232e2721519783ac3d9343b8f69cb5720
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Exclude:
|
6
|
+
- 'bin/**'
|
7
|
+
- 'config/initializers/integration*'
|
8
|
+
- 'db/schema.rb'
|
9
|
+
- 'vendor/**'
|
10
|
+
TargetRubyVersion: 2.5
|
11
|
+
TargetRailsVersion: 5.2
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# -----------------------------------------------------------------------------
|
16
|
+
# RAILS
|
17
|
+
|
18
|
+
Rails:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
#
|
22
|
+
# False positives:
|
23
|
+
# * On Acfs::Resource#update_attriubutes!
|
24
|
+
#
|
25
|
+
Rails/ActiveRecordAliases:
|
26
|
+
Exclude:
|
27
|
+
- spec/**/*_spec.rb
|
28
|
+
|
29
|
+
#
|
30
|
+
# False positives:
|
31
|
+
# * On embedded models in migrations.
|
32
|
+
#
|
33
|
+
Rails/ApplicationRecord:
|
34
|
+
Exclude:
|
35
|
+
- 'db/**/*'
|
36
|
+
|
37
|
+
#
|
38
|
+
# Often when triggered it just wants to pass joined paths as separate
|
39
|
+
# arguments but that can hurt readability.
|
40
|
+
#
|
41
|
+
Rails/FilePath:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
#
|
45
|
+
# False positives:
|
46
|
+
# * Specs and migrations often need to update things without validations.
|
47
|
+
#
|
48
|
+
Rails/SkipsModelValidations:
|
49
|
+
Exclude:
|
50
|
+
- 'db/migrations/**.rb'
|
51
|
+
- 'spec/**/*_spec.rb'
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# -----------------------------------------------------------------------------
|
56
|
+
# RSPEC
|
57
|
+
|
58
|
+
RSpec:
|
59
|
+
Include:
|
60
|
+
- 'spec/**/*_spec.rb'
|
61
|
+
- 'spec/spec_helper.rb'
|
62
|
+
- 'spec/rails_helper.rb'
|
63
|
+
|
64
|
+
RSpec/ContextWording:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
RSpec/ExampleLength:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
RSpec/ExpectInHook:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
RSpec/FilePath:
|
74
|
+
Exclude:
|
75
|
+
- 'spec/client/**/*_spec.rb'
|
76
|
+
|
77
|
+
RSpec/MessageSpies:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
RSpec/MissingExampleGroupArgument:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
RSpec/MultipleExpectations:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
RSpec/NestedGroups:
|
87
|
+
Max: 5
|
88
|
+
|
89
|
+
# -----------------------------------------------------------------------------
|
90
|
+
# Layout
|
91
|
+
|
92
|
+
Layout/AlignParameters:
|
93
|
+
EnforcedStyle: with_fixed_indentation
|
94
|
+
|
95
|
+
Layout/CaseIndentation:
|
96
|
+
EnforcedStyle: end
|
97
|
+
SupportedStyles:
|
98
|
+
- case
|
99
|
+
- end
|
100
|
+
IndentOneStep: true
|
101
|
+
|
102
|
+
Layout/MultilineMethodCallIndentation:
|
103
|
+
EnforcedStyle: indented
|
104
|
+
|
105
|
+
Layout/SpaceInsideBlockBraces:
|
106
|
+
EnforcedStyle: space
|
107
|
+
EnforcedStyleForEmptyBraces: no_space
|
108
|
+
SpaceBeforeBlockParameters: false
|
109
|
+
|
110
|
+
Layout/SpaceInsideHashLiteralBraces:
|
111
|
+
EnforcedStyle: no_space
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
# -----------------------------------------------------------------------------
|
116
|
+
# Lint
|
117
|
+
|
118
|
+
#
|
119
|
+
# False positives:
|
120
|
+
# * expect { something }.to change { something } often triggers this
|
121
|
+
#
|
122
|
+
Lint/AmbiguousBlockAssociation:
|
123
|
+
Exclude:
|
124
|
+
- 'spec/**/*_spec.rb'
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
# -----------------------------------------------------------------------------
|
129
|
+
# Metrics
|
130
|
+
|
131
|
+
Metrics/BlockLength:
|
132
|
+
Exclude:
|
133
|
+
- 'db/**/*'
|
134
|
+
- 'spec/**/*'
|
135
|
+
- 'config/**/*'
|
136
|
+
- '**/*.rake'
|
137
|
+
|
138
|
+
Metrics/ClassLength:
|
139
|
+
Max: 200
|
140
|
+
|
141
|
+
Metrics/LineLength:
|
142
|
+
Exclude:
|
143
|
+
- 'db/**/*'
|
144
|
+
- 'spec/**/*'
|
145
|
+
- 'config/**/*'
|
146
|
+
|
147
|
+
Metrics/MethodLength:
|
148
|
+
Exclude:
|
149
|
+
- 'db/**/*'
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# -----------------------------------------------------------------------------
|
154
|
+
# Style
|
155
|
+
|
156
|
+
Style/BracesAroundHashParameters:
|
157
|
+
EnforcedStyle: context_dependent
|
158
|
+
|
159
|
+
#
|
160
|
+
# Both styles or mixtures are reasonable
|
161
|
+
#
|
162
|
+
Style/ClassAndModuleChildren:
|
163
|
+
EnforcedStyle: compact
|
164
|
+
Enabled: false
|
165
|
+
|
166
|
+
#
|
167
|
+
# Would be better but unlikely...
|
168
|
+
#
|
169
|
+
Style/Documentation:
|
170
|
+
Enabled: false
|
171
|
+
|
172
|
+
#
|
173
|
+
# Scripts might include on top-level
|
174
|
+
#
|
175
|
+
Style/MixinUsage:
|
176
|
+
Exclude:
|
177
|
+
- 'scripts/**/*'
|
178
|
+
|
179
|
+
Style/RaiseArgs:
|
180
|
+
EnforcedStyle: compact
|
181
|
+
|
182
|
+
#
|
183
|
+
# Quick single line rescues in specs
|
184
|
+
#
|
185
|
+
Style/RescueModifier:
|
186
|
+
Exclude:
|
187
|
+
- 'spec/**/*_spec.rb'
|
188
|
+
|
189
|
+
#
|
190
|
+
# Quick single line rescues in specs
|
191
|
+
#
|
192
|
+
Style/RescueStandardError:
|
193
|
+
Exclude:
|
194
|
+
- 'spec/**/*_spec.rb'
|
195
|
+
|
196
|
+
#
|
197
|
+
# Often used pattern in chaining subjects in specs
|
198
|
+
#
|
199
|
+
Style/Semicolon:
|
200
|
+
Exclude:
|
201
|
+
- 'spec/**/*_spec.rb'
|
202
|
+
|
203
|
+
Style/SignalException:
|
204
|
+
EnforcedStyle: only_raise
|
205
|
+
|
206
|
+
Style/TrailingCommaInArrayLiteral:
|
207
|
+
EnforcedStyleForMultiline: comma
|
208
|
+
|
209
|
+
Style/TrailingCommaInHashLiteral:
|
210
|
+
EnforcedStyleForMultiline: comma
|
211
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
dist: xenial
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 2.6.3
|
7
|
+
- 2.5.5
|
8
|
+
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/rails-5-2.gemfile
|
11
|
+
- gemfiles/rails-master.gemfile
|
12
|
+
|
13
|
+
before_install:
|
14
|
+
- gem update --system
|
15
|
+
- gem install bundler
|
16
|
+
|
17
|
+
script:
|
18
|
+
- bundle exec rspec spec
|
19
|
+
|
20
|
+
jobs:
|
21
|
+
allow_failures:
|
22
|
+
- gemfile: gemfiles/rails-master.gemfile
|
23
|
+
|
24
|
+
include:
|
25
|
+
- stage: Release
|
26
|
+
rvm: 2.6.3
|
27
|
+
env: []
|
28
|
+
script: skip
|
29
|
+
install: skip
|
30
|
+
deploy:
|
31
|
+
provider: rubygems
|
32
|
+
api_key:
|
33
|
+
secure: m5gUzb8J40lo4EJ2xE8XwoeHq4S3ZEDE+AyikDHzGKc5NEQQcCRoc469UlDO7fYfBHGKLh2eEe6+e/T+dyRE/C0qE/tfd6pVWf8xdyzt9+rB0zM3k7pR2Aud2hZ8NFF4bAQ28OvQ2y9pWWLVS9Bn/C0Xou951yZM+vufPVZpX7+08Aw+ZdPQrmg+v9SxsvWElm/is0CMjsHxpEy1vpyyBlF/DhNpHgd+69nupyTuZP8bg3lirZexek0xNaccNpflmrUeRwE7yofVGMfrRhvm5kOniYI+sQl/Zwru9+hK2WaSzfX/ou4ENihiLDGo5gdWeYcyLbS61yQARsRn21cN6SA0iYVuVnAruHC3uoxRh7ty1H8s3aUJnPTnnBj5cnfP9pqOyZI8zFi54CujkEFbRVLlWfGjKtCScgFBwkpXS5aB6CBplulMrX3kz/jYXFgodXLsV10WD725WGJ2Jkb52PoT5i2GyA/Ao746s7+wPIEV/l8NAurcroSHOzr9PcAUG/CwdzgidSnLfwl+qplMCGaUHtdHkPaRHqJL9j4BmcqoGVMaU0a4mAXsrlJG/drT2PMMrREKChtnQPtWg3L9HHDHBIKuXZCIQ7G9n2Dz7lpWnyKZKjJTcFyZWbbnKHLXlE1KDBUiG9qqrYbpky+IEPUt4jZ1W8hx4tKGjNlNwjU=
|
34
|
+
gem: rails-assets-manifest
|
35
|
+
on:
|
36
|
+
tags: true
|
37
|
+
repo: jgraichen/rails-assets-manifest
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
|
5
|
+
|
6
|
+
|
7
|
+
## Unreleased
|
8
|
+
---
|
9
|
+
|
10
|
+
### New
|
11
|
+
|
12
|
+
### Changes
|
13
|
+
|
14
|
+
### Fixes
|
15
|
+
|
16
|
+
### Breaks
|
17
|
+
|
18
|
+
|
19
|
+
## 1.0.0 - (2019-08-07)
|
20
|
+
---
|
21
|
+
|
22
|
+
### New
|
23
|
+
* Initial release
|
24
|
+
|
25
|
+
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jan Graichen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Rails::Assets::Manifest
|
2
|
+
|
3
|
+
Load all assets in your rails application from a `manifest.json`, e.g. generated by [webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest).
|
4
|
+
|
5
|
+
This gem does not make any assumption on which tool to use to make your assets not how to configure or invoke it. It only requires a manifest JSON. The Manifest must either be a simple string map or must map to objects having a `'src'` attribute. Subresource integrity is supported too:
|
6
|
+
|
7
|
+
```json
|
8
|
+
{
|
9
|
+
"application.css": {
|
10
|
+
"src": "2b16adf6f756625a0194.css",
|
11
|
+
"integrity": "sha384-/oreyvcV6U6htGZD0fDWR8/Txezke8KhD0QNgHb660hSaW7M+ZzxxuB4Vo+PuAC9"
|
12
|
+
},
|
13
|
+
"application.js": {
|
14
|
+
"src": "2b16adf6f756625a0194.js",
|
15
|
+
"integrity": "sha384-iJ55fQQApbQGxWEWSbWStBabi+yNGxZSQy/010+1Dhxl+rymyhGF4NtjUkOsYv7B"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
```
|
19
|
+
|
20
|
+
This gem does not add new helper methods but extends the existing helpers. SRI is automatically added if available and within a secure context:
|
21
|
+
|
22
|
+
```slim
|
23
|
+
html
|
24
|
+
head
|
25
|
+
= stylesheet_link_tag 'application', media: 'all'
|
26
|
+
= javascript_include_tag 'application'
|
27
|
+
```
|
28
|
+
|
29
|
+
```html
|
30
|
+
<link rel="stylesheet" media="all" href="2b16adf6f756625a0194.css" integrity="sha384-/oreyvcV6U6htGZD0fDWR8/Txezke8KhD0QNgHb660hSaW7M+ZzxxuB4Vo+PuAC9">
|
31
|
+
<script src="2b16adf6f756625a0194.js" integrity="sha384-iJ55fQQApbQGxWEWSbWStBabi+yNGxZSQy/010+1Dhxl+rymyhGF4NtjUkOsYv7B"></script>
|
32
|
+
```
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'rails-assets-manifest'
|
40
|
+
```
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
The manifest path can be configured e.g. in an environment:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
config.assets.manifest = "public/.asset-manifest.json"
|
48
|
+
```
|
49
|
+
|
50
|
+
If `config.cache_classes` is set to `true` the manifest file be loaded once on boot and raise errors if missing or invalid.
|
51
|
+
|
52
|
+
Assets included with `integrity: true` will raise an error if the integrity option is missing in the manifest.
|
53
|
+
|
54
|
+
## TODO
|
55
|
+
|
56
|
+
* Override/Join with `asset_host` URL?
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. [Fork it](http://github.com/jgraichen/rails-assets-manifest/fork)
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit specs for your feature so that I do not break it later
|
63
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
6. Create new Pull Request
|
66
|
+
|
67
|
+
## MIT License
|
68
|
+
|
69
|
+
Copyright (c) 2018 Jan Graichen
|
70
|
+
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
72
|
+
of this software and associated documentation files (the "Software"), to deal
|
73
|
+
in the Software without restriction, including without limitation the rights
|
74
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
75
|
+
copies of the Software, and to permit persons to whom the Software is
|
76
|
+
furnished to do so, subject to the following conditions:
|
77
|
+
|
78
|
+
The above copyright notice and this permission notice shall be included in all
|
79
|
+
copies or substantial portions of the Software.
|
80
|
+
|
81
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
82
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
83
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
84
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
85
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
86
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
87
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rails/assets/manifest'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
require 'rails/assets/manifest/version'
|
7
|
+
|
8
|
+
module Rails
|
9
|
+
module Assets
|
10
|
+
module Manifest
|
11
|
+
require 'rails/assets/manifest/manifest'
|
12
|
+
require 'rails/assets/manifest/helper'
|
13
|
+
require 'rails/assets/manifest/railtie' if defined?(Rails::Railtie)
|
14
|
+
|
15
|
+
class ManifestMissing < StandardError; end
|
16
|
+
class ManifestInvalid < StandardError; end
|
17
|
+
class EntryMissing < StandardError; end
|
18
|
+
class IntegrityMissing < StandardError; end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
delegate :lookup, :lookup!, to: :instance
|
22
|
+
|
23
|
+
def instance
|
24
|
+
@instance ||= begin
|
25
|
+
config = Rails.application.config
|
26
|
+
|
27
|
+
Manifest.new \
|
28
|
+
path: config.assets.manifest,
|
29
|
+
cache: config.cache_classes
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails::Assets::Manifest
|
4
|
+
module Helper
|
5
|
+
def compute_asset_path(name, **_kwargs)
|
6
|
+
::Rails::Assets::Manifest.lookup!(name).src
|
7
|
+
end
|
8
|
+
|
9
|
+
def asset_integrity(name, **kwargs)
|
10
|
+
::Rails::Assets::Manifest.lookup!(path_with_extname(name, **kwargs)).integrity
|
11
|
+
end
|
12
|
+
|
13
|
+
def javascript_include_tag(*sources, integrity: nil, **kwargs)
|
14
|
+
return super(*sources, **kwargs) unless compute_integrity?(integrity)
|
15
|
+
|
16
|
+
with_integrity(sources, integrity, :javascript, **kwargs) do |source, options|
|
17
|
+
super(source, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def stylesheet_link_tag(*sources, integrity: nil, **kwargs)
|
22
|
+
return super(*sources, **kwargs) unless compute_integrity?(integrity)
|
23
|
+
|
24
|
+
with_integrity(sources, integrity, :stylesheet, **kwargs) do |source, options|
|
25
|
+
super(source, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def compute_integrity?(option)
|
32
|
+
return false unless secure_subresource_integrity_context?
|
33
|
+
|
34
|
+
option || option.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_integrity(sources, required, type, **kwargs)
|
38
|
+
sources.map do |source|
|
39
|
+
integrity = asset_integrity(source, type: type, **kwargs)
|
40
|
+
|
41
|
+
if required && !integrity
|
42
|
+
raise IntegrityMissing.new <<~ERROR
|
43
|
+
SRI missing for #{path_with_extname(source, kwargs)}
|
44
|
+
ERROR
|
45
|
+
end
|
46
|
+
|
47
|
+
yield(source, integrity: integrity, **kwargs)
|
48
|
+
end.join.html_safe
|
49
|
+
end
|
50
|
+
|
51
|
+
def secure_subresource_integrity_context?
|
52
|
+
respond_to?(:request) && (request&.local? || request&.ssl?)
|
53
|
+
end
|
54
|
+
|
55
|
+
def path_with_extname(path, options)
|
56
|
+
path = path.to_s
|
57
|
+
"#{path}#{compute_asset_extname(path, options)}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails::Assets::Manifest
|
4
|
+
class Manifest
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(path:, cache: true)
|
8
|
+
@path = path.to_s.freeze
|
9
|
+
@cache = cache
|
10
|
+
|
11
|
+
data if cache?
|
12
|
+
end
|
13
|
+
|
14
|
+
def cache?
|
15
|
+
@cache
|
16
|
+
end
|
17
|
+
|
18
|
+
def lookup(name)
|
19
|
+
data[name.to_s].presence
|
20
|
+
end
|
21
|
+
|
22
|
+
def lookup!(name)
|
23
|
+
lookup(name) || begin
|
24
|
+
raise EntryMissing.new <<~ERROR
|
25
|
+
Can't find #{name} in #{path}. Your manifest contains:
|
26
|
+
#{JSON.pretty_generate(data.keys)}
|
27
|
+
ERROR
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
Entry = Struct.new(:src, :integrity) do
|
34
|
+
def integrity?
|
35
|
+
integrity.present?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
if cache?
|
41
|
+
@data ||= load
|
42
|
+
else
|
43
|
+
load
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def load
|
48
|
+
JSON.parse(File.read(path)).transform_values do |entry|
|
49
|
+
if entry.is_a?(String)
|
50
|
+
Entry.new(entry, nil)
|
51
|
+
elsif entry.is_a?(Hash)
|
52
|
+
Entry.new(entry.fetch('src'), entry['integrity'])
|
53
|
+
else
|
54
|
+
raise "Invalid entry: #{entry.inspect}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
rescue Errno::ENOENT => e
|
58
|
+
raise ManifestMissing.new <<~ERROR
|
59
|
+
Asset manifest does not exist: #{e}
|
60
|
+
ERROR
|
61
|
+
rescue => e
|
62
|
+
raise ManifestInvalid.new <<~ERROR
|
63
|
+
Asset manifest could not be loaded: #{e}
|
64
|
+
ERROR
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Assets
|
5
|
+
module Manifest
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
config.assets = ::ActiveSupport::OrderedOptions.new
|
8
|
+
config.assets.manifest = 'public/assets/manifest.json'
|
9
|
+
|
10
|
+
config.after_initialize do |_|
|
11
|
+
ActiveSupport.on_load(:action_view) do
|
12
|
+
include Helper
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer 'rails-assets-manifest' do |app|
|
17
|
+
::Rails::Assets::Manifest.instance if server?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def server?
|
23
|
+
!(console? || generator? || rake?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def console?
|
27
|
+
defined?(Rails::Console)
|
28
|
+
end
|
29
|
+
|
30
|
+
def generator?
|
31
|
+
defined?(Rails::Generators)
|
32
|
+
end
|
33
|
+
|
34
|
+
def rake?
|
35
|
+
File.basename($0) == "rake"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Assets
|
5
|
+
module Manifest
|
6
|
+
module VERSION
|
7
|
+
MAJOR = 1
|
8
|
+
MINOR = 0
|
9
|
+
PATCH = 0
|
10
|
+
STAGE = nil
|
11
|
+
|
12
|
+
STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
|
13
|
+
|
14
|
+
def self.to_s
|
15
|
+
STRING
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rails/assets/manifest/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'rails-assets-manifest'
|
9
|
+
spec.version = Rails::Assets::Manifest::VERSION
|
10
|
+
spec.authors = ['Jan Graichen']
|
11
|
+
spec.email = ['jgraichen@altimos.de']
|
12
|
+
|
13
|
+
spec.summary = 'Load all rails assets from an external manifest.'
|
14
|
+
spec.description = 'Load all rails assets from an external manifest.'
|
15
|
+
spec.homepage = 'https://github.com/jgraichen/rails-assets-manifest'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/jgraichen/rails-assets-manifest'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/jgraichen/rails-assets-manifest/blob/master/CHANGELOG.md'
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'activesupport', '> 4.2'
|
32
|
+
spec.add_dependency 'railties', '> 4.2'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-assets-manifest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Graichen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Load all rails assets from an external manifest.
|
56
|
+
email:
|
57
|
+
- jgraichen@altimos.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".editorconfig"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- gemfiles/rails-4-2.gemfile
|
75
|
+
- gemfiles/rails-5-0.gemfile
|
76
|
+
- gemfiles/rails-5-1.gemfile
|
77
|
+
- gemfiles/rails-5-2.gemfile
|
78
|
+
- gemfiles/rails-master.gemfile
|
79
|
+
- lib/rails/assets/manifest.rb
|
80
|
+
- lib/rails/assets/manifest/helper.rb
|
81
|
+
- lib/rails/assets/manifest/manifest.rb
|
82
|
+
- lib/rails/assets/manifest/railtie.rb
|
83
|
+
- lib/rails/assets/manifest/version.rb
|
84
|
+
- rails-assets-manifest.gemspec
|
85
|
+
homepage: https://github.com/jgraichen/rails-assets-manifest
|
86
|
+
licenses: []
|
87
|
+
metadata:
|
88
|
+
homepage_uri: https://github.com/jgraichen/rails-assets-manifest
|
89
|
+
source_code_uri: https://github.com/jgraichen/rails-assets-manifest
|
90
|
+
changelog_uri: https://github.com/jgraichen/rails-assets-manifest/blob/master/CHANGELOG.md
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Load all rails assets from an external manifest.
|
110
|
+
test_files: []
|