123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::Processing

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/sprockets/processing.rb

Overview

Processing is an internal mixin whose public methods are exposed on the Environment and CachedEnvironment classes.

Constant Summary

Utils - Included

MODULE_INCLUDE_MUTEX, WHITESPACE_ORDINALS

ProcessorUtils - Included

VALID_METADATA_COMPOUND_TYPES, VALID_METADATA_COMPOUND_TYPES_HASH, VALID_METADATA_TYPES, VALID_METADATA_VALUE_TYPES, VALID_METADATA_VALUE_TYPES_HASH

Instance Method Summary

ProcessorUtils - Included

#call_processor

Public: Invoke processor.

#call_processors

Public: Invoke list of processors in right to left order.

#compose_processors

Public: Compose processors in right to left order.

#processor_cache_key

Internal: Get processor defined cached key.

#processors_cache_keys

Internal: Get combined cache keys for set of processors.

#validate_processor_result!

Internal: Validate returned result of calling a processor pipeline and raise a friendly user error message.

URIUtils - Included

#build_asset_uri

Internal: Build Asset URI.

#build_file_digest_uri

Internal: Build file-digest dependency URI.

#encode_uri_query_params

Internal: Serialize hash of params into query string.

#join_file_uri

Internal: Join file: URI component parts into String.

#join_uri

Internal: Join URI component parts into String.

#parse_asset_uri

Internal: Parse Asset URI.

#parse_file_digest_uri

Internal: Parse file-digest dependency URI.

#parse_uri_query_params

Internal: Parse query string into hash of params.

#split_file_uri

Internal: Parse file: URI into component parts.

#split_uri

Internal: Parse URI into component parts.

#valid_asset_uri?

Internal: Check if String is a valid Asset URI.

Utils - Included

#concat_javascript_sources

Internal: Accumulate asset source to buffer and append a trailing semicolon if necessary.

#dfs

Internal: Post-order Depth-First search algorithm.

#dfs_paths

Internal: Post-order Depth-First search algorithm that gathers all paths along the way.

#duplicable?

Internal: Check if object can safely be .dup’d.

#hash_reassoc

Internal: Duplicate and store key/value on new frozen hash.

#hash_reassoc1

Internal: Duplicate and store key/value on new frozen hash.

#module_include

Internal: Inject into target module for the duration of the block.

#string_end_with_semicolon?

Internal: Check if string has a trailing semicolon.

Instance Method Details

#bundle_processors

Bundle Processors are ran on concatenated assets rather than individual files.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 95

def bundle_processors
  config[:bundle_processors]
end

#pipelines

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 14

def pipelines
  config[:pipelines]
end

#postprocessors

Postprocessors are ran after Preprocessors and Engine processors.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 39

def postprocessors
  config[:postprocessors]
end

#preprocessors Also known as: #processors

Preprocessors are ran before Postprocessors and Engine processors.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 33

def preprocessors
  config[:preprocessors]
end

#processors

Alias for #preprocessors.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 36

alias_method :processors, :preprocessors

#register_bundle_metadata_reducer(mime_type, key, *args, &block)

Public: Register bundle metadata reducer function.

Examples

Sprockets. 'application/javascript', :jshint_errors, [], :+

Sprockets. 'text/css', :selector_count, 0 { |total, count|
  total + count
}

mime_type - String MIME Type. Use ‘/’ applies to all types. key - Symbol metadata key initial - Initial memo to pass to the reduce function (default: nil) block - Proc accepting the memo accumulator and current value

Returns nothing.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 137

def (mime_type, key, *args, &block)
  case args.size
  when 0
    reducer = block
  when 1
    if block_given?
      initial = args[0]
      reducer = block
    else
      initial = nil
      reducer = args[0].to_proc
    end
  when 2
    initial = args[0]
    reducer = args[1].to_proc
  else
    raise ArgumentError, "wrong number of arguments (#{args.size} for 0..2)"
  end

  self.config = hash_reassoc(config, :bundle_reducers, mime_type) do |reducers|
    reducers.merge(key => [initial, reducer])
  end
end

#register_bundle_processor(*args, &block)

Registers a new Bundle Processor klass for mime_type.

register_bundle_processor  'application/javascript', Sprockets::DirectiveProcessor

A block can be passed for to create a shorthand processor.

register_bundle_processor 'application/javascript' do |input|
  input[:data].gsub(...)
end
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 109

def register_bundle_processor(*args, &block)
  register_config_processor(:bundle_processors, *args, &block)
end

#register_config_processor(type, mime_type, processor = nil, &block) (private)

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 212

def register_config_processor(type, mime_type, processor = nil, &block)
  processor ||= block

  self.config = hash_reassoc(config, type, mime_type) do |processors|
    processors.unshift(processor)
    processors
  end
end

#register_pipeline(name, proc = nil, &block)

Registers a pipeline that will be called by call_processor method.

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 19

def register_pipeline(name, proc = nil, &block)
  proc ||= block

  self.config = hash_reassoc(config, :pipeline_exts) do |pipeline_exts|
    pipeline_exts.merge(".#{name}".freeze => name.to_sym)
  end

  self.config = hash_reassoc(config, :pipelines) do |pipelines|
    pipelines.merge(name.to_sym => proc)
  end
end

#register_postprocessor(*args, &block)

Registers a new Postprocessor klass for mime_type.

register_postprocessor 'application/javascript', Sprockets::DirectiveProcessor

A block can be passed for to create a shorthand processor.

register_postprocessor 'application/javascript' do |input|
  input[:data].gsub(...)
end
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 69

def register_postprocessor(*args, &block)
  register_config_processor(:postprocessors, *args, &block)
  compute_transformers!(self.config[:registered_transformers])
end

#register_preprocessor(*args, &block) Also known as: #register_processor

Registers a new Preprocessor klass for mime_type.

register_preprocessor 'text/css', Sprockets::DirectiveProcessor

A block can be passed for to create a shorthand processor.

register_preprocessor 'text/css' do |input|
  input[:data].gsub(...)
end
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 53

def register_preprocessor(*args, &block)
  register_config_processor(:preprocessors, *args, &block)
  compute_transformers!(self.config[:registered_transformers])
end

#register_processor(*args, &block)

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 57

alias_method :register_processor, :register_preprocessor

#unregister_bundle_processor(*args)

Remove Bundle Processor klass for mime_type.

unregister_bundle_processor 'application/javascript', Sprockets::DirectiveProcessor
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 117

def unregister_bundle_processor(*args)
  unregister_config_processor(:bundle_processors, *args)
end

#unregister_config_processor(type, mime_type, processor) (private)

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 221

def unregister_config_processor(type, mime_type, processor)
  self.config = hash_reassoc(config, type, mime_type) do |processors|
    processors.delete_if { |p| p == processor || p.class == processor }
    processors
  end
end

#unregister_postprocessor(*args)

Remove Postprocessor klass for mime_type.

unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 88

def unregister_postprocessor(*args)
  unregister_config_processor(:postprocessors, *args)
  compute_transformers!(self.config[:registered_transformers])
end

#unregister_preprocessor(*args) Also known as: #unregister_processor

Remove Preprocessor klass for mime_type.

unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor
[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 78

def unregister_preprocessor(*args)
  unregister_config_processor(:preprocessors, *args)
  compute_transformers!(self.config[:registered_transformers])
end

#unregister_processor(*args)

[ GitHub ]

  
# File 'lib/sprockets/processing.rb', line 82

alias_method :unregister_processor, :unregister_preprocessor