1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
require "propshaft/manifest"
require "propshaft/load_path"
require "propshaft/resolver/dynamic"
require "propshaft/resolver/static"
require "propshaft/server"
require "propshaft/processor"
require "propshaft/compilers"
require "propshaft/compiler/css_asset_urls"
require "propshaft/compiler/js_asset_urls"
require "propshaft/compiler/source_mapping_urls"
class Propshaft::Assembly
attr_reader :config
def initialize(config)
@config = config
end
def load_path
@load_path ||= Propshaft::LoadPath.new(
config.paths,
compilers: compilers,
version: config.version,
file_watcher: config.file_watcher,
integrity_hash_algorithm: config.integrity_hash_algorithm
)
end
def resolver
@resolver ||= if config.manifest_path.exist?
Propshaft::Resolver::Static.new manifest_path: config.manifest_path, prefix: config.prefix
else
Propshaft::Resolver::Dynamic.new load_path: load_path, prefix: config.prefix
end
end
def server
Propshaft::Server.new(self)
end
def processor
Propshaft::Processor.new \
load_path: load_path, output_path: config.output_path, compilers: compilers, manifest_path: config.manifest_path
end
def compilers
@compilers ||=
Propshaft::Compilers.new(self).tap do |compilers|
Array(config.compilers).each do |(mime_type, klass)|
compilers.register mime_type, klass
end
end
end
def reveal(path_type = :logical_path)
path_type = path_type.presence_in(%i[ logical_path path ]) || raise(ArgumentError, "Unknown path_type: #{path_type}")
load_path.assets.collect do |asset|
asset.send(path_type)
end
end
end
|