manifester 0.1.2 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 970a70f2001b8db6a644a0a2838892722797a372e4864a68808b820f3b19ba47
4
- data.tar.gz: 5593f78a76fbf7555dea253fcad7397c4c8b9f664e75350fbc2e6052fe002740
3
+ metadata.gz: 29824867c809881b67054ed4b5afe7da25f2522c8942c2a97ffabc3cb77e318e
4
+ data.tar.gz: 0f7e32d8feaf9d0808b4c280ca3ea8b480b2f43ef449e6294f1c2071498df8e4
5
5
  SHA512:
6
- metadata.gz: 225a319989dd4f87be860b5924c5b1420645d57fb348624c6e5a6501c37e165822f3a3fde229e0b1b309edfa057252be1aff990db9e8f2c94a561ced062cd63c
7
- data.tar.gz: cb9a5f88e5e0c4e25c0f9a65bcdc09f3c57e136184de784c34c11d01adf4b2f078a003b2f22b0727061a801d99bce3a1a76291ac6849b5910567f4aa5005c996
6
+ metadata.gz: 43ec8577fc3597f5ee45875c6d057c8c08da99f437a817fd8239f069925e47dbca35409420a6cf0905ea3928059ed662835ac3192413d937b8723a53516269f3
7
+ data.tar.gz: b582bb945ae72312d85ac10ecd117e07faf4061511818281d13d57718e2d1e904a1e89c8c17b976cb10104ccbc8682a56917a9be56d2a9fb8721974bcb65ad4a
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Manifester
2
- Short description and motivation.
2
+ Manifester was born from the need to ship webpacker generated assets without webpacker.
3
+
4
+ When we first shipped [Avo](https://github.com/avo-hq/avo) we shipped it with the whole Webpacker pipeline. That meant rebuilding the assets on every deploy of the parent app and other nasty unwanted behaviors (conflicting pipelines, etc.).
5
+
6
+ We just needed something that would take the packed files when we and
3
7
 
4
8
  ## Usage
5
9
  How to use my plugin.
data/lib/manifester.rb CHANGED
@@ -2,8 +2,14 @@ require "zeitwerk"
2
2
  require "manifester/version"
3
3
 
4
4
  loader = Zeitwerk::Loader.for_gem
5
+ loader.push_dir("#{__dir__}/manifester", namespace: Manifester)
5
6
  loader.setup
6
7
 
8
+ require "manifester/helper"
9
+ require "manifester/instance"
10
+ require "manifester/configuration"
11
+ require "manifester/manifest"
12
+
7
13
  module Manifester
8
14
  extend self
9
15
 
@@ -16,9 +22,4 @@ module Manifester
16
22
  end
17
23
  end
18
24
 
19
- require "manifester/instance"
20
- require "manifester/env"
21
- require "manifester/configuration"
22
- require "manifester/manifest"
23
-
24
25
  require "manifester/engine" if defined?(Rails)
@@ -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,15 +1,5 @@
1
1
  module Manifester
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Manifester
4
-
5
- initializer "manifester.helper" do
6
- ActiveSupport.on_load :action_controller do
7
- ActionController::Base.helper Manifester::ApplicationHelper
8
- end
9
-
10
- ActiveSupport.on_load :action_view do
11
- include Manifester::ApplicationHelper
12
- end
13
- end
14
4
  end
15
5
  end
@@ -1,5 +1,5 @@
1
1
  module Manifester
2
- module ApplicationHelper
2
+ module Helper
3
3
  def current_manifester_instance
4
4
  Manifester.instance
5
5
  end
@@ -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,7 +106,9 @@ module Manifester
94
106
  # <%= javascript_manifest_tag 'calendar' %>
95
107
  # <%= javascript_manifest_tag 'map' %>
96
108
  def javascript_manifest_tag(*names, **options)
97
- javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
109
+ return javascript_pack_tag(*names, **options) if fallback_to_webpacker?
110
+
111
+ javascript_include_tag(*manifester_sources_from_manifest_entrypoints(names, type: :javascript), **options)
98
112
  end
99
113
 
100
114
  # Creates a link tag, for preloading, that references a given Manifester asset.
@@ -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,12 +151,14 @@ module Manifester
135
151
  # <%= stylesheet_manifest_tag 'calendar' %>
136
152
  # <%= stylesheet_manifest_tag 'map' %>
137
153
  def stylesheet_manifest_tag(*names, **options)
138
- stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
154
+ return stylesheet_pack_tag(*names, **options) if fallback_to_webpacker?
155
+
156
+ stylesheet_link_tag(*manifester_sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
139
157
  end
140
158
 
141
159
  private
142
160
 
143
- def sources_from_manifest_entrypoints(names, type:)
161
+ def manifester_sources_from_manifest_entrypoints(names, type:)
144
162
  names.map { |name| current_manifester_instance.manifest.lookup_manifest_with_chunks!(name.to_s, type: type) }.flatten.uniq
145
163
  end
146
164
 
@@ -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
@@ -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.2'
2
+ VERSION = '0.1.7'
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.2
4
+ version: 0.1.7
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
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Manifester loads stylesheets and javascript assets from your manifest.json
42
- file.
41
+ description: Manifester loads your webpacker generated javascript and stylesheets
42
+ assets from your manifest.json file.
43
43
  email:
44
44
  - adrian@adrianthedev.com
45
45
  executables: []
@@ -49,29 +49,20 @@ files:
49
49
  - MIT-LICENSE
50
50
  - README.md
51
51
  - Rakefile
52
- - app/assets/config/manifester_manifest.js
53
- - app/assets/stylesheets/manifester/application.css
54
- - app/controllers/manifester/application_controller.rb
55
- - app/helpers/manifester/application_helper.rb
56
- - app/jobs/manifester/application_job.rb
57
- - app/mailers/manifester/application_mailer.rb
58
- - app/models/manifester/application_record.rb
59
- - app/views/layouts/manifester/application.html.erb
60
- - config/routes.rb
61
52
  - lib/install/config/manifester.yml
62
53
  - lib/manifester.rb
63
54
  - lib/manifester/configuration.rb
64
55
  - lib/manifester/engine.rb
65
- - lib/manifester/env.rb
56
+ - lib/manifester/helper.rb
66
57
  - lib/manifester/instance.rb
67
58
  - lib/manifester/manifest.rb
68
59
  - lib/manifester/version.rb
69
60
  - lib/tasks/manifester_tasks.rake
70
- homepage: https://avohq.io
61
+ homepage: https://github.com/avo-hq/manifester
71
62
  licenses:
72
63
  - MIT
73
64
  metadata:
74
- homepage_uri: https://avohq.io
65
+ homepage_uri: https://github.com/avo-hq/manifester
75
66
  source_code_uri: https://github.com/avo-hq/manifester
76
67
  changelog_uri: https://github.com/avo-hq/manifester
77
68
  post_install_message:
@@ -92,6 +83,5 @@ requirements: []
92
83
  rubygems_version: 3.0.3
93
84
  signing_key:
94
85
  specification_version: 4
95
- summary: Manifester loads stylesheets and javascript assets from your manifest.json
96
- file.
86
+ summary: Manifester loads your webpacker generated assets.
97
87
  test_files: []
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/manifester .css
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,4 +0,0 @@
1
- module Manifester
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Manifester
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module Manifester
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module Manifester
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Manifester</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "manifester/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>
data/config/routes.rb DELETED
@@ -1,2 +0,0 @@
1
- Manifester::Engine.routes.draw do
2
- end
@@ -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