Class: Yarrow::Assets::Manifest
- Inherits:
-
Object
- Object
- Yarrow::Assets::Manifest
- Defined in:
- lib/yarrow/assets/manifest.rb
Overview
Provides access to the bundle of compiled CSS and JS assets.
This is currently based on the output structure of the JSON manifest file generated by Sprockets, but this class isn’t coupled to the Sprockets API so could be used as a generic manifest reader.
-
‘logical_path` represents the core named path to an asset sans version, eg: `main.css`
-
‘digest_path` represents the versioned instance of an asset with associated digest,
eg: `main-4362eea15558e73d3663de653cdeb81e.css`
Instance Method Summary collapse
-
#css_digest_paths ⇒ Array<String>
Returns the list of generated CSS assets in the manifest.
-
#css_logical_paths ⇒ Array<String>
Returns the list of named CSS assets in the manifest.
-
#digest_path(logical_path) ⇒ String
Returns the generated digest path to a named asset.
-
#digest_paths ⇒ Array<String>
Returns the list of generated digest paths in the manifest.
-
#exists?(logical_path) ⇒ Boolean
True if the named asset exists.
-
#initialize(config) ⇒ Manifest
constructor
Initializes the manifest from a Sprockets-style JSON file.
-
#js_digest_paths ⇒ Array<String>
Returns the list of generated JS assets in the manifest.
-
#js_logical_paths ⇒ Array<String>
Returns the list of named JS assets in the manifest.
-
#logical_paths ⇒ Array<String>
Returns the list of named assets in the manifest.
Constructor Details
#initialize(config) ⇒ Manifest
Initializes the manifest from a Sprockets-style JSON file.
If no assets directory is given, looks for a manifest in the main output directory.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yarrow/assets/manifest.rb', line 23 def initialize(config) raise Yarrow::ConfigurationError if config.assets.nil? if config.assets.output_dir manifest_path = Pathname.new(config.assets.output_dir) + config.assets.manifest_file else manifest_path = Pathname.new(config.output_dir) + config.assets.manifest_file end if File.exists?(manifest_path) manifest_data = JSON.parse(File.read(manifest_path)) @manifest_index = if manifest_data.key?('assets') manifest_data['assets'] else manifest_data end else @manifest_index = {} end end |
Instance Method Details
#css_digest_paths ⇒ Array<String>
Returns the list of generated CSS assets in the manifest.
99 100 101 |
# File 'lib/yarrow/assets/manifest.rb', line 99 def css_digest_paths select_by_extension(digest_paths, '.css') end |
#css_logical_paths ⇒ Array<String>
Returns the list of named CSS assets in the manifest.
83 84 85 |
# File 'lib/yarrow/assets/manifest.rb', line 83 def css_logical_paths select_by_extension(logical_paths, '.css') end |
#digest_path(logical_path) ⇒ String
Returns the generated digest path to a named asset.
59 60 61 |
# File 'lib/yarrow/assets/manifest.rb', line 59 def digest_path(logical_path) @manifest_index[logical_path] end |
#digest_paths ⇒ Array<String>
Returns the list of generated digest paths in the manifest.
75 76 77 |
# File 'lib/yarrow/assets/manifest.rb', line 75 def digest_paths @manifest_index.values end |
#exists?(logical_path) ⇒ Boolean
True if the named asset exists.
50 51 52 |
# File 'lib/yarrow/assets/manifest.rb', line 50 def exists?(logical_path) @manifest_index.key? logical_path end |
#js_digest_paths ⇒ Array<String>
Returns the list of generated JS assets in the manifest.
107 108 109 |
# File 'lib/yarrow/assets/manifest.rb', line 107 def js_digest_paths select_by_extension(digest_paths, '.js') end |
#js_logical_paths ⇒ Array<String>
Returns the list of named JS assets in the manifest.
91 92 93 |
# File 'lib/yarrow/assets/manifest.rb', line 91 def js_logical_paths select_by_extension(logical_paths, '.js') end |
#logical_paths ⇒ Array<String>
Returns the list of named assets in the manifest.
67 68 69 |
# File 'lib/yarrow/assets/manifest.rb', line 67 def logical_paths @manifest_index.keys end |