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.
-
#file(logical_path) ⇒ Hash
Returns a hash of file information for a generated asset.
-
#files ⇒ Array<Hash>
Returns the list of generated files in the manifest.
-
#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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yarrow/assets/manifest.rb', line 24 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_index = JSON.parse(File.read(manifest_path)) else @manifest_index = { 'assets' => {}, 'files' => {} } end end |
Instance Method Details
#css_digest_paths ⇒ Array<String>
Returns the list of generated CSS assets in the manifest.
114 115 116 |
# File 'lib/yarrow/assets/manifest.rb', line 114 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.
98 99 100 |
# File 'lib/yarrow/assets/manifest.rb', line 98 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.
57 58 59 |
# File 'lib/yarrow/assets/manifest.rb', line 57 def digest_path(logical_path) @manifest_index['assets'][logical_path] end |
#digest_paths ⇒ Array<String>
Returns the list of generated digest paths in the manifest.
82 83 84 |
# File 'lib/yarrow/assets/manifest.rb', line 82 def digest_paths @manifest_index['files'].keys end |
#exists?(logical_path) ⇒ Boolean
True if the named asset exists.
48 49 50 |
# File 'lib/yarrow/assets/manifest.rb', line 48 def exists?(logical_path) @manifest_index['assets'].key? logical_path end |
#file(logical_path) ⇒ Hash
Returns a hash of file information for a generated asset.
66 67 68 |
# File 'lib/yarrow/assets/manifest.rb', line 66 def file(logical_path) @manifest_index['files'][digest_path(logical_path)] end |
#files ⇒ Array<Hash>
Returns the list of generated files in the manifest.
90 91 92 |
# File 'lib/yarrow/assets/manifest.rb', line 90 def files @manifest_index['files'].values end |
#js_digest_paths ⇒ Array<String>
Returns the list of generated JS assets in the manifest.
122 123 124 |
# File 'lib/yarrow/assets/manifest.rb', line 122 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.
106 107 108 |
# File 'lib/yarrow/assets/manifest.rb', line 106 def js_logical_paths select_by_extension(logical_paths, '.js') end |
#logical_paths ⇒ Array<String>
Returns the list of named assets in the manifest.
74 75 76 |
# File 'lib/yarrow/assets/manifest.rb', line 74 def logical_paths @manifest_index['assets'].keys end |