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_COMPOUND_TYPES_HASH, Sprockets::ProcessorUtils::VALID_METADATA_TYPES, Sprockets::ProcessorUtils::VALID_METADATA_VALUE_TYPES, Sprockets::ProcessorUtils::VALID_METADATA_VALUE_TYPES_HASH
Instance Method Summary collapse
-
#bundle_processors ⇒ Object
Bundle Processors are ran on concatenated assets rather than individual files.
- #pipelines ⇒ Object
-
#postprocessors ⇒ Object
Postprocessors are ran after Preprocessors and Engine processors.
-
#preprocessors ⇒ Object
(also: #processors)
Preprocessors are ran before Postprocessors and Engine processors.
-
#register_bundle_metadata_reducer(mime_type, key, *args, &block) ⇒ Object
Public: Register bundle metadata reducer function.
-
#register_bundle_processor(*args, &block) ⇒ Object
Registers a new Bundle Processor ‘klass` for `mime_type`.
-
#register_pipeline(name, proc = nil, &block) ⇒ Object
Registers a pipeline that will be called by ‘call_processor` method.
-
#register_postprocessor(*args, &block) ⇒ Object
Registers a new Postprocessor ‘klass` for `mime_type`.
-
#register_preprocessor(*args, &block) ⇒ Object
(also: #register_processor)
Registers a new Preprocessor ‘klass` for `mime_type`.
-
#unregister_bundle_processor(*args) ⇒ Object
Remove Bundle Processor ‘klass` for `mime_type`.
-
#unregister_postprocessor(*args) ⇒ Object
Remove Postprocessor ‘klass` for `mime_type`.
-
#unregister_preprocessor(*args) ⇒ Object
(also: #unregister_processor)
Remove Preprocessor ‘klass` for `mime_type`.
Methods included from ProcessorUtils
#call_processor, #call_processors, #compose_processors, #processor_cache_key, #processors_cache_keys, #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, #string_end_with_semicolon?
Instance Method Details
#bundle_processors ⇒ Object
Bundle Processors are ran on concatenated assets rather than individual files.
95 96 97 |
# File 'lib/sprockets/processing.rb', line 95 def bundle_processors config[:bundle_processors] end |
#pipelines ⇒ Object
14 15 16 |
# File 'lib/sprockets/processing.rb', line 14 def pipelines config[:pipelines] end |
#postprocessors ⇒ Object
Postprocessors are ran after Preprocessors and Engine processors.
39 40 41 |
# File 'lib/sprockets/processing.rb', line 39 def postprocessors config[:postprocessors] end |
#preprocessors ⇒ Object Also known as: processors
Preprocessors are ran before Postprocessors and Engine processors.
33 34 35 |
# File 'lib/sprockets/processing.rb', line 33 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 function (default: nil) block - Proc accepting the memo accumulator and current value
Returns nothing.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# 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) ⇒ 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' do |input|
input[:data].gsub(...)
end
109 110 111 |
# File 'lib/sprockets/processing.rb', line 109 def register_bundle_processor(*args, &block) register_config_processor(:bundle_processors, *args, &block) end |
#register_pipeline(name, proc = nil, &block) ⇒ Object
Registers a pipeline that will be called by ‘call_processor` method.
19 20 21 22 23 24 25 26 27 28 29 |
# 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) ⇒ 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' do |input|
input[:data].gsub(...)
end
69 70 71 72 |
# 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) ⇒ 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' do |input|
input[:data].gsub(...)
end
53 54 55 56 |
# 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 |
#unregister_bundle_processor(*args) ⇒ Object
Remove Bundle Processor ‘klass` for `mime_type`.
unregister_bundle_processor 'application/javascript', Sprockets::DirectiveProcessor
117 118 119 |
# File 'lib/sprockets/processing.rb', line 117 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
88 89 90 91 |
# 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) ⇒ Object Also known as: unregister_processor
Remove Preprocessor ‘klass` for `mime_type`.
unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor
78 79 80 81 |
# File 'lib/sprockets/processing.rb', line 78 def unregister_preprocessor(*args) unregister_config_processor(:preprocessors, *args) compute_transformers!(self.config[:registered_transformers]) end |