hanami-assets 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -5
- data/hanami-assets.gemspec +3 -3
- data/lib/hanami/assets.rb +11 -0
- data/lib/hanami/assets/bundler.rb +16 -10
- data/lib/hanami/assets/config/manifest.rb +21 -21
- data/lib/hanami/assets/configuration.rb +22 -21
- data/lib/hanami/assets/helpers.rb +61 -44
- data/lib/hanami/assets/precompiler.rb +1 -1
- data/lib/hanami/assets/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8e0e90a36ecac6502638dc45f8e6ccc9a125996
|
4
|
+
data.tar.gz: fb02ee2c512d39ec402912eb7068d1a58dbce6e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20709714238a4e6be95896009c24bdca8a638a4f0b09c12e52b55970da48bce30b4c372d5df9dcb527dee6a89fe0a119d30a28cc0e6c3535ca4591afefdaf9f5
|
7
|
+
data.tar.gz: 6b62752acaf443cba4740817be6f494feb5794a0d3254d193872d86dc9d1b141fd8a9c3a2171bb89c2aca34edbdb1439acd261caa0aa84e7d23bd045c65128a7
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Hanami::Assets
|
2
2
|
Assets management for Ruby web applications
|
3
3
|
|
4
|
+
## v0.4.0 - 2016-11-15
|
5
|
+
### Fixed
|
6
|
+
- [Luca Guidi] Ensure `NullManifest` to be pretty printable
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.3+ and JRuby 9.1.5.0+
|
10
|
+
- [Sean Collins] Rename digest into fingerprint
|
11
|
+
|
4
12
|
## v0.3.0 - 2016-07-22
|
5
13
|
### Added
|
6
14
|
- [Matthew Gibbons & Sean Collins] Subresource Integrity (SRI)
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Assets management for Ruby web projects
|
|
25
25
|
|
26
26
|
## Rubies
|
27
27
|
|
28
|
-
__Hanami::Assets__ supports Ruby (MRI) 2.
|
28
|
+
__Hanami::Assets__ supports Ruby (MRI) 2.3+ and JRuby 9.1.5.0+
|
29
29
|
|
30
30
|
## Installation
|
31
31
|
|
@@ -372,19 +372,19 @@ Hanami::Assets.configure do
|
|
372
372
|
end
|
373
373
|
```
|
374
374
|
|
375
|
-
###
|
375
|
+
### Fingerprint Mode
|
376
376
|
|
377
377
|
This is a mode that can be activated via configuration and it's suitable for production environments.
|
378
|
-
When generating files, it adds a string to the end of each file name, which is a
|
378
|
+
When generating files, it adds a string to the end of each file name, which is a [checksum](https://en.wikipedia.org/wiki/Checksum) of its contents.
|
379
379
|
This lets you leverage caching while still ensuring that clients get the most up-to-date assets (this is known as *cache busting*).
|
380
380
|
|
381
381
|
```ruby
|
382
382
|
Hanami::Assets.configure do
|
383
|
-
|
383
|
+
fingerprint true
|
384
384
|
end
|
385
385
|
```
|
386
386
|
|
387
|
-
Once turned on, it will look at `/public/assets.json`, and helpers such as `javascript` will return a relative URL that includes the
|
387
|
+
Once turned on, it will look at `/public/assets.json`, and helpers such as `javascript` will return a relative URL that includes the fingerprint of the asset.
|
388
388
|
|
389
389
|
```erb
|
390
390
|
<%= javascript 'application' %>
|
data/hanami-assets.gemspec
CHANGED
@@ -17,10 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
|
-
spec.required_ruby_version = '>= 2.
|
20
|
+
spec.required_ruby_version = '>= 2.3.0'
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'hanami-utils', '~> 0.
|
23
|
-
spec.add_runtime_dependency 'hanami-helpers', '~> 0.
|
22
|
+
spec.add_runtime_dependency 'hanami-utils', '~> 0.9'
|
23
|
+
spec.add_runtime_dependency 'hanami-helpers', '~> 0.5'
|
24
24
|
spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.2'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
data/lib/hanami/assets.rb
CHANGED
@@ -53,6 +53,17 @@ module Hanami
|
|
53
53
|
Bundler.new(configuration, duplicates).run
|
54
54
|
end
|
55
55
|
|
56
|
+
# Precompile assets
|
57
|
+
#
|
58
|
+
# @since 0.4.0
|
59
|
+
def self.precompile(configurations)
|
60
|
+
require 'hanami/assets/precompiler'
|
61
|
+
require 'hanami/assets/bundler'
|
62
|
+
|
63
|
+
Precompiler.new(configuration, configurations).run
|
64
|
+
Bundler.new(configuration, configurations).run
|
65
|
+
end
|
66
|
+
|
56
67
|
# Preload the framework
|
57
68
|
#
|
58
69
|
# This MUST be used in production mode
|
@@ -38,11 +38,7 @@ module Hanami
|
|
38
38
|
def initialize(configuration, duplicates)
|
39
39
|
@manifest = Hash[]
|
40
40
|
@configuration = configuration
|
41
|
-
@
|
42
|
-
[@configuration]
|
43
|
-
else
|
44
|
-
duplicates.map(&:configuration)
|
45
|
-
end
|
41
|
+
@duplicates = duplicates
|
46
42
|
end
|
47
43
|
|
48
44
|
# Start the process.
|
@@ -50,12 +46,12 @@ module Hanami
|
|
50
46
|
# For each asset contained in the sources and third party gems, it will:
|
51
47
|
#
|
52
48
|
# * Compress
|
53
|
-
# * Create a
|
54
|
-
# * Generate
|
49
|
+
# * Create a fingerprinted version of the file
|
50
|
+
# * Generate a subresource integrity digest
|
55
51
|
#
|
56
|
-
# At the end it will generate a
|
52
|
+
# At the end it will generate a manifest
|
57
53
|
#
|
58
|
-
# @see Hanami::Assets::Configuration#
|
54
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
59
55
|
# @see Hanami::Assets::Configuration#manifest
|
60
56
|
# @see Hanami::Assets::Configuration#manifest_path
|
61
57
|
def run
|
@@ -132,7 +128,7 @@ module Hanami
|
|
132
128
|
def _configuration_for(asset)
|
133
129
|
url = _convert_to_url(asset)
|
134
130
|
|
135
|
-
|
131
|
+
configurations.find { |config| url.start_with?(config.prefix) } ||
|
136
132
|
@configuration
|
137
133
|
end
|
138
134
|
|
@@ -141,6 +137,16 @@ module Hanami
|
|
141
137
|
def public_directory
|
142
138
|
@configuration.public_directory
|
143
139
|
end
|
140
|
+
|
141
|
+
# @since 0.4.0
|
142
|
+
# @api private
|
143
|
+
def configurations
|
144
|
+
if @duplicates.empty?
|
145
|
+
[@configuration]
|
146
|
+
else
|
147
|
+
@duplicates.map { |dup| dup.respond_to?(:configuration) ? dup.configuration : dup }
|
148
|
+
end
|
149
|
+
end
|
144
150
|
end
|
145
151
|
end
|
146
152
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module Hanami
|
2
2
|
module Assets
|
3
3
|
# This error is raised when the application starts but can't be load the
|
4
|
-
#
|
4
|
+
# manifest file.
|
5
5
|
#
|
6
6
|
# @since 0.1.0
|
7
7
|
# @api private
|
8
|
-
class
|
8
|
+
class MissingManifestFileError < Error
|
9
9
|
def initialize(path)
|
10
10
|
super("Can't read manifest: #{path}")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
# This error is raised when an asset is referenced from the DOM, but it's
|
15
|
-
# not present in the
|
15
|
+
# not present in the manifest
|
16
16
|
#
|
17
17
|
# @since 0.1.0
|
18
18
|
# @api private
|
19
|
-
class
|
19
|
+
class MissingManifestAssetError < Error
|
20
20
|
def initialize(asset, manifest_path)
|
21
21
|
super("Can't find asset `#{asset}' in manifest (#{manifest_path})")
|
22
22
|
end
|
@@ -27,29 +27,29 @@ module Hanami
|
|
27
27
|
# @since 0.1.0
|
28
28
|
# @api private
|
29
29
|
module Config
|
30
|
-
# Default value for configuration's
|
30
|
+
# Default value for configuration's manifest.
|
31
31
|
#
|
32
|
-
# It indicates that the
|
32
|
+
# It indicates that the manifest wasn't loaded yet.
|
33
33
|
#
|
34
34
|
# At the load time, this should be replaced by an instance of
|
35
35
|
# <tt>Hanami::Assets::Config::Manifest</tt>.
|
36
36
|
#
|
37
37
|
# If for some reason that won't happen, the instance of this class is
|
38
38
|
# still referenced by the configuration and all the method invocations
|
39
|
-
# will raise a <tt>Hanami::Assets::
|
39
|
+
# will raise a <tt>Hanami::Assets::MissingManifestFileError</tt>.
|
40
40
|
#
|
41
41
|
# @since 0.1.0
|
42
42
|
# @api private
|
43
43
|
#
|
44
44
|
# @see Hanami::Assets::Configuration#manifest
|
45
45
|
# @see Hanami::Assets::Configuration#manifest_path
|
46
|
-
# @see Hanami::Assets::Configuration#
|
47
|
-
class
|
46
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
47
|
+
class NullManifest < Utils::BasicObject
|
48
48
|
# Return a new instance
|
49
49
|
#
|
50
50
|
# @param configuration [Hanami::Assets::Configuration]
|
51
51
|
#
|
52
|
-
# @return [Hanami::Assets::Config::
|
52
|
+
# @return [Hanami::Assets::Config::NullManifest] a new instance
|
53
53
|
#
|
54
54
|
# @since 0.1.0
|
55
55
|
# @api private
|
@@ -57,23 +57,23 @@ module Hanami
|
|
57
57
|
@configuration = configuration
|
58
58
|
end
|
59
59
|
|
60
|
-
# @raise [Hanami::Assets::
|
60
|
+
# @raise [Hanami::Assets::MissingManifestFileError]
|
61
61
|
#
|
62
62
|
# @since 0.1.0
|
63
63
|
# @api private
|
64
64
|
def method_missing(*)
|
65
65
|
::Kernel.raise(
|
66
|
-
::Hanami::Assets::
|
66
|
+
::Hanami::Assets::MissingManifestFileError.new(@configuration.manifest_path)
|
67
67
|
)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
#
|
71
|
+
# Manifest file
|
72
72
|
#
|
73
73
|
# @since 0.1.0
|
74
74
|
# @api private
|
75
|
-
class
|
76
|
-
# @since 0.
|
75
|
+
class Manifest
|
76
|
+
# @since 0.4.0
|
77
77
|
# @api private
|
78
78
|
TARGET = 'target'.freeze
|
79
79
|
|
@@ -83,8 +83,8 @@ module Hanami
|
|
83
83
|
|
84
84
|
# Return a new instance
|
85
85
|
#
|
86
|
-
# @param assets [Hash] the content of the
|
87
|
-
# @param manifest_path [Pathname] the path to the
|
86
|
+
# @param assets [Hash] the content of the manifest
|
87
|
+
# @param manifest_path [Pathname] the path to the manifest
|
88
88
|
#
|
89
89
|
# @return [Hanami::Assets::Config::Manifest] a new instance
|
90
90
|
#
|
@@ -98,20 +98,20 @@ module Hanami
|
|
98
98
|
@manifest_path = manifest_path
|
99
99
|
end
|
100
100
|
|
101
|
-
# Resolve the given asset into a
|
101
|
+
# Resolve the given asset into a fingerprinted path
|
102
102
|
#
|
103
103
|
# For a given path <tt>/assets/application.js</tt> it will return
|
104
104
|
# <tt>/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js</tt>
|
105
105
|
#
|
106
106
|
# @param asset [#to_s] the relative asset path
|
107
107
|
#
|
108
|
-
# @return [String] the
|
108
|
+
# @return [String] the fingerprinted path
|
109
109
|
#
|
110
|
-
# @raise [Hanami::Assets::
|
110
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] when the asset can't be
|
111
111
|
# found in manifest
|
112
112
|
def resolve(asset)
|
113
113
|
@assets.fetch(asset.to_s) do
|
114
|
-
raise Hanami::Assets::
|
114
|
+
raise Hanami::Assets::MissingManifestAssetError.new(asset, @manifest_path)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -86,9 +86,9 @@ module Hanami
|
|
86
86
|
framework.configuration
|
87
87
|
end
|
88
88
|
|
89
|
-
# @since 0.
|
89
|
+
# @since 0.4.0
|
90
90
|
# @api private
|
91
|
-
attr_reader :
|
91
|
+
attr_reader :public_manifest
|
92
92
|
|
93
93
|
# Return a new instance
|
94
94
|
#
|
@@ -96,8 +96,9 @@ module Hanami
|
|
96
96
|
#
|
97
97
|
# @since 0.1.0
|
98
98
|
# @api private
|
99
|
-
def initialize
|
99
|
+
def initialize(&blk)
|
100
100
|
reset!
|
101
|
+
instance_eval(&blk) if block_given?
|
101
102
|
end
|
102
103
|
|
103
104
|
# Compile mode
|
@@ -114,17 +115,17 @@ module Hanami
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
|
-
#
|
118
|
+
# Fingerprint mode
|
118
119
|
#
|
119
|
-
# Determine if the helpers should generate the
|
120
|
+
# Determine if the helpers should generate the fingerprinted path for an asset.
|
120
121
|
# Usually this is turned on in production mode.
|
121
122
|
#
|
122
123
|
# @since 0.1.0
|
123
|
-
def
|
124
|
+
def fingerprint(value = nil)
|
124
125
|
if value.nil?
|
125
|
-
@
|
126
|
+
@fingerprint
|
126
127
|
else
|
127
|
-
@
|
128
|
+
@fingerprint = value
|
128
129
|
end
|
129
130
|
end
|
130
131
|
|
@@ -411,8 +412,8 @@ module Hanami
|
|
411
412
|
"#{@base_url}#{compile_path(source)}"
|
412
413
|
end
|
413
414
|
|
414
|
-
# An array of
|
415
|
-
# integrity checks
|
415
|
+
# An array of crypographically secure hashing algorithms to use for
|
416
|
+
# generating asset subresource integrity checks
|
416
417
|
#
|
417
418
|
# @since 0.3.0
|
418
419
|
def subresource_integrity_algorithms
|
@@ -430,11 +431,11 @@ module Hanami
|
|
430
431
|
# @since 0.3.0
|
431
432
|
# @api private
|
432
433
|
def subresource_integrity_value(source)
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
434
|
+
return unless subresource_integrity
|
435
|
+
|
436
|
+
public_manifest.subresource_integrity_values(
|
437
|
+
prefix.join(source)
|
438
|
+
).join(SUBRESOURCE_INTEGRITY_SEPARATOR)
|
438
439
|
end
|
439
440
|
|
440
441
|
# Load Javascript compressor
|
@@ -501,11 +502,11 @@ module Hanami
|
|
501
502
|
@prefix = Utils::PathPrefix.new(DEFAULT_PREFIX)
|
502
503
|
@subresource_integrity = false
|
503
504
|
@cdn = false
|
504
|
-
@
|
505
|
+
@fingerprint = false
|
505
506
|
@compile = false
|
506
507
|
@base_url = nil
|
507
508
|
@destination_directory = nil
|
508
|
-
@
|
509
|
+
@public_manifest = Config::NullManifest.new(self)
|
509
510
|
|
510
511
|
@javascript_compressor = nil
|
511
512
|
@stylesheet_compressor = nil
|
@@ -521,9 +522,9 @@ module Hanami
|
|
521
522
|
#
|
522
523
|
# @since 0.1.0
|
523
524
|
def load!
|
524
|
-
if (
|
525
|
-
@
|
526
|
-
JSON.
|
525
|
+
if (fingerprint || subresource_integrity) && manifest_path.exist?
|
526
|
+
@public_manifest = Config::Manifest.new(
|
527
|
+
JSON.parse(manifest_path.read),
|
527
528
|
manifest_path
|
528
529
|
)
|
529
530
|
end
|
@@ -591,7 +592,7 @@ module Hanami
|
|
591
592
|
# @api private
|
592
593
|
def compile_path(source)
|
593
594
|
result = prefix.join(source)
|
594
|
-
result =
|
595
|
+
result = public_manifest.target(result) if fingerprint
|
595
596
|
result.to_s
|
596
597
|
end
|
597
598
|
|
@@ -84,22 +84,27 @@ module Hanami
|
|
84
84
|
# comes from the application or third party gems. It also accepts strings
|
85
85
|
# representing absolute URLs in case of public CDN (eg. jQuery CDN).
|
86
86
|
#
|
87
|
-
# If the "
|
88
|
-
# relative URL.
|
87
|
+
# If the "fingerprint mode" is on, <tt>src</tt> is the fingerprinted
|
88
|
+
# version of the relative URL.
|
89
89
|
#
|
90
90
|
# If the "CDN mode" is on, the <tt>src</tt> is an absolute URL of the
|
91
91
|
# application CDN.
|
92
92
|
#
|
93
|
+
# If the "subresource integrity mode" is on, <tt>integriy</tt> is the
|
94
|
+
# name of the algorithm, then a hyphen, then the hash value of the file.
|
95
|
+
# If more than one algorithm is used, they'll be separated by a space.
|
96
|
+
#
|
93
97
|
# @param sources [Array<String>] one or more assets by name or absolute URL
|
94
98
|
#
|
95
99
|
# @return [Hanami::Utils::Escape::SafeString] the markup
|
96
100
|
#
|
97
|
-
# @raise [Hanami::Assets::
|
98
|
-
#
|
101
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
102
|
+
# `subresource_integrity` modes are on and the javascript file is missing
|
103
|
+
# from the manifest
|
99
104
|
#
|
100
105
|
# @since 0.1.0
|
101
106
|
#
|
102
|
-
# @see Hanami::Assets::Configuration#
|
107
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
103
108
|
# @see Hanami::Assets::Configuration#cdn
|
104
109
|
# @see Hanami::Assets::Helpers#asset_path
|
105
110
|
#
|
@@ -146,7 +151,7 @@ module Hanami
|
|
146
151
|
#
|
147
152
|
# # <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
|
148
153
|
#
|
149
|
-
# @example
|
154
|
+
# @example Fingerprint Mode
|
150
155
|
#
|
151
156
|
# <%= javascript 'application' %>
|
152
157
|
#
|
@@ -178,23 +183,28 @@ module Hanami
|
|
178
183
|
# comes from the application or third party gems. It also accepts strings
|
179
184
|
# representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
|
180
185
|
#
|
181
|
-
# If the "
|
182
|
-
# relative URL.
|
186
|
+
# If the "fingerprint mode" is on, <tt>href</tt> is the fingerprinted
|
187
|
+
# version of the relative URL.
|
183
188
|
#
|
184
189
|
# If the "CDN mode" is on, the <tt>href</tt> is an absolute URL of the
|
185
190
|
# application CDN.
|
186
191
|
#
|
192
|
+
# If the "subresource integrity mode" is on, <tt>integriy</tt> is the
|
193
|
+
# name of the algorithm, then a hyphen, then the hashed value of the file.
|
194
|
+
# If more than one algorithm is used, they'll be separated by a space.
|
187
195
|
# @param sources [Array<String>] one or more assets by name or absolute URL
|
188
196
|
#
|
189
197
|
# @return [Hanami::Utils::Escape::SafeString] the markup
|
190
198
|
#
|
191
|
-
# @raise [Hanami::Assets::
|
192
|
-
#
|
199
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
200
|
+
# `subresource_integrity` modes are on and the stylesheet file is missing
|
201
|
+
# from the manifest
|
193
202
|
#
|
194
203
|
# @since 0.1.0
|
195
204
|
#
|
196
|
-
# @see Hanami::Assets::Configuration#
|
205
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
197
206
|
# @see Hanami::Assets::Configuration#cdn
|
207
|
+
# @see Hanami::Assets::Configuration#subresource_integrity
|
198
208
|
# @see Hanami::Assets::Helpers#asset_path
|
199
209
|
#
|
200
210
|
# @example Single Asset
|
@@ -228,7 +238,7 @@ module Hanami
|
|
228
238
|
#
|
229
239
|
# # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" rel="stylesheet">
|
230
240
|
#
|
231
|
-
# @example
|
241
|
+
# @example Fingerprint Mode
|
232
242
|
#
|
233
243
|
# <%= stylesheet 'application' %>
|
234
244
|
#
|
@@ -264,8 +274,8 @@ module Hanami
|
|
264
274
|
# <tt>alt</tt> Attribute is auto generated from <tt>src</tt>.
|
265
275
|
# You can specify a different value, by passing the <tt>:src</tt> option.
|
266
276
|
#
|
267
|
-
# If the "
|
268
|
-
# relative URL.
|
277
|
+
# If the "fingerprint mode" is on, <tt>src</tt> is the fingerprinted
|
278
|
+
# version of the relative URL.
|
269
279
|
#
|
270
280
|
# If the "CDN mode" is on, the <tt>src</tt> is an absolute URL of the
|
271
281
|
# application CDN.
|
@@ -274,13 +284,15 @@ module Hanami
|
|
274
284
|
#
|
275
285
|
# @return [Hanami::Utils::Helpers::HtmlBuilder] the builder
|
276
286
|
#
|
277
|
-
# @raise [Hanami::Assets::
|
278
|
-
#
|
287
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
288
|
+
# `subresource_integrity` modes are on and the image file is missing
|
289
|
+
# from the manifest
|
279
290
|
#
|
280
291
|
# @since 0.1.0
|
281
292
|
#
|
282
|
-
# @see Hanami::Assets::Configuration#
|
293
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
283
294
|
# @see Hanami::Assets::Configuration#cdn
|
295
|
+
# @see Hanami::Assets::Configuration#subresource_integrity
|
284
296
|
# @see Hanami::Assets::Helpers#asset_path
|
285
297
|
#
|
286
298
|
# @example Basic Usage
|
@@ -307,7 +319,7 @@ module Hanami
|
|
307
319
|
#
|
308
320
|
# # <img src="https://example-cdn.com/images/logo.png" alt="Logo">
|
309
321
|
#
|
310
|
-
# @example
|
322
|
+
# @example Fingerprint Mode
|
311
323
|
#
|
312
324
|
# <%= image 'logo.png' %>
|
313
325
|
#
|
@@ -331,8 +343,8 @@ module Hanami
|
|
331
343
|
#
|
332
344
|
# It accepts one string representing the name of the asset.
|
333
345
|
#
|
334
|
-
# If the "
|
335
|
-
# relative URL.
|
346
|
+
# If the "fingerprint mode" is on, <tt>href</tt> is the fingerprinted version
|
347
|
+
# of the relative URL.
|
336
348
|
#
|
337
349
|
# If the "CDN mode" is on, the <tt>href</tt> is an absolute URL of the
|
338
350
|
# application CDN.
|
@@ -341,12 +353,13 @@ module Hanami
|
|
341
353
|
#
|
342
354
|
# @return [Hanami::Utils::Helpers::HtmlBuilder] the builder
|
343
355
|
#
|
344
|
-
# @raise [Hanami::Assets::
|
345
|
-
#
|
356
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
357
|
+
# `subresource_integrity` modes are on and the favicon is file missing
|
358
|
+
# from the manifest
|
346
359
|
#
|
347
360
|
# @since 0.1.0
|
348
361
|
#
|
349
|
-
# @see Hanami::Assets::Configuration#
|
362
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
350
363
|
# @see Hanami::Assets::Configuration#cdn
|
351
364
|
# @see Hanami::Assets::Helpers#asset_path
|
352
365
|
#
|
@@ -368,7 +381,7 @@ module Hanami
|
|
368
381
|
#
|
369
382
|
# # <link id: "fav" href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">
|
370
383
|
#
|
371
|
-
# @example
|
384
|
+
# @example Fingerprint Mode
|
372
385
|
#
|
373
386
|
# <%= favicon %>
|
374
387
|
#
|
@@ -396,8 +409,8 @@ module Hanami
|
|
396
409
|
# Alternatively, it accepts a block that allows to specify one or more
|
397
410
|
# sources via the <tt>source</tt> tag.
|
398
411
|
#
|
399
|
-
# If the "
|
400
|
-
# relative URL.
|
412
|
+
# If the "fingerprint mode" is on, <tt>src</tt> is the fingerprinted
|
413
|
+
# version of the relative URL.
|
401
414
|
#
|
402
415
|
# If the "CDN mode" is on, the <tt>src</tt> is an absolute URL of the
|
403
416
|
# application CDN.
|
@@ -406,15 +419,16 @@ module Hanami
|
|
406
419
|
#
|
407
420
|
# @return [Hanami::Utils::Helpers::HtmlBuilder] the builder
|
408
421
|
#
|
409
|
-
# @raise [Hanami::Assets::
|
410
|
-
#
|
422
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
423
|
+
# `subresource_integrity` modes are on and the video file is missing
|
424
|
+
# from the manifest
|
411
425
|
#
|
412
426
|
# @raise [ArgumentError] if source isn't specified both as argument or
|
413
427
|
# tag inside the given block
|
414
428
|
#
|
415
429
|
# @since 0.1.0
|
416
430
|
#
|
417
|
-
# @see Hanami::Assets::Configuration#
|
431
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
418
432
|
# @see Hanami::Assets::Configuration#cdn
|
419
433
|
# @see Hanami::Assets::Helpers#asset_path
|
420
434
|
#
|
@@ -489,7 +503,7 @@ module Hanami
|
|
489
503
|
#
|
490
504
|
# # ArgumentError
|
491
505
|
#
|
492
|
-
# @example
|
506
|
+
# @example Fingerprint Mode
|
493
507
|
#
|
494
508
|
# <%= video 'movie.mp4' %>
|
495
509
|
#
|
@@ -514,8 +528,8 @@ module Hanami
|
|
514
528
|
# Alternatively, it accepts a block that allows to specify one or more
|
515
529
|
# sources via the <tt>source</tt> tag.
|
516
530
|
#
|
517
|
-
# If the "
|
518
|
-
# relative URL.
|
531
|
+
# If the "fingerprint mode" is on, <tt>src</tt> is the fingerprinted
|
532
|
+
# version of the relative URL.
|
519
533
|
#
|
520
534
|
# If the "CDN mode" is on, the <tt>src</tt> is an absolute URL of the
|
521
535
|
# application CDN.
|
@@ -524,15 +538,16 @@ module Hanami
|
|
524
538
|
#
|
525
539
|
# @return [Hanami::Utils::Helpers::HtmlBuilder] the builder
|
526
540
|
#
|
527
|
-
# @raise [Hanami::Assets::
|
528
|
-
#
|
541
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
542
|
+
# `subresource_integrity` modes are on and the audio file is missing
|
543
|
+
# from the manifest
|
529
544
|
#
|
530
545
|
# @raise [ArgumentError] if source isn't specified both as argument or
|
531
546
|
# tag inside the given block
|
532
547
|
#
|
533
548
|
# @since 0.1.0
|
534
549
|
#
|
535
|
-
# @see Hanami::Assets::Configuration#
|
550
|
+
# @see Hanami::Assets::Configuration#fingerprint
|
536
551
|
# @see Hanami::Assets::Configuration#cdn
|
537
552
|
# @see Hanami::Assets::Helpers#asset_path
|
538
553
|
#
|
@@ -607,7 +622,7 @@ module Hanami
|
|
607
622
|
#
|
608
623
|
# # ArgumentError
|
609
624
|
#
|
610
|
-
# @example
|
625
|
+
# @example Fingerprint Mode
|
611
626
|
#
|
612
627
|
# <%= audio 'song.ogg' %>
|
613
628
|
#
|
@@ -630,7 +645,7 @@ module Hanami
|
|
630
645
|
#
|
631
646
|
# Absolute URLs are returned as they are.
|
632
647
|
#
|
633
|
-
# If
|
648
|
+
# If Fingerprint mode is on, it returns the fingerprinted path of the source
|
634
649
|
#
|
635
650
|
# If CDN mode is on, it returns the absolute URL of the asset.
|
636
651
|
#
|
@@ -638,8 +653,9 @@ module Hanami
|
|
638
653
|
#
|
639
654
|
# @return [String] the asset path
|
640
655
|
#
|
641
|
-
# @raise [Hanami::Assets::
|
642
|
-
#
|
656
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
657
|
+
# `subresource_integrity` modes are on and the asset is missing
|
658
|
+
# from the manifest
|
643
659
|
#
|
644
660
|
# @since 0.1.0
|
645
661
|
#
|
@@ -655,7 +671,7 @@ module Hanami
|
|
655
671
|
#
|
656
672
|
# # "https://code.jquery.com/jquery-2.1.4.min.js"
|
657
673
|
#
|
658
|
-
# @example
|
674
|
+
# @example Fingerprint Mode
|
659
675
|
#
|
660
676
|
# <%= asset_path 'application.js' %>
|
661
677
|
#
|
@@ -677,7 +693,7 @@ module Hanami
|
|
677
693
|
#
|
678
694
|
# Absolute URLs are returned as they are.
|
679
695
|
#
|
680
|
-
# If
|
696
|
+
# If Fingerprint mode is on, it returns the fingerprint URL of the source
|
681
697
|
#
|
682
698
|
# If CDN mode is on, it returns the absolute URL of the asset.
|
683
699
|
#
|
@@ -685,8 +701,9 @@ module Hanami
|
|
685
701
|
#
|
686
702
|
# @return [String] the asset URL
|
687
703
|
#
|
688
|
-
# @raise [Hanami::Assets::
|
689
|
-
#
|
704
|
+
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
|
705
|
+
# `subresource_integrity` modes are on and the asset is missing
|
706
|
+
# from the manifest
|
690
707
|
#
|
691
708
|
# @since 0.1.0
|
692
709
|
#
|
@@ -702,7 +719,7 @@ module Hanami
|
|
702
719
|
#
|
703
720
|
# # "https://code.jquery.com/jquery-2.1.4.min.js"
|
704
721
|
#
|
705
|
-
# @example
|
722
|
+
# @example Fingerprint Mode
|
706
723
|
#
|
707
724
|
# <%= asset_url 'application.js' %>
|
708
725
|
#
|
@@ -47,7 +47,7 @@ module Hanami
|
|
47
47
|
# @since 0.3.0
|
48
48
|
# @api private
|
49
49
|
def clear_manifest(manifest)
|
50
|
-
JSON.
|
50
|
+
JSON.parse(manifest).each do |_, asset_hash|
|
51
51
|
asset_file_name = @configuration.public_directory.join(asset_hash['target'])
|
52
52
|
asset_file_name.unlink if asset_file_name.exist?
|
53
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hanami-utils
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
21
|
+
version: '0.9'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0.
|
28
|
+
version: '0.9'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: hanami-helpers
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '0.
|
35
|
+
version: '0.5'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
42
|
+
version: '0.5'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: tilt
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -241,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
241
|
requirements:
|
242
242
|
- - ">="
|
243
243
|
- !ruby/object:Gem::Version
|
244
|
-
version: 2.
|
244
|
+
version: 2.3.0
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
246
|
requirements:
|
247
247
|
- - ">="
|