module Sprockets::Transformers

def register_transformer(from, to, proc)

Returns nothing.

register_transformer 'image/svg+xml', 'image/png', ConvertSvgToPng

ConvertCoffeeScriptToJavaScript
register_transformer 'text/coffeescript', 'application/javascript',

Examples

proc - Callable block that accepts an input Hash.
to - String mime type
from - String mime type

Public: Register a transformer from and to a mime type.
def register_transformer(from, to, proc)
  mutate_hash_config(:transformers, from) do |transformers|
    transformers.merge(to => proc)
  end
end

def resolve_transform_type(type, accept = nil)

Returns String mime type or nil is no type satisfied the accept value.

# => nil
resolve_transform_type('text/css', 'image/png')

# => 'image/png'
resolve_transform_type('image/svg+xml', 'image/png, image/*')

# => 'text/plain'
resolve_transform_type('text/plain', 'text/plain')

Examples

accept - String accept type list (default: '*/*')
type - String from mime type

transformed to.
Public: Resolve target mime type that the source type should be
def resolve_transform_type(type, accept = nil)
  find_best_mime_type_match(accept || '*/*', [type].compact + transformers[type].keys)
end

def unwrap_transformer(from, to)

Returns Array of Procs.

to - String mime type
from - String mime type

Internal: Find and load transformer by from and to mime type.
def unwrap_transformer(from, to)
  if processor = transformers[from][to]
    [unwrap_processor(processor)]
  else
    []
  end
end