Sha256: 2c1ca2e57330053a41e92506908cb1d2d25d2f05ab87a52cf0aacd72872bf6fc

Contents?: true

Size: 713 Bytes

Versions: 8

Compression:

Stored size: 713 Bytes

Contents

class Propshaft::Compilers
  attr_reader :registrations, :assembly

  def initialize(assembly)
    @assembly      = assembly
    @registrations = Hash.new
  end

  def register(mime_type, klass)
    registrations[mime_type] ||= []
    registrations[mime_type] << klass
  end

  def any?
    registrations.any?
  end

  def compilable?(asset)
    registrations[asset.content_type.to_s].present?
  end

  def compile(asset)
    if relevant_registrations = registrations[asset.content_type.to_s]
      asset.content.dup.tap do |input|
        relevant_registrations.each do |compiler|
          input.replace compiler.new(assembly).compile(input)
        end
      end
    else
      asset.content
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
propshaft-0.1.7 lib/propshaft/compilers.rb
propshaft-0.1.6 lib/propshaft/compilers.rb
propshaft-0.1.5 lib/propshaft/compilers.rb
propshaft-0.1.4 lib/propshaft/compilers.rb
propshaft-0.1.3 lib/propshaft/compilers.rb
propshaft-0.1.2 lib/propshaft/compilers.rb
propshaft-0.1.1 lib/propshaft/compilers.rb
propshaft-0.1.0 lib/propshaft/compilers.rb