manifester 0.1.0 → 0.1.1
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 +4 -4
- data/app/helpers/manifester/application_helper.rb +134 -4
- data/lib/manifester.rb +7 -1
- data/lib/manifester/manifest.rb +3 -3
- data/lib/manifester/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f56198d24089e1e07ceefeb6d32815b16cb9fd4af486f35115ad723cb79da23
|
4
|
+
data.tar.gz: 5e5da6d15231011463c71fd74f5c10ad64f98c582a73a19010f8c8d8bee176e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea664adc048231d6e35d6c0589cf758e07d4c98e2b172254560ae15dbde10d3fc05704b8edde38a09251cf220e3177b419ea377763834c99a83a80b5c65490b
|
7
|
+
data.tar.gz: 8f40f946e02ab5a68954183e4102b93b8bafb32f8e181974f14e5e4419c36dbf921cbde76c7282387f876a4afc29356f881f9bba3e31379c71504af51c46b2ed
|
@@ -4,21 +4,151 @@ module Manifester
|
|
4
4
|
Manifester.instance
|
5
5
|
end
|
6
6
|
|
7
|
+
# Computes the relative path for a given Webpacker asset.
|
8
|
+
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
9
|
+
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# <%= asset_manifest_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
|
14
|
+
def asset_manifest_path(name, **options)
|
15
|
+
path_to_asset(current_manifester_instance.manifest.lookup!(name), options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Computes the absolute path for a given Webpacker asset.
|
19
|
+
# Returns the absolute path using manifest.json and passes it to url_to_asset helper.
|
20
|
+
# This will use url_to_asset internally, so most of their behaviors will be the same.
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# <%= asset_manifest_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
|
25
|
+
def asset_manifest_url(name, **options)
|
26
|
+
url_to_asset(current_manifester_instance.manifest.lookup!(name), options)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Computes the relative path for a given Webpacker image with the same automated processing as image_manifest_tag.
|
30
|
+
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
31
|
+
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
32
|
+
def image_manifest_path(name, **options)
|
33
|
+
resolve_path_to_image(name, **options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Computes the absolute path for a given Webpacker image with the same automated
|
37
|
+
# processing as image_manifest_tag. Returns the relative path using manifest.json
|
38
|
+
# and passes it to path_to_asset helper. This will use path_to_asset internally,
|
39
|
+
# so most of their behaviors will be the same.
|
40
|
+
def image_manifest_url(name, **options)
|
41
|
+
resolve_path_to_image(name, **options.merge(protocol: :request))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates an image tag that references the named pack file.
|
45
|
+
#
|
46
|
+
# Example:
|
47
|
+
#
|
48
|
+
# <%= image_manifest_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
49
|
+
# <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
|
50
|
+
#
|
51
|
+
# <%= image_manifest_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
52
|
+
# <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
|
53
|
+
def image_manifest_tag(name, **options)
|
54
|
+
if options[:srcset] && !options[:srcset].is_a?(String)
|
55
|
+
options[:srcset] = options[:srcset].map do |src_name, size|
|
56
|
+
"#{resolve_path_to_image(src_name)} #{size}"
|
57
|
+
end.join(", ")
|
58
|
+
end
|
59
|
+
|
60
|
+
image_tag(resolve_path_to_image(name), options)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Creates a link tag for a favicon that references the named pack file.
|
64
|
+
#
|
65
|
+
# Example:
|
66
|
+
#
|
67
|
+
# <%= favicon_manifest_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
|
68
|
+
# <link href="/packs/mb-icon-k344a6d59eef8632c9d1.png" rel="apple-touch-icon" type="image/png" />
|
69
|
+
def favicon_manifest_tag(name, **options)
|
70
|
+
favicon_link_tag(resolve_path_to_image(name), options)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
74
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
75
|
+
# By default, this list is auto-generated to match everything in
|
76
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
77
|
+
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
#
|
81
|
+
# <%= javascript_manifest_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
|
82
|
+
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
83
|
+
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
84
|
+
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
85
|
+
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
86
|
+
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
87
|
+
#
|
88
|
+
# DO:
|
89
|
+
#
|
90
|
+
# <%= javascript_manifest_tag 'calendar', 'map' %>
|
91
|
+
#
|
92
|
+
# DON'T:
|
93
|
+
#
|
94
|
+
# <%= javascript_manifest_tag 'calendar' %>
|
95
|
+
# <%= javascript_manifest_tag 'map' %>
|
7
96
|
def javascript_manifest_tag(*names, **options)
|
8
97
|
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
|
9
98
|
end
|
10
99
|
|
11
|
-
|
12
|
-
|
100
|
+
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
101
|
+
# In production mode, the digested reference is automatically looked up.
|
102
|
+
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
103
|
+
#
|
104
|
+
# Example:
|
105
|
+
#
|
106
|
+
# <%= preload_manifest_asset 'fonts/fa-regular-400.woff2' %> # =>
|
107
|
+
# <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
108
|
+
def preload_manifest_asset(name, **options)
|
109
|
+
if self.class.method_defined?(:preload_link_tag)
|
110
|
+
preload_link_tag(current_manifester_instance.manifest.lookup!(name), options)
|
111
|
+
else
|
112
|
+
raise "You need Rails >= 5.2 to use this tag."
|
113
|
+
end
|
13
114
|
end
|
14
115
|
|
15
|
-
|
116
|
+
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
117
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
118
|
+
# By default, this list is auto-generated to match everything in
|
119
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
120
|
+
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
121
|
+
#
|
122
|
+
# Examples:
|
123
|
+
#
|
124
|
+
# <%= stylesheet_manifest_tag 'calendar', 'map' %> # =>
|
125
|
+
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
126
|
+
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
127
|
+
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
128
|
+
#
|
129
|
+
# DO:
|
130
|
+
#
|
131
|
+
# <%= stylesheet_manifest_tag 'calendar', 'map' %>
|
132
|
+
#
|
133
|
+
# DON'T:
|
134
|
+
#
|
135
|
+
# <%= stylesheet_manifest_tag 'calendar' %>
|
136
|
+
# <%= stylesheet_manifest_tag 'map' %>
|
137
|
+
def stylesheet_manifest_tag(*names, **options)
|
138
|
+
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
16
139
|
end
|
17
140
|
|
18
141
|
private
|
19
142
|
|
20
143
|
def sources_from_manifest_entrypoints(names, type:)
|
21
|
-
names.map { |name| current_manifester_instance.manifest.
|
144
|
+
names.map { |name| current_manifester_instance.manifest.lookup_manifest_with_chunks!(name.to_s, type: type) }.flatten.uniq
|
145
|
+
end
|
146
|
+
|
147
|
+
def resolve_path_to_image(name, **options)
|
148
|
+
path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
|
149
|
+
path_to_asset(current_manifester_instance.manifest.lookup!(path), options)
|
150
|
+
rescue
|
151
|
+
path_to_asset(current_manifester_instance.manifest.lookup!(name), options)
|
22
152
|
end
|
23
153
|
end
|
24
154
|
end
|
data/lib/manifester.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "manifester/version"
|
2
|
-
require "manifester/engine"
|
3
2
|
|
4
3
|
module Manifester
|
5
4
|
extend self
|
@@ -12,3 +11,10 @@ module Manifester
|
|
12
11
|
@instance ||= Manifester::Instance.new
|
13
12
|
end
|
14
13
|
end
|
14
|
+
|
15
|
+
require "manifester/instance"
|
16
|
+
require "manifester/env"
|
17
|
+
require "manifester/configuration"
|
18
|
+
require "manifester/manifest"
|
19
|
+
|
20
|
+
require "manifester/engine" if defined?(Rails)
|
data/lib/manifester/manifest.rb
CHANGED
@@ -12,7 +12,7 @@ class Manifester::Manifest
|
|
12
12
|
@data = load
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def lookup_manifest_with_chunks(name, pack_type = {})
|
16
16
|
manifest_pack_type = manifest_type(pack_type[:type])
|
17
17
|
manifest_pack_name = manifest_name(name, manifest_pack_type)
|
18
18
|
find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type]
|
@@ -20,8 +20,8 @@ class Manifester::Manifest
|
|
20
20
|
nil
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def lookup_manifest_with_chunks!(name, pack_type = {})
|
24
|
+
lookup_manifest_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Computes the relative path for a given Manifester asset using manifest.json.
|
data/lib/manifester/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manifester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|