Module: Sprockets::Processing

Includes:
ProcessorUtils, URIUtils, Utils
Included in:
Configuration, Loader
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

Constants included from ProcessorUtils

Sprockets::ProcessorUtils::VALID_METADATA_COMPOUND_TYPES, Sprockets::ProcessorUtils::VALID_METADATA_TYPES, Sprockets::ProcessorUtils::VALID_METADATA_VALUE_TYPES

Constants included from Utils

Utils::UNBOUND_METHODS_BIND_TO_ANY_OBJECT

Instance Method Summary collapse

Methods included from ProcessorUtils

#call_processor, #call_processors, #compose_processors, #processor_cache_key, #processors_cache_keys, #valid_processor_metadata_value?, #validate_processor_result!

Methods included from URIUtils

#build_asset_uri, #build_file_digest_uri, #encode_uri_query_params, #join_file_uri, #join_uri, #parse_asset_uri, #parse_file_digest_uri, #parse_uri_query_params, #split_file_uri, #split_uri, #valid_asset_uri?

Methods included from Utils

#concat_javascript_sources, #dfs, #dfs_paths, #duplicable?, #hash_reassoc, #hash_reassoc1, #module_include, #normalize_extension, #string_end_with_semicolon?

Instance Method Details

#bundle_processorsObject

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



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

def bundle_processors
  config[:bundle_processors]
end

#pipelinesObject



16
17
18
# File 'lib/sprockets/processing.rb', line 16

def pipelines
  config[:pipelines]
end

#postprocessorsObject

Postprocessors are ran after Preprocessors and Engine processors.



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

def postprocessors
  config[:postprocessors]
end

#preprocessorsObject Also known as: processors

Preprocessors are ran before Postprocessors and Engine processors.



30
31
32
# File 'lib/sprockets/processing.rb', line 30

def preprocessors
  config[:preprocessors]
end

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

Public: Register bundle metadata reducer function.

Examples

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

Sprockets.register_bundle_metadata_reducer '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 funciton (default: nil) block - Proc accepting the memo accumulator and current value

Returns nothing.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/sprockets/processing.rb', line 130

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) ⇒ Object

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', :my_processor do |context, data|
  data.gsub(...)
end


102
103
104
# File 'lib/sprockets/processing.rb', line 102

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

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



20
21
22
23
24
25
26
# File 'lib/sprockets/processing.rb', line 20

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

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

#register_postprocessor(*args, &block) ⇒ Object

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', :my_processor do |context, data|
  data.gsub(...)
end


65
66
67
# File 'lib/sprockets/processing.rb', line 65

def register_postprocessor(*args, &block)
  register_config_processor(:postprocessors, *args, &block)
end

#register_preprocessor(*args, &block) ⇒ Object 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', :my_processor do |context, data|
  data.gsub(...)
end


50
51
52
# File 'lib/sprockets/processing.rb', line 50

def register_preprocessor(*args, &block)
  register_config_processor(:preprocessors, *args, &block)
end

#unregister_bundle_processor(*args) ⇒ Object

Remove Bundle Processor ‘klass` for `mime_type`.

unregister_bundle_processor 'application/javascript', Sprockets::DirectiveProcessor


110
111
112
# File 'lib/sprockets/processing.rb', line 110

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

#unregister_postprocessor(*args) ⇒ Object

Remove Postprocessor ‘klass` for `mime_type`.

unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor


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

def unregister_postprocessor(*args)
  unregister_config_processor(:postprocessors, *args)
end

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

Remove Preprocessor ‘klass` for `mime_type`.

unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor


73
74
75
# File 'lib/sprockets/processing.rb', line 73

def unregister_preprocessor(*args)
  unregister_config_processor(:preprocessors, *args)
end