Permalink
Browse files

Rename formats to processors

  • Loading branch information...
1 parent 7e131ee commit ae313886936a887ea837fb71c9808ebb8e84c5e5 @josh josh committed May 20, 2011
View
@@ -73,7 +73,7 @@ def evaluate(filename, options = {})
asset_pathname.engine_format_extension
data = options[:data] || pathname.read
- engines = options[:engines] || environment.formats(extension) +
+ engines = options[:engines] || environment.processors(extension) +
asset_pathname.engines.reverse
engines.inject(data) do |result, engine|
@@ -25,16 +25,16 @@ module Sprockets
# the processor to do whatever you'd like. You could add your own
# custom directives or invent your own directive syntax.
#
- # `Environment#formats` includes `DirectiveProcessor` by default.
+ # `Environment#processors` includes `DirectiveProcessor` by default.
#
# To remove the processor entirely:
#
- # env.unregister_format('.css', Sprockets::DirectiveProcessor)
- # env.unregister_format('.js', Sprockets::DirectiveProcessor)
+ # env.unregister_processor('.css', Sprockets::DirectiveProcessor)
+ # env.unregister_processor('.js', Sprockets::DirectiveProcessor)
#
# Then inject your own preprocessor:
#
- # env.register_format('.css', MyProcessor)
+ # env.register_processor('.css', MyProcessor)
#
class DirectiveProcessor < Tilt::Template
attr_reader :pathname
@@ -184,8 +184,8 @@ def extract_directive(line)
#
# Replace the current processor on the environment with your own:
#
- # env.unregister_format('.css', Sprockets::DirectiveProcessor)
- # env.register_format('.css', DirectiveProcessor)
+ # env.unregister_processor('.css', Sprockets::DirectiveProcessor)
+ # env.register_processor('.css', DirectiveProcessor)
#
def process_directives
directives.each do |name, *args|
@@ -25,14 +25,14 @@ def initialize(root = ".")
@mime_types = {}
@engines = {}
- @formats = Hash.new { |h, k| h[k] = [] }
+ @processors = Hash.new { |h, k| h[k] = [] }
@bundle_processors = Hash.new { |h, k| h[k] = [] }
register_mime_type 'text/css', '.css'
register_mime_type 'application/javascript', '.js'
- register_format '.css', DirectiveProcessor
- register_format '.js', DirectiveProcessor
+ register_processor '.css', DirectiveProcessor
+ register_processor '.js', DirectiveProcessor
register_engine '.jst', JstProcessor
register_engine '.ejs', EjsTemplate
@@ -22,7 +22,7 @@ def initialize(environment, trail, static_root)
@mime_types = environment.mime_types
@engines = environment.engines
- @formats = environment.formats
+ @processors = environment.processors
@bundle_processors = environment.bundle_processors
end
@@ -109,7 +109,7 @@ def build_asset(logical_path, pathname, options)
extension = asset_pathname.format_extension ||
asset_pathname.engine_format_extension
- if formats(extension).any?
+ if processors(extension).any?
logger.info "[Sprockets] #{logical_path} building"
asset = BundledAsset.new(self, logical_path, pathname, options)
else
@@ -20,28 +20,28 @@ def register_mime_type(mime_type, ext)
@mime_types[ext] = mime_type
end
- def formats(ext = nil)
+ def processors(ext = nil)
if ext
- @formats[normalize_extension(ext)].dup
+ @processors[normalize_extension(ext)].dup
else
- deep_copy_hash(@formats)
+ deep_copy_hash(@processors)
end
end
def format_extensions
- @formats.keys
+ @processors.keys
end
- def register_format(ext, klass)
+ def register_processor(ext, klass)
expire_index!
ext = normalize_extension(ext)
@trail.extensions << ext
- @formats[ext].push(klass)
+ @processors[ext].push(klass)
end
- def unregister_format(ext, klass)
+ def unregister_processor(ext, klass)
expire_index!
- @formats[normalize_extension(ext)].delete(klass)
+ @processors[normalize_extension(ext)].delete(klass)
end
def engines(ext = nil)
@@ -111,8 +111,8 @@ def process_require_glob_directive(glob)
end
test "custom processor using Context#sprockets_resolve and Context#sprockets_depend" do
- @env.unregister_format('.js', Sprockets::DirectiveProcessor)
- @env.register_format('.js', TestDirectiveProcessor)
+ @env.unregister_processor('.js', Sprockets::DirectiveProcessor)
+ @env.register_processor('.js', TestDirectiveProcessor)
assert_equal "var Foo = {};\n\n", @env["require_glob.js"].to_s
end
View
@@ -403,7 +403,7 @@ def foo; end
end
test "disabling default directive preprocessor" do
- @env.unregister_format('.js', Sprockets::DirectiveProcessor)
+ @env.unregister_processor('.js', Sprockets::DirectiveProcessor)
assert_equal "// =require \"notfound\"\n", @env["missing_require.js"].to_s
end
end

0 comments on commit ae31388

Please sign in to comment.