Class: Shakapacker::Manifest
- Inherits:
-
Object
- Object
- Shakapacker::Manifest
- Defined in:
- lib/shakapacker/manifest.rb
Overview
Singleton registry for accessing the packs path using a generated manifest. This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to, say, “calendar.js” or “calendar.css” and turn it into “/packs/calendar-1016838bab065ae1e314.js” or “/packs/calendar-1016838bab065ae1e314.css”.
When the configuration is set to on-demand compilation, with the ‘compile: true` option in the shakapacker.yml file, any lookups will be preceded by a compilation if one is needed.
Defined Under Namespace
Classes: MissingEntryError
Instance Method Summary collapse
-
#initialize(instance) ⇒ Manifest
constructor
A new instance of Manifest.
-
#lookup(name, pack_type = {}) ⇒ Object
Computes the relative path for a given Shakapacker asset using manifest.json.
-
#lookup!(name, pack_type = {}) ⇒ Object
Like lookup, except that if no asset is found, raises a Shakapacker::Manifest::MissingEntryError.
- #lookup_pack_with_chunks(name, pack_type = {}) ⇒ Object
- #lookup_pack_with_chunks!(name, pack_type = {}) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(instance) ⇒ Manifest
Returns a new instance of Manifest.
13 14 15 |
# File 'lib/shakapacker/manifest.rb', line 13 def initialize(instance) @instance = instance end |
Instance Method Details
#lookup(name, pack_type = {}) ⇒ Object
Computes the relative path for a given Shakapacker asset using manifest.json. If no asset is found, returns nil.
Example:
Shakapacker.manifest.lookup('calendar.js') # => "/packs/calendar-1016838bab065ae1e122.js"
41 42 43 44 45 |
# File 'lib/shakapacker/manifest.rb', line 41 def lookup(name, pack_type = {}) compile if compiling? find(full_pack_name(name, pack_type[:type])) end |
#lookup!(name, pack_type = {}) ⇒ Object
Like lookup, except that if no asset is found, raises a Shakapacker::Manifest::MissingEntryError.
48 49 50 |
# File 'lib/shakapacker/manifest.rb', line 48 def lookup!(name, pack_type = {}) lookup(name, pack_type) || handle_missing_entry(name, pack_type) end |
#lookup_pack_with_chunks(name, pack_type = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/shakapacker/manifest.rb', line 21 def lookup_pack_with_chunks(name, pack_type = {}) compile if compiling? manifest_pack_type = manifest_type(pack_type[:type]) manifest_pack_name = manifest_name(name, manifest_pack_type) find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type] rescue NoMethodError nil end |
#lookup_pack_with_chunks!(name, pack_type = {}) ⇒ Object
31 32 33 |
# File 'lib/shakapacker/manifest.rb', line 31 def lookup_pack_with_chunks!(name, pack_type = {}) lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type) end |
#refresh ⇒ Object
17 18 19 |
# File 'lib/shakapacker/manifest.rb', line 17 def refresh @data = load end |