Skip to content

Commit

Permalink
Add support for .jst.eco assets when the eco gem is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Jun 5, 2011
1 parent 68cca18 commit 18ebc05
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/sprockets/eco_template.rb
@@ -0,0 +1,20 @@
require 'tilt'

module Sprockets
class EcoTemplate < Tilt::Template
def self.default_mime_type
'application/javascript'
end

def initialize_engine
require_template_library 'eco'
end

def prepare
end

def evaluate(scope, locals, &block)
Eco.compile(data)
end
end
end
4 changes: 3 additions & 1 deletion lib/sprockets/engines.rb
@@ -1,3 +1,4 @@
require 'sprockets/eco_template'
require 'sprockets/ejs_template'
require 'sprockets/jst_processor'
require 'sprockets/utils'
Expand Down Expand Up @@ -28,8 +29,9 @@ def register_engine(ext, klass)
extend Engines

register_engine '.coffee', Tilt::CoffeeScriptTemplate
register_engine '.erb', Tilt::ERBTemplate
register_engine '.eco', EcoTemplate
register_engine '.ejs', EjsTemplate
register_engine '.erb', Tilt::ERBTemplate
register_engine '.jst', JstProcessor
register_engine '.less', Tilt::LessTemplate
register_engine '.sass', Tilt::SassTemplate
Expand Down
1 change: 1 addition & 0 deletions sprockets.gemspec
Expand Up @@ -11,6 +11,7 @@ Gem::Specification.new do |s|
s.add_dependency "tilt", ["~> 1.1", "!= 1.3.0"]

s.add_development_dependency "coffee-script", "~> 2.0"
s.add_development_dependency "eco", "~> 1.0"
s.add_development_dependency "ejs", "~> 1.0"
s.add_development_dependency "execjs", "~> 1.0"
s.add_development_dependency "json"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/default/goodbye.jst.eco
@@ -0,0 +1 @@
Goodbye <%= @name %>
9 changes: 8 additions & 1 deletion test/test_environment.rb
Expand Up @@ -51,9 +51,16 @@ def self.test(name, &block)
end
end

test "eco templates" do
asset = @env["goodbye.jst"]
context = ExecJS.compile("var window = this; #{asset}")
assert_equal "Goodbye world\n", context.call("JST['goodbye']", :name => "world")
end

test "ejs templates" do
asset = @env["hello.jst"]
assert_equal "window.JST || (window.JST = {});\nwindow.JST[\"hello\"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('hello: ', name ,'\\n');}return __p.join('');};\n", asset.to_s
context = ExecJS.compile("var window = this; #{asset}")
assert_equal "hello: world\n", context.call("JST['hello']", :name => "world")
end

test "lookup mime type" do
Expand Down

0 comments on commit 18ebc05

Please sign in to comment.