Skip to content

Commit 2c9333b

Browse files
committed
Template -> Processor
Closes #681
1 parent b4d8a66 commit 2c9333b

23 files changed

+452
-415
lines changed

lib/sprockets.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ module Sprockets
1111
# Processing
1212
autoload :Bundle, 'sprockets/bundle'
1313
autoload :ClosureCompressor, 'sprockets/closure_compressor'
14+
autoload :CoffeeScriptProcessor, 'sprockets/coffee_script_processor'
1415
autoload :CoffeeScriptTemplate, 'sprockets/coffee_script_template'
1516
autoload :Context, 'sprockets/context'
1617
autoload :DirectiveProcessor, 'sprockets/directive_processor'
18+
autoload :EcoProcessor, 'sprockets/eco_processor'
1719
autoload :EcoTemplate, 'sprockets/eco_template'
20+
autoload :EjsProcessor, 'sprockets/ejs_processor'
1821
autoload :EjsTemplate, 'sprockets/ejs_template'
22+
autoload :ERBProcessor, 'sprockets/erb_processor'
1923
autoload :ERBTemplate, 'sprockets/erb_template'
2024
autoload :JstProcessor, 'sprockets/jst_processor'
2125
autoload :SassCompressor, 'sprockets/sass_compressor'
26+
autoload :SassProcessor, 'sprockets/sass_processor'
2227
autoload :SassTemplate, 'sprockets/sass_template'
28+
autoload :ScssProcessor, 'sprockets/sass_processor'
2329
autoload :ScssTemplate, 'sprockets/sass_template'
2430
autoload :UglifierCompressor, 'sprockets/uglifier_compressor'
2531
autoload :YUICompressor, 'sprockets/yui_compressor'
@@ -130,21 +136,21 @@ module Sprockets
130136

131137
# Mmm, CoffeeScript
132138
register_mime_type 'text/coffeescript', extensions: ['.coffee']
133-
register_engine '.coffee', LazyProcessor.new { CoffeeScriptTemplate }, mime_type: 'application/javascript'
139+
register_engine '.coffee', LazyProcessor.new { CoffeeScriptProcessor }, mime_type: 'application/javascript'
134140

135141
# JST engines
136142
register_mime_type 'text/eco', extensions: ['.eco']
137143
register_mime_type 'text/ejs', extensions: ['.ejs']
138144
register_engine '.jst', LazyProcessor.new { JstProcessor }, mime_type: 'application/javascript'
139-
register_engine '.eco', LazyProcessor.new { EcoTemplate }, mime_type: 'application/javascript'
140-
register_engine '.ejs', LazyProcessor.new { EjsTemplate }, mime_type: 'application/javascript'
145+
register_engine '.eco', LazyProcessor.new { EcoProcessor }, mime_type: 'application/javascript'
146+
register_engine '.ejs', LazyProcessor.new { EjsProcessor }, mime_type: 'application/javascript'
141147

142148
# CSS engines
143149
register_mime_type 'text/sass', extensions: ['.sass']
144150
register_mime_type 'text/scss', extensions: ['.scss']
145-
register_engine '.sass', LazyProcessor.new { SassTemplate }, mime_type: 'text/css'
146-
register_engine '.scss', LazyProcessor.new { ScssTemplate }, mime_type: 'text/css'
151+
register_engine '.sass', LazyProcessor.new { SassProcessor }, mime_type: 'text/css'
152+
register_engine '.scss', LazyProcessor.new { ScssProcessor }, mime_type: 'text/css'
147153

148154
# Other
149-
register_engine '.erb', LazyProcessor.new { ERBTemplate }, mime_type: 'text/plain'
155+
register_engine '.erb', LazyProcessor.new { ERBProcessor }, mime_type: 'text/plain'
150156
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'coffee_script'
2+
3+
module Sprockets
4+
# Processor engine class for the CoffeeScript compiler.
5+
# Depends on the `coffee-script` and `coffee-script-source` gems.
6+
#
7+
# For more infomation see:
8+
#
9+
# https://github.com/josh/ruby-coffee-script
10+
#
11+
module CoffeeScriptProcessor
12+
VERSION = '1'
13+
SOURCE_VERSION = ::CoffeeScript::Source.version
14+
15+
def self.call(input)
16+
data = input[:data]
17+
key = [self.name, SOURCE_VERSION, VERSION, data]
18+
input[:cache].fetch(key) do
19+
::CoffeeScript.compile(data)
20+
end
21+
end
22+
end
23+
end
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
require 'coffee_script'
1+
require 'sprockets/coffee_script_processor'
22

33
module Sprockets
4-
# Template engine class for the CoffeeScript compiler.
5-
# Depends on the `coffee-script` and `coffee-script-source` gems.
6-
#
7-
# For more infomation see:
8-
#
9-
# https://github.com/josh/ruby-coffee-script
10-
#
11-
module CoffeeScriptTemplate
12-
VERSION = '1'
13-
SOURCE_VERSION = ::CoffeeScript::Source.version
14-
15-
def self.call(input)
16-
data = input[:data]
17-
key = ['CoffeeScriptTemplate', SOURCE_VERSION, VERSION, data]
18-
input[:cache].fetch(key) do
19-
::CoffeeScript.compile(data)
20-
end
21-
end
22-
end
4+
# Deprecated
5+
CoffeeScriptTemplate = CoffeeScriptProcessor
236
end

lib/sprockets/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'sprockets/errors'
55

66
module Sprockets
7-
# Deprecated: `Context` provides helper methods to all `Template` processors.
7+
# Deprecated: `Context` provides helper methods to all processors.
88
# They are typically accessed by ERB templates. You can mix in custom helpers
99
# by injecting them into `Environment#context_class`. Do not mix them into
1010
# `Context` directly.

lib/sprockets/eco_processor.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'eco'
2+
3+
module Sprockets
4+
# Processor engine class for the Eco compiler. Depends on the `eco` gem.
5+
#
6+
# For more infomation see:
7+
#
8+
# https://github.com/sstephenson/ruby-eco
9+
# https://github.com/sstephenson/eco
10+
#
11+
module EcoProcessor
12+
VERSION = '1'
13+
14+
# Compile template data with Eco compiler.
15+
#
16+
# Returns a JS function definition String. The result should be
17+
# assigned to a JS variable.
18+
#
19+
# # => "function(...) {...}"
20+
#
21+
def self.call(input)
22+
data = input[:data]
23+
key = [self.name, ::Eco::Source::VERSION, VERSION, data]
24+
input[:cache].fetch(key) do
25+
::Eco.compile(data)
26+
end
27+
end
28+
end
29+
end

lib/sprockets/eco_template.rb

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
require 'eco'
1+
require 'sprockets/eco_processor'
22

33
module Sprockets
4-
# Template engine class for the Eco compiler. Depends on the `eco` gem.
5-
#
6-
# For more infomation see:
7-
#
8-
# https://github.com/sstephenson/ruby-eco
9-
# https://github.com/sstephenson/eco
10-
#
11-
module EcoTemplate
12-
VERSION = '1'
13-
14-
# Compile template data with Eco compiler.
15-
#
16-
# Returns a JS function definition String. The result should be
17-
# assigned to a JS variable.
18-
#
19-
# # => "function(...) {...}"
20-
#
21-
def self.call(input)
22-
data = input[:data]
23-
key = ['EcoTemplate', ::Eco::Source::VERSION, VERSION, data]
24-
input[:cache].fetch(key) do
25-
::Eco.compile(data)
26-
end
27-
end
28-
end
4+
# Deprecated
5+
EcoTemplate = EcoProcessor
296
end

lib/sprockets/ejs_processor.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'ejs'
2+
3+
module Sprockets
4+
# Processor engine class for the EJS compiler. Depends on the `ejs` gem.
5+
#
6+
# For more infomation see:
7+
#
8+
# https://github.com/sstephenson/ruby-ejs
9+
#
10+
module EjsProcessor
11+
VERSION = '1'
12+
13+
# Compile template data with EJS compiler.
14+
#
15+
# Returns a JS function definition String. The result should be
16+
# assigned to a JS variable.
17+
#
18+
# # => "function(obj){...}"
19+
#
20+
def self.call(input)
21+
data = input[:data]
22+
key = [self.name, VERSION, data]
23+
input[:cache].fetch(key) do
24+
::EJS.compile(data)
25+
end
26+
end
27+
end
28+
end

lib/sprockets/ejs_template.rb

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
require 'ejs'
1+
require 'sprockets/ejs_processor'
22

33
module Sprockets
4-
# Template engine class for the EJS compiler. Depends on the `ejs` gem.
5-
#
6-
# For more infomation see:
7-
#
8-
# https://github.com/sstephenson/ruby-ejs
9-
#
10-
module EjsTemplate
11-
VERSION = '1'
12-
13-
# Compile template data with EJS compiler.
14-
#
15-
# Returns a JS function definition String. The result should be
16-
# assigned to a JS variable.
17-
#
18-
# # => "function(obj){...}"
19-
#
20-
def self.call(input)
21-
data = input[:data]
22-
key = ['EjsTemplate', VERSION, data]
23-
input[:cache].fetch(key) do
24-
::EJS.compile(data)
25-
end
26-
end
27-
end
4+
# Deprecated
5+
EjsTemplate = EjsProcessor
286
end

lib/sprockets/engines.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ module Sprockets
77
#
88
# An engine is a type of processor that is bound to a filename
99
# extension. `application.js.coffee` indicates that the
10-
# `CoffeeScriptTemplate` engine will be ran on the file.
10+
# `CoffeeScriptProcessor` engine will be ran on the file.
1111
#
1212
# Extensions can be stacked and will be evaulated from right to
13-
# left. `application.js.coffee.erb` will first run `ERBTemplate`
14-
# then `CoffeeScriptTemplate`.
13+
# left. `application.js.coffee.erb` will first run `ERBProcessor`
14+
# then `CoffeeScriptProcessor`.
1515
#
1616
# All `Engine`s must follow the `Template` interface. It is
1717
# recommended to subclass `Template`.
@@ -23,15 +23,15 @@ module Sprockets
2323
#
2424
# The global registry is exposed for plugins to register themselves.
2525
#
26-
# Sprockets.register_engine '.sass', SassTemplate
26+
# Sprockets.register_engine '.sass', SassProcessor
2727
#
2828
module Engines
2929
# Returns a `Hash` of `Engine`s registered on the `Environment`.
3030
# If an `ext` argument is supplied, the `Engine` associated with
3131
# that extension will be returned.
3232
#
3333
# environment.engines
34-
# # => {".coffee" => CoffeeScriptTemplate, ".sass" => SassTemplate, ...}
34+
# # => {".coffee" => CoffeeScriptProcessor, ".sass" => SassProcessor, ...}
3535
#
3636
attr_reader :engines
3737

@@ -56,7 +56,7 @@ def unwrap_engines(extnames)
5656
# Registers a new Engine `klass` for `ext`. If the `ext` already
5757
# has an engine registered, it will be overridden.
5858
#
59-
# environment.register_engine '.coffee', CoffeeScriptTemplate
59+
# environment.register_engine '.coffee', CoffeeScriptProcessor
6060
#
6161
def register_engine(ext, klass, options = {})
6262
ext = Sprockets::Utils.normalize_extension(ext)

lib/sprockets/erb_processor.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'erb'
2+
3+
module Sprockets
4+
class ERBProcessor
5+
def self.call(input)
6+
new.call(input)
7+
end
8+
9+
def initialize(&block)
10+
@block = block
11+
end
12+
13+
def call(input)
14+
engine = ::ERB.new(input[:data], nil, '<>')
15+
context = input[:environment].context_class.new(input)
16+
klass = (class << context; self; end)
17+
klass.class_eval(&@block) if @block
18+
engine.def_method(klass, :_evaluate_template, input[:filename])
19+
data = context._evaluate_template
20+
context.metadata.merge(data: data)
21+
end
22+
end
23+
end

lib/sprockets/erb_template.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
require 'erb'
1+
require 'sprockets/erb_processor'
22

33
module Sprockets
4-
class ERBTemplate
5-
def self.call(input)
6-
new.call(input)
7-
end
8-
9-
def initialize(&block)
10-
@block = block
11-
end
12-
13-
def call(input)
14-
engine = ::ERB.new(input[:data], nil, '<>')
15-
context = input[:environment].context_class.new(input)
16-
klass = (class << context; self; end)
17-
klass.class_eval(&@block) if @block
18-
engine.def_method(klass, :_evaluate_template, input[:filename])
19-
data = context._evaluate_template
20-
context.metadata.merge(data: data)
21-
end
22-
end
4+
# Deprecated
5+
ERBTemplate = ERBProcessor
236
end

lib/sprockets/lazy_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Sprockets
22
# Internal: Used for lazy loading processors.
33
#
4-
# LazyProcessor.new { CoffeeScriptTemplate }
4+
# LazyProcessor.new { CoffeeScriptProcessor }
55
#
66
class LazyProcessor
77
def initialize(&block)

lib/sprockets/legacy_tilt_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Sprockets
66
#
77
# Will be removed in Sprockets 4.x.
88
#
9-
# LegacyTiltProcessor.new(Tilt::CoffeeScriptTemplate)
9+
# LegacyTiltProcessor.new(Tilt::CoffeeScriptProcessor)
1010
#
1111
class LegacyTiltProcessor < Delegator
1212
def initialize(klass)

lib/sprockets/sass_cache_store.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Deprecated: Require sprockets/sass_template instead
2-
require 'sprockets/sass_template'
1+
# Deprecated: Require sprockets/sass_processor instead
2+
require 'sprockets/sass_processor'

lib/sprockets/sass_functions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Deprecated: Require sprockets/sass_template instead
2-
require 'sprockets/sass_template'
1+
# Deprecated: Require sprockets/sass_processor instead
2+
require 'sprockets/sass_processor'

lib/sprockets/sass_importer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Deprecated: Require sprockets/sass_template instead
2-
require 'sprockets/sass_template'
1+
# Deprecated: Require sprockets/sass_processor instead
2+
require 'sprockets/sass_processor'

0 commit comments

Comments
 (0)