class Yarrow::Assets::Manifest
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`
Public Class Methods
Initializes the manifest from a Sprockets-style JSON file.
If no assets directory is given, looks for a manifest in the main output directory.
@param config [Yarrow::Configuration]
# 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
Public Instance Methods
Returns the list of generated CSS assets in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 99 def css_digest_paths select_by_extension(digest_paths, '.css') end
Returns the list of named CSS assets in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 83 def css_logical_paths select_by_extension(logical_paths, '.css') end
Returns the generated digest path to a named asset.
@param logical_path [String] @return [String]
# File lib/yarrow/assets/manifest.rb, line 59 def digest_path(logical_path) @manifest_index[logical_path] end
Returns the list of generated digest paths in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 75 def digest_paths @manifest_index.values end
True if the named asset exists.
@param logical_path [String] @return [Boolean]
# File lib/yarrow/assets/manifest.rb, line 50 def exists?(logical_path) @manifest_index.key? logical_path end
Returns the list of generated JS assets in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 107 def js_digest_paths select_by_extension(digest_paths, '.js') end
Returns the list of named JS assets in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 91 def js_logical_paths select_by_extension(logical_paths, '.js') end
Returns the list of named assets in the manifest.
@return [Array<String>]
# File lib/yarrow/assets/manifest.rb, line 67 def logical_paths @manifest_index.keys end
Private Instance Methods
# File lib/yarrow/assets/manifest.rb, line 113 def select_by_extension(collection, ext) collection.select { |asset| asset.end_with?(ext) } end