class Propshaft::Processor

Constants

MANIFEST_FILENAME

Attributes

compilers[R]
load_path[R]
output_path[R]

Public Class Methods

new(load_path:, output_path:, compilers:) click to toggle source
# File lib/propshaft/processor.rb, line 8
def initialize(load_path:, output_path:, compilers:)
  @load_path, @output_path = load_path, output_path
  @compilers = compilers
end

Public Instance Methods

clean() click to toggle source
# File lib/propshaft/processor.rb, line 23
def clean
  Propshaft::OutputPath.new(output_path, load_path.manifest).clean(2, 1.hour)
end
clobber() click to toggle source
# File lib/propshaft/processor.rb, line 19
def clobber
  FileUtils.rm_r(output_path) if File.exist?(output_path)
end
process() click to toggle source
# File lib/propshaft/processor.rb, line 13
def process
  ensure_output_path_exists
  write_manifest
  output_assets
end

Private Instance Methods

compile_asset(asset) click to toggle source
# File lib/propshaft/processor.rb, line 54
def compile_asset(asset)
  File.open(output_path.join(asset.digested_path), "w+") do |file|
    begin
      file.write compilers.compile(asset)
    rescue Encoding::UndefinedConversionError
      # FIXME: Not sure if there's a better way here?
      file.write compilers.compile(asset).force_encoding("UTF-8")
    end
  end if compilers.compilable?(asset)
end
copy_asset(asset) click to toggle source
# File lib/propshaft/processor.rb, line 65
def copy_asset(asset)
  FileUtils.copy asset.path, output_path.join(asset.digested_path)
end
ensure_output_path_exists() click to toggle source
# File lib/propshaft/processor.rb, line 28
def ensure_output_path_exists
  FileUtils.mkdir_p output_path
end
output_asset(asset) click to toggle source
# File lib/propshaft/processor.rb, line 50
def output_asset(asset)
  compile_asset(asset) || copy_asset(asset)
end
output_assets() click to toggle source
# File lib/propshaft/processor.rb, line 40
def output_assets
  load_path.assets.each do |asset|
    unless output_path.join(asset.digested_path).exist?
      Propshaft.logger.info "Writing #{asset.digested_path}"
      FileUtils.mkdir_p output_path.join(asset.digested_path.parent)
      output_asset(asset)
    end
  end
end
write_manifest() click to toggle source
# File lib/propshaft/processor.rb, line 33
def write_manifest
  File.open(output_path.join(MANIFEST_FILENAME), "wb+") do |manifest|
    manifest.write load_path.manifest.to_json
  end
end