class Requirejs::Manifest
Class responsible for proper assets paths generation that is used in standard non-almond build with digest settings turned on - to properly map resources to their digested paths Paths are stored in manifest file.
Public Class Methods
new(scope, file)
click to toggle source
# File lib/requirejs/manifest.rb, line 7 def initialize(scope, file) @scope, @file = scope, file @manifest_location = File.join(Requirejs.config.cache_build_scripts_location, 'manifest.yaml') end
Public Instance Methods
paths()
click to toggle source
# File lib/requirejs/manifest.rb, line 12 def paths if manifest_exists? read_paths_from_manifest else paths = extract_paths_from_environment save_manifest(paths) paths end end
paths_as_json()
click to toggle source
# File lib/requirejs/manifest.rb, line 22 def paths_as_json JSON.pretty_generate(paths) end
Private Instance Methods
extract_paths_from_environment()
click to toggle source
# File lib/requirejs/manifest.rb, line 36 def extract_paths_from_environment {}.tap do |hash| @scope.environment.each_logical_path do |logical_path| next unless include_asset?(logical_path) hash[logical_path.gsub(/(^.*)\.js$/, '\1')] = @scope.path_to_asset(logical_path).gsub(/(^.*)\.js$/, '\1') end end end
include_asset?(logical_path)
click to toggle source
# File lib/requirejs/manifest.rb, line 45 def include_asset?(logical_path) (logical_path =~/.*\.js$/) && (File.basename(logical_path) != File.basename(@file)) end
manifest_exists?()
click to toggle source
# File lib/requirejs/manifest.rb, line 32 def manifest_exists? File.exists?(@manifest_location) end
read_paths_from_manifest()
click to toggle source
# File lib/requirejs/manifest.rb, line 28 def read_paths_from_manifest YAML.load(File.read(@manifest_location)) end
save_manifest(paths)
click to toggle source
# File lib/requirejs/manifest.rb, line 49 def save_manifest(paths) File.open(@manifest_location, 'w') do |f| f.write(YAML.dump(paths)) end end