rails-assets-manifest 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20fbdae0fd6c2a519e249839ea5d49d59cf397de3381b34554473a932abddc71
4
- data.tar.gz: 40652e5ad01c108a0be622b689175c9f9a05c6b94042c88d89645e0a41881e70
3
+ metadata.gz: cf7f05873e248861f8c1e82511a9a2006336acceaed1446555cc0ee9e4262228
4
+ data.tar.gz: cdfac3bf315ea70fd619c095f156b346e8f0fef8e4710db98e262ad25c080f11
5
5
  SHA512:
6
- metadata.gz: 44179030578e024114a95376ee277b130d4e6998d497eb96c7616a319a008d38ec33cf24dce8bd55410e3a687c0ad848ee5c20a9adfbf79b41384258d6b53311
7
- data.tar.gz: 598b10ec984f8c488df4d3b7ed48409c06db220b2e85a86babcc7e42187e9380835f0140a57af523dd7d35848205a3c232e2721519783ac3d9343b8f69cb5720
6
+ metadata.gz: 8ac084087c8b7315975722241c18eef100a4148f10e70fa5f23ca515d26ede428bb222cae792c2cc116abe0873633d726f4dc23807f47622e0228ffbb203f519
7
+ data.tar.gz: e915fe0abf63b0c369aca79a5199b29f2d2e25927c4fbcd75d8c87adeb9f0e5634f50662d8090de96b69b638ba657e0e7fc4ba1b5be4ca3a81aab8719a31b0ba
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
5
5
 
6
6
 
7
+
7
8
  ## Unreleased
8
9
  ---
9
10
 
@@ -16,6 +17,16 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
16
17
  ### Breaks
17
18
 
18
19
 
20
+ ## 1.1.0 - (2019-08-08)
21
+ ---
22
+
23
+ ### New
24
+ * Add passthrough option to load assets from other plugins (e.g. sprockets)
25
+
26
+ ### Changes
27
+ * Only default to add available integrity if asset is from the manifest
28
+
29
+
19
30
  ## 1.0.0 - (2019-08-07)
20
31
  ---
21
32
 
@@ -29,6 +29,10 @@ module Rails
29
29
  cache: config.cache_classes
30
30
  end
31
31
  end
32
+
33
+ def passthrough?
34
+ Rails.application.config.assets.passthrough
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -4,10 +4,16 @@ module Rails::Assets::Manifest
4
4
  module Helper
5
5
  def compute_asset_path(name, **_kwargs)
6
6
  ::Rails::Assets::Manifest.lookup!(name).src
7
+ rescue EntryMissing => e
8
+ return super if Rails::Assets::Manifest.passthrough?
9
+ raise
7
10
  end
8
11
 
9
12
  def asset_integrity(name, **kwargs)
10
13
  ::Rails::Assets::Manifest.lookup!(path_with_extname(name, **kwargs)).integrity
14
+ rescue EntryMissing => e
15
+ return super if Rails::Assets::Manifest.passthrough?
16
+ raise
11
17
  end
12
18
 
13
19
  def javascript_include_tag(*sources, integrity: nil, **kwargs)
@@ -36,15 +42,34 @@ module Rails::Assets::Manifest
36
42
 
37
43
  def with_integrity(sources, required, type, **kwargs)
38
44
  sources.map do |source|
39
- integrity = asset_integrity(source, type: type, **kwargs)
45
+ path = path_with_extname(source, type: type, **kwargs)
40
46
 
41
- if required && !integrity
42
- raise IntegrityMissing.new <<~ERROR
43
- SRI missing for #{path_with_extname(source, kwargs)}
44
- ERROR
47
+ # integrity hash passed directly
48
+ if required.is_a?(String)
49
+ next yield(source, integrity: required, **kwargs)
50
+
51
+ # Explicit passed `true` option
52
+ elsif required
53
+ integrity = asset_integrity(source, type: type, **kwargs)
54
+
55
+ if !integrity
56
+ raise IntegrityMissing.new "SRI missing for #{path}"
57
+ end
58
+
59
+ next yield(source, integrity: integrity, **kwargs)
60
+
61
+ # No integrity option passed or `nil` default from above
62
+ elsif required.nil?
63
+ entry = ::Rails::Assets::Manifest.lookup(path)
64
+
65
+ # Only if it is an asset from our manifest and there is an integrity
66
+ # we default to adding one
67
+ if(entry && entry.integrity)
68
+ next yield(source, integrity: entry.integrity, **kwargs)
69
+ end
45
70
  end
46
71
 
47
- yield(source, integrity: integrity, **kwargs)
72
+ yield(source, **kwargs)
48
73
  end.join.html_safe
49
74
  end
50
75
 
@@ -4,9 +4,20 @@ module Rails
4
4
  module Assets
5
5
  module Manifest
6
6
  class Railtie < ::Rails::Railtie
7
- config.assets = ::ActiveSupport::OrderedOptions.new
7
+ # If this plugin is used with sprockets this option
8
+ # already exists and must not be overriden. Otherwise
9
+ # all sprockets default options are removed breaking
10
+ # sprockets.
11
+ config.assets ||= ::ActiveSupport::OrderedOptions.new
12
+
13
+ # Path where the manifest file is loaded from.
8
14
  config.assets.manifest = 'public/assets/manifest.json'
9
15
 
16
+ # If set to true missing assets will not raise an
17
+ # exception but are passed through to sprockets
18
+ # or rails own asset methods.
19
+ config.assets.passthrough = false
20
+
10
21
  config.after_initialize do |_|
11
22
  ActiveSupport.on_load(:action_view) do
12
23
  include Helper
@@ -5,7 +5,7 @@ module Rails
5
5
  module Manifest
6
6
  module VERSION
7
7
  MAJOR = 1
8
- MINOR = 0
8
+ MINOR = 1
9
9
  PATCH = 0
10
10
  STAGE = nil
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-assets-manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport