Permalink
Browse files

Implement render instead of evaluate

  • Loading branch information...
1 parent 314734e commit 79d5fa7bdeb10b8c2d0525fe6bb1b9812366b41a @josh josh committed Dec 19, 2013
@@ -17,7 +17,7 @@ module Sprockets
# environment.unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
#
class CharsetNormalizer < Template
- def evaluate(context, locals, &block)
+ def render(context)
charset = nil
# Find and strip out any `@charset` definitions
@@ -10,7 +10,7 @@ def initialize_engine
require 'closure-compiler'
end
- def evaluate(context, locals, &block)
+ def render(context)
Closure::Compiler.new.compile(data)
end
end
@@ -10,7 +10,7 @@ def initialize_engine
require 'coffee_script'
end
- def evaluate(scope, locals, &block)
+ def render(context)
@output ||= CoffeeScript.compile(data)
end
end
@@ -194,7 +194,7 @@ def evaluate(path, options = {})
processors.each do |processor|
begin
template = processor.new(pathname.to_s) { result }
- result = template.render(self, {})
+ result = template.render(self)
rescue Exception => e
annotate_exception! e
raise
@@ -80,12 +80,10 @@ def prepare
@included_pathnames = []
end
- # Implemented for Template#render.
- #
# `context` is a `Context` instance with methods that allow you to
# access the environment and append to the bundle. See `Context`
# for the complete API.
- def evaluate(context, locals, &block)
+ def render(context)
@context = context
@result = ""
@@ -26,7 +26,7 @@ def initialize_engine
#
# # => "function(...) {...}"
#
- def evaluate(scope, locals, &block)
+ def render(context)
Eco.compile(data)
end
end
@@ -25,7 +25,7 @@ def initialize_engine
#
# # => "function(obj){...}"
#
- def evaluate(scope, locals, &block)
+ def render(context)
EJS.compile(data)
end
end
@@ -8,12 +8,12 @@ def initialize_engine
require 'erb'
end
- def evaluate(scope, locals, &block)
+ def render(context)
engine = ::ERB.new(data, nil, '<>')
method_name = "__sprockets_#{Thread.current.object_id.abs}"
- klass = (class << scope; self; end)
+ klass = (class << context; self; end)
engine.def_method(klass, method_name, file)
- scope.send(method_name)
+ context.send(method_name)
end
end
end
@@ -6,10 +6,10 @@ def self.default_namespace
'this.JST'
end
- def evaluate(scope, locals, &block)
+ def render(context)
namespace = self.class.default_namespace
<<-JST
-(function() { #{namespace} || (#{namespace} = {}); #{namespace}[#{scope.logical_path.inspect}] = #{indent(data)};
+(function() { #{namespace} || (#{namespace} = {}); #{namespace}[#{context.logical_path.inspect}] = #{indent(data)};
}).call(this);
JST
end
@@ -10,7 +10,7 @@ def initialize_engine
require 'less'
end
- def evaluate(scope, locals, &block)
+ def render(context)
if ::Less.const_defined? :Engine
engine = ::Less::Engine.new(data)
else
@@ -30,7 +30,7 @@ def self.to_s
end
# Call processor block with `context` and `data`.
- def evaluate(context, locals)
+ def render(context)
self.class.processor.call(context, data)
end
end
@@ -10,7 +10,7 @@ module Sprockets
# environment.unregister_postprocessor 'application/javascript', Sprockets::SafetyColons
#
class SafetyColons < Template
- def evaluate(context, locals, &block)
+ def render(context)
# If the file is blank or ends in a semicolon, leave it as is
if data =~ /\A\s*\Z/m || data =~ /;\s*\Z/m
data
@@ -10,7 +10,7 @@ def initialize_engine
require 'sass'
end
- def evaluate(context, locals, &block)
+ def render(context)
::Sass::Engine.new(data, {
:syntax => :scss,
:cache => false,
@@ -24,7 +24,7 @@ def syntax
:sass
end
- def evaluate(context, locals, &block)
+ def render(context)
# Use custom importer that knows about Sprockets Caching
cache_store = SassCacheStore.new(context.environment)
@@ -22,9 +22,5 @@ def initialize(file, &block)
prepare if respond_to?(:prepare)
end
-
- def render(scope = Object.new, locals = {})
- evaluate(scope, locals)
- end
end
end
@@ -10,7 +10,7 @@ def initialize_engine
require 'uglifier'
end
- def evaluate(context, locals, &block)
+ def render(context)
# Feature detect Uglifier 2.0 option support
if Uglifier::DEFAULTS[:copyright]
# Uglifier < 2.x
@@ -8,7 +8,7 @@ def initialize_engine
require 'yui/compressor'
end
- def evaluate(context, locals, &block)
+ def render(context)
case context.content_type
when 'application/javascript'
YUI::JavaScriptCompressor.new.compress(data)
@@ -60,7 +60,7 @@ def initialize_engine
require 'yaml'
end
- def evaluate(context, locals)
+ def render(context)
manifest = YAML.load(data)
manifest['require'].each do |logical_path|
context.require_asset(logical_path)
@@ -80,7 +80,7 @@ def initialize_engine
require 'base64'
end
- def evaluate(context, locals)
+ def render(context)
data.gsub(/url\(\"(.+?)\"\)/) do
path = context.resolve($1)
context.depend_on(path)
@@ -6,13 +6,13 @@ def self.default_mime_type
'application/javascript'
end
- def evaluate(scope, locals, &block)
+ def render(context)
"alert(#{data.inspect});"
end
end
class StringTemplate < Sprockets::Template
- def evaluate(scope, locals, &block)
+ def render(context)
data.gsub(/#\{.*?\}/, "moo")
end
end
View
@@ -213,7 +213,7 @@ class TestSassCompressor < TestBaseSass
silence_warnings do
uncompressed = "p {\n margin: 0;\n padding: 0;\n}\n"
compressed = "p{margin:0;padding:0}\n"
- assert_equal compressed, Sprockets::SassCompressor.new("foo.css") { uncompressed }.render
+ assert_equal compressed, Sprockets::SassCompressor.new("foo.css") { uncompressed }.render(Object.new)
end
end
end

0 comments on commit 79d5fa7

Please sign in to comment.