lib/tilt.rb in tilt-0.5 vs lib/tilt.rb in tilt-0.6
- old
+ new
@@ -1,7 +1,7 @@
module Tilt
- VERSION = '0.5'
+ VERSION = '0.6'
@template_mappings = {}
# Hash of template path pattern => template implementation
# class mappings.
@@ -75,10 +75,11 @@
options, line = line, 1 if line.is_a?(Hash)
@file = file
@line = line || 1
@options = options || {}
@reader = block || lambda { |t| File.read(file) }
+ @data = nil
if !self.class.engine_initialized
initialize_engine
self.class.engine_initialized = true
end
@@ -398,13 +399,12 @@
locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
if scope.respond_to?(:to_h)
scope = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
locals = scope.merge(locals)
end
- # TODO: Is it possible to lazy yield ?
locals['yield'] = block.nil? ? '' : yield
- locals['content'] = block.nil? ? '' : yield
+ locals['content'] = locals['yield']
@engine.render(locals)
end
end
register 'liquid', LiquidTemplate
@@ -435,26 +435,26 @@
register 'markdown', RDiscountTemplate
register 'mkd', RDiscountTemplate
register 'md', RDiscountTemplate
-# RedCloth implementation. See:
-# http://redcloth.org/
-class RedClothTemplate < Template
- def initialize_engine
- require_template_library 'redcloth' unless defined? ::RedCloth
- end
+ # RedCloth implementation. See:
+ # http://redcloth.org/
+ class RedClothTemplate < Template
+ def initialize_engine
+ require_template_library 'redcloth' unless defined? ::RedCloth
+ end
- def compile!
- @engine = RedCloth.new(data)
- end
+ def compile!
+ @engine = RedCloth.new(data)
+ end
- def evaluate(scope, locals, &block)
- @engine.to_html
+ def evaluate(scope, locals, &block)
+ @engine.to_html
+ end
end
-end
-register 'textile', RedClothTemplate
+ register 'textile', RedClothTemplate
# Mustache is written and maintained by Chris Wanstrath. See:
# http://github.com/defunkt/mustache
#
@@ -468,13 +468,14 @@
require_template_library 'mustache' unless defined? ::Mustache
end
def compile!
Mustache.view_namespace = options[:namespace]
+ Mustache.view_path = options[:view_path] || options[:mustaches]
@engine = options[:view] || Mustache.view_class(name)
options.each do |key, value|
- next if %w[view namespace mustaches].include?(key.to_s)
+ next if %w[view view_path namespace mustaches].include?(key.to_s)
@engine.send("#{key}=", value) if @engine.respond_to? "#{key}="
end
end
def evaluate(scope=nil, locals={}, &block)
@@ -523,6 +524,23 @@
def evaluate(scope, locals, &block)
@engine.to_s
end
end
register 'rdoc', RDocTemplate
+
+ # CoffeeScript info:
+ # http://jashkenas.github.com/coffee-script/
+ class CoffeeTemplate < Template
+ def initialize_engine
+ require_template_library 'coffee-script' unless defined? ::CoffeeScript
+ end
+
+ def compile!
+ @engine = ::CoffeeScript::compile(data, options)
+ end
+
+ def evaluate(scope, locals, &block)
+ @engine
+ end
+ end
+ register 'coffee', CoffeeTemplate
end