`Processing` is an internal mixin whose public methods are exposed on the `Environment` and `Index` classes.
Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.
Bundle Processors are ran on concatenated assets rather than individual files.
All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.
# File lib/sprockets/processing.rb, line 176 176: def bundle_processors(mime_type = nil) 177: if mime_type 178: @bundle_processors[mime_type].dup 179: else 180: deep_copy_hash(@bundle_processors) 181: end 182: end
Return CSS compressor or nil if none is set
# File lib/sprockets/processing.rb, line 226 226: def css_compressor 227: bundle_processors('text/css').detect { |klass| 228: klass.respond_to?(:name) && 229: klass.name == 'Sprockets::Processor (css_compressor)' 230: } 231: end
Assign a compressor to run on `text/css` assets.
The compressor object must respond to `compress` or `compile`.
# File lib/sprockets/processing.rb, line 236 236: def css_compressor=(compressor) 237: expire_index! 238: 239: unregister_bundle_processor 'text/css', :css_compressor 240: return unless compressor 241: 242: register_bundle_processor 'text/css', :css_compressor do |context, data| 243: compressor.compress(data) 244: end 245: end
Returns an `Array` of format extension `String`s.
format_extensions # => ['.js', '.css']
# File lib/sprockets/processing.rb, line 25 25: def format_extensions 26: @trail.extensions - @engines.keys 27: end
Return JS compressor or nil if none is set
# File lib/sprockets/processing.rb, line 248 248: def js_compressor 249: bundle_processors('application/javascript').detect { |klass| 250: klass.respond_to?(:name) && 251: klass.name == 'Sprockets::Processor (js_compressor)' 252: } 253: end
Assign a compressor to run on `application/javascript` assets.
The compressor object must respond to `compress` or `compile`.
# File lib/sprockets/processing.rb, line 258 258: def js_compressor=(compressor) 259: expire_index! 260: 261: unregister_bundle_processor 'application/javascript', :js_compressor 262: return unless compressor 263: 264: register_bundle_processor 'application/javascript', :js_compressor do |context, data| 265: compressor.compress(data) 266: end 267: end
Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.
Postprocessors are ran after Preprocessors and Engine processors.
All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.
# File lib/sprockets/processing.rb, line 67 67: def postprocessors(mime_type = nil) 68: if mime_type 69: @postprocessors[mime_type].dup 70: else 71: deep_copy_hash(@postprocessors) 72: end 73: end
Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.
Preprocessors are ran before Postprocessors and Engine processors.
All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.
# File lib/sprockets/processing.rb, line 51 51: def preprocessors(mime_type = nil) 52: if mime_type 53: @preprocessors[mime_type].dup 54: else 55: deep_copy_hash(@preprocessors) 56: end 57: end
Deprecated alias for `preprocessors`.
# File lib/sprockets/processing.rb, line 38 38: def processors(*args) 39: preprocessors(*args) 40: end
Registers a new Bundle Processor `klass` for `mime_type`.
register_bundle_processor 'text/css', Sprockets::CharsetNormalizer
A block can be passed for to create a shorthand processor.
register_bundle_processor :my_processor do |context, data| data.gsub(...) end
# File lib/sprockets/processing.rb, line 194 194: def register_bundle_processor(mime_type, klass, &block) 195: expire_index! 196: 197: if block_given? 198: name = klass.to_s 199: klass = Class.new(Processor) do 200: @name = name 201: @processor = block 202: end 203: end 204: 205: @bundle_processors[mime_type].push(klass) 206: end
Registers a new Engine `klass` for `ext`.
# File lib/sprockets/processing.rb, line 30 30: def register_engine(ext, klass) 31: # Overrides the global behavior to expire the index 32: expire_index! 33: add_engine_to_trail(ext, klass) 34: super 35: end
Register a new mime type.
# File lib/sprockets/processing.rb, line 13 13: def register_mime_type(mime_type, ext) 14: # Overrides the global behavior to expire the index 15: expire_index! 16: @trail.append_extension(ext) 17: super 18: end
Registers a new Postprocessor `klass` for `mime_type`.
register_postprocessor 'text/css', Sprockets::CharsetNormalizer
A block can be passed for to create a shorthand processor.
register_postprocessor :my_processor do |context, data| data.gsub(...) end
# File lib/sprockets/processing.rb, line 114 114: def register_postprocessor(mime_type, klass, &block) 115: expire_index! 116: 117: if block_given? 118: name = klass.to_s 119: klass = Class.new(Processor) do 120: @name = name 121: @processor = block 122: end 123: end 124: 125: @postprocessors[mime_type].push(klass) 126: end
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 :my_processor do |context, data| data.gsub(...) end
# File lib/sprockets/processing.rb, line 90 90: def register_preprocessor(mime_type, klass, &block) 91: expire_index! 92: 93: if block_given? 94: name = klass.to_s 95: klass = Class.new(Processor) do 96: @name = name 97: @processor = block 98: end 99: end 100: 101: @preprocessors[mime_type].push(klass) 102: end
Deprecated alias for `register_preprocessor`.
# File lib/sprockets/processing.rb, line 76 76: def register_processor(*args, &block) 77: register_preprocessor(*args, &block) 78: end
Remove Bundle Processor `klass` for `mime_type`.
unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
# File lib/sprockets/processing.rb, line 212 212: def unregister_bundle_processor(mime_type, klass) 213: expire_index! 214: 215: if klass.is_a?(String) || klass.is_a?(Symbol) 216: klass = @bundle_processors[mime_type].detect { |cls| 217: cls.respond_to?(:name) && 218: cls.name == "Sprockets::Processor (#{klass})" 219: } 220: end 221: 222: @bundle_processors[mime_type].delete(klass) 223: end
Remove Postprocessor `klass` for `mime_type`.
unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor
# File lib/sprockets/processing.rb, line 154 154: def unregister_postprocessor(mime_type, klass) 155: expire_index! 156: 157: if klass.is_a?(String) || klass.is_a?(Symbol) 158: klass = @postprocessors[mime_type].detect { |cls| 159: cls.respond_to?(:name) && 160: cls.name == "Sprockets::Processor (#{klass})" 161: } 162: end 163: 164: @postprocessors[mime_type].delete(klass) 165: end
Remove Preprocessor `klass` for `mime_type`.
unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor
# File lib/sprockets/processing.rb, line 137 137: def unregister_preprocessor(mime_type, klass) 138: expire_index! 139: 140: if klass.is_a?(String) || klass.is_a?(Symbol) 141: klass = @preprocessors[mime_type].detect { |cls| 142: cls.respond_to?(:name) && 143: cls.name == "Sprockets::Processor (#{klass})" 144: } 145: end 146: 147: @preprocessors[mime_type].delete(klass) 148: end
Deprecated alias for `unregister_preprocessor`.
# File lib/sprockets/processing.rb, line 129 129: def unregister_processor(*args) 130: unregister_preprocessor(*args) 131: end
# File lib/sprockets/processing.rb, line 270 270: def add_engine_to_trail(ext, klass) 271: @trail.append_extension(ext.to_s) 272: 273: if klass.respond_to?(:default_mime_type) && klass.default_mime_type 274: if format_ext = extension_for_mime_type(klass.default_mime_type) 275: @trail.alias_extension(ext.to_s, format_ext) 276: end 277: end 278: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.