manifester 0.1.4 → 0.1.5

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: b1e937b503930933967e434a8456c8abfd1f288396645e2caa6d7b40865623cd
4
- data.tar.gz: 7d95cf05e9d381728a0ebc751163f9769f5b7aafacab4c55e96a912af6f612ce
3
+ metadata.gz: 4bf42ad927b127e72debfa126bd7c4117f7f794fcb87d61266ba1241c7fd2e26
4
+ data.tar.gz: 91c7da5020d971a9fe82e5b35d30f02015cb6920ee9638b513fad9c783b461e2
5
5
  SHA512:
6
- metadata.gz: 512c0e43eb71410ea9a48b15bd2501c94489343bbc157a9d3169297b100b4db5d877170554016bff190fc4ebbc2e5a06962c94252528dbc2e40ca754f71e6336
7
- data.tar.gz: 2114f8172d336d440c096640ec45bb2f9c5e031ac4dcdfa01b01b59a401f772247d56aa92f0daf7780df3e581ad83a766548fe7c363d4542832055f6ff16d9b2
6
+ metadata.gz: c03ae21fa18927df9bf59a83a23d1eca5508f22ed19e71c41dac582d83b09d7a3bb9bf592959e3b14c87817defcdd21a0c85010dd09b00c70fa96c72b4e768de
7
+ data.tar.gz: 8147999a1e4af9be730f39a1e54f0d1523b3902a41118850bda307a5d6fbf7396b42249a176b510c1fea7d11feca9f72b38ea12dc39c8820d7f9993bcff6867f
@@ -12,6 +12,8 @@ module Manifester
12
12
  #
13
13
  # <%= asset_manifest_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
14
14
  def asset_manifest_path(name, **options)
15
+ return asset_pack_path(name, **options) if fallback_to_webpacker?
16
+
15
17
  path_to_asset(current_manifester_instance.manifest.lookup!(name), options)
16
18
  end
17
19
 
@@ -23,6 +25,8 @@ module Manifester
23
25
  #
24
26
  # <%= asset_manifest_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
25
27
  def asset_manifest_url(name, **options)
28
+ return asset_pack_url(name, **options) if fallback_to_webpacker?
29
+
26
30
  url_to_asset(current_manifester_instance.manifest.lookup!(name), options)
27
31
  end
28
32
 
@@ -30,6 +34,8 @@ module Manifester
30
34
  # Returns the relative path using manifest.json and passes it to path_to_asset helper.
31
35
  # This will use path_to_asset internally, so most of their behaviors will be the same.
32
36
  def image_manifest_path(name, **options)
37
+ return image_pack_path(name, **options) if fallback_to_webpacker?
38
+
33
39
  resolve_path_to_image(name, **options)
34
40
  end
35
41
 
@@ -38,6 +44,8 @@ module Manifester
38
44
  # and passes it to path_to_asset helper. This will use path_to_asset internally,
39
45
  # so most of their behaviors will be the same.
40
46
  def image_manifest_url(name, **options)
47
+ return image_pack_url(name, **options) if fallback_to_webpacker?
48
+
41
49
  resolve_path_to_image(name, **options.merge(protocol: :request))
42
50
  end
43
51
 
@@ -51,6 +59,8 @@ module Manifester
51
59
  # <%= image_manifest_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
52
60
  # <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
53
61
  def image_manifest_tag(name, **options)
62
+ return image_pack_tag(name, **options) if fallback_to_webpacker?
63
+
54
64
  if options[:srcset] && !options[:srcset].is_a?(String)
55
65
  options[:srcset] = options[:srcset].map do |src_name, size|
56
66
  "#{resolve_path_to_image(src_name)} #{size}"
@@ -67,6 +77,8 @@ module Manifester
67
77
  # <%= favicon_manifest_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
68
78
  # <link href="/packs/mb-icon-k344a6d59eef8632c9d1.png" rel="apple-touch-icon" type="image/png" />
69
79
  def favicon_manifest_tag(name, **options)
80
+ return favicon_pack_tag(name, **options) if fallback_to_webpacker?
81
+
70
82
  favicon_link_tag(resolve_path_to_image(name), options)
71
83
  end
72
84
 
@@ -94,6 +106,8 @@ module Manifester
94
106
  # <%= javascript_manifest_tag 'calendar' %>
95
107
  # <%= javascript_manifest_tag 'map' %>
96
108
  def javascript_manifest_tag(*names, **options)
109
+ return javascript_pack_tag(*names, **options) if fallback_to_webpacker?
110
+
97
111
  javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
98
112
  end
99
113
 
@@ -106,6 +120,8 @@ module Manifester
106
120
  # <%= preload_manifest_asset 'fonts/fa-regular-400.woff2' %> # =>
107
121
  # <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
108
122
  def preload_manifest_asset(name, **options)
123
+ return preload_pack_asset(name, **options) if fallback_to_webpacker?
124
+
109
125
  if self.class.method_defined?(:preload_link_tag)
110
126
  preload_link_tag(current_manifester_instance.manifest.lookup!(name), options)
111
127
  else
@@ -135,6 +151,8 @@ module Manifester
135
151
  # <%= stylesheet_manifest_tag 'calendar' %>
136
152
  # <%= stylesheet_manifest_tag 'map' %>
137
153
  def stylesheet_manifest_tag(*names, **options)
154
+ return stylesheet_pack_tag(*names, **options) if fallback_to_webpacker?
155
+
138
156
  stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
139
157
  end
140
158
 
@@ -150,5 +168,9 @@ module Manifester
150
168
  rescue
151
169
  path_to_asset(current_manifester_instance.manifest.lookup!(name), options)
152
170
  end
171
+
172
+ def fallback_to_webpacker?
173
+ current_manifester_instance.config.fallback_to_webpacker?
174
+ end
153
175
  end
154
176
  end
data/lib/manifester.rb CHANGED
@@ -6,7 +6,6 @@ loader.push_dir("#{__dir__}/manifester", namespace: Manifester)
6
6
  loader.setup
7
7
 
8
8
  require "manifester/instance"
9
- require "manifester/env"
10
9
  require "manifester/configuration"
11
10
  require "manifester/manifest"
12
11
 
@@ -1,22 +1,24 @@
1
- require "yaml"
2
- require "active_support/core_ext/hash/keys"
3
- require "active_support/core_ext/hash/indifferent_access"
4
-
5
1
  class Manifester::Configuration
6
- attr_reader :root_path, :config_path, :env
2
+ attr_reader :root_path
3
+ attr_reader :public_root_dir
4
+ attr_reader :public_output_dir
5
+ attr_reader :cache_manifest
6
+ attr_reader :fallback_to_webpacker
7
7
 
8
- def initialize(root_path:, config_path:, env:)
8
+ def initialize(root_path:, public_root_dir:, public_output_dir:, cache_manifest:, fallback_to_webpacker:)
9
9
  @root_path = root_path
10
- @config_path = config_path
11
- @env = env
10
+ @public_root_dir = public_root_dir
11
+ @public_output_dir = public_output_dir
12
+ @cache_manifest = cache_manifest
13
+ @fallback_to_webpacker = fallback_to_webpacker
12
14
  end
13
15
 
14
16
  def public_path
15
- root_path.join(fetch(:public_root_path))
17
+ root_path.join(@public_root_dir)
16
18
  end
17
19
 
18
20
  def public_output_path
19
- public_path.join(fetch(:public_output_path))
21
+ public_path.join(@public_output_dir)
20
22
  end
21
23
 
22
24
  def public_manifest_path
@@ -24,34 +26,10 @@ class Manifester::Configuration
24
26
  end
25
27
 
26
28
  def cache_manifest?
27
- fetch(:cache_manifest)
29
+ @cache_manifest
28
30
  end
29
31
 
30
- private
31
- def fetch(key)
32
- data.fetch(key, defaults[key])
33
- end
34
-
35
- def data
36
- @data ||= load
37
- end
38
-
39
- def load
40
- YAML.load(config_path.read)[env].deep_symbolize_keys
41
-
42
- rescue Errno::ENOENT => e
43
- raise "Manifester configuration file not found #{config_path}. " \
44
- "Please run rails manifester:install " \
45
- "Error: #{e.message}"
46
-
47
- rescue Psych::SyntaxError => e
48
- raise "YAML syntax error occurred while parsing #{config_path}. " \
49
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
50
- "Error: #{e.message}"
51
- end
52
-
53
- def defaults
54
- @defaults ||= \
55
- HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/manifester.yml", __FILE__))[env])
56
- end
32
+ def fallback_to_webpacker?
33
+ fallback_to_webpacker.call
34
+ end
57
35
  end
@@ -1,21 +1,19 @@
1
1
  class Manifester::Instance
2
2
  cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
3
3
 
4
- attr_reader :root_path, :config_path
4
+ attr_reader :root_path
5
5
 
6
- def initialize(root_path: Rails.root, config_path: Rails.root.join("config/manifester.yml"))
7
- @root_path, @config_path = root_path, config_path
8
- end
9
-
10
- def env
11
- @env ||= Manifester::Env.inquire self
6
+ def initialize(root_path: Rails.root, public_root_dir: "public", public_output_dir: "packs", cache_manifest: false, fallback_to_webpacker: -> {})
7
+ @root_path, @public_root_dir, @public_output_dir, @cache_manifest, @fallback_to_webpacker = root_path, public_root_dir, public_output_dir, cache_manifest, fallback_to_webpacker
12
8
  end
13
9
 
14
10
  def config
15
11
  @config ||= Manifester::Configuration.new(
16
- root_path: root_path,
17
- config_path: config_path,
18
- env: env
12
+ root_path: @root_path,
13
+ public_root_dir: @public_root_dir,
14
+ public_output_dir: @public_output_dir,
15
+ cache_manifest: @cache_manifest,
16
+ fallback_to_webpacker: @fallback_to_webpacker
19
17
  )
20
18
  end
21
19
 
@@ -1,3 +1,3 @@
1
1
  module Manifester
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
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
4
+ version: 0.1.5
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-13 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -62,7 +62,6 @@ files:
62
62
  - lib/manifester.rb
63
63
  - lib/manifester/configuration.rb
64
64
  - lib/manifester/engine.rb
65
- - lib/manifester/env.rb
66
65
  - lib/manifester/instance.rb
67
66
  - lib/manifester/manifest.rb
68
67
  - lib/manifester/version.rb
@@ -1,39 +0,0 @@
1
- class Manifester::Env
2
- DEFAULT = "production".freeze
3
-
4
- delegate :config_path, :logger, to: :@manifester
5
-
6
- def self.inquire(manifester)
7
- new(manifester).inquire
8
- end
9
-
10
- def initialize(manifester)
11
- @manifester = manifester
12
- end
13
-
14
- def inquire
15
- fallback_env_warning if config_path.exist? && !current
16
- current || DEFAULT.inquiry
17
- end
18
-
19
- private
20
- def current
21
- Rails.env.presence_in(available_environments)
22
- end
23
-
24
- def fallback_env_warning
25
- logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/manifester.yml, falling back to #{DEFAULT} environment"
26
- end
27
-
28
- def available_environments
29
- if config_path.exist?
30
- YAML.load(config_path.read).keys
31
- else
32
- [].freeze
33
- end
34
- rescue Psych::SyntaxError => e
35
- raise "YAML syntax error occurred while parsing #{config_path}. " \
36
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
37
- "Error: #{e.message}"
38
- end
39
- end