lib/malt/engines/mustache.rb in malt-0.3.0 vs lib/malt/engines/mustache.rb in malt-0.4.0
- old
+ new
@@ -2,38 +2,44 @@
module Malt::Engine
# Mustache engine.
#
- # http://github.com/defunkt/mustache
+ # @see http://github.com/defunkt/mustache
#
class Mustache < Abstract
register :mustache
- ## Convert Markdown text to intermediate object.
- #def intermediate(params)
- # text = params[:text]
- # ???
- #end
-
#
- def render(params={}, &yld) #file, db, &yld)
- text = params[:text]
- data = params[:data]
+ def render(params={}, &content) #file, db, &content)
+ text, scope, locals = parameters(params, :text, :scope, :locals)
- data = make_hash(data, &yld)
+ locals = make_hash(scope, locals, &content)
+ # convert symbol keys to strings w/o rewriting the hash
+ symbol_keys = locals.keys.select{ |k| Symbol === k }
+ symbol_keys.each do |k|
+ locals[k.to_s] = locals[k]
+ locals.delete(k)
+ end
+
#engine = intermediate(params)
#engine.render(data)
- ::Mustache.render(text, data)
+
+ ::Mustache.render(text, locals)
end
+ #
+ #def intermediate(params)
+ # text = parameters(params, :text)
+ # ???
+ #end
- private
+ private
# Load rdoc makup library if not already loaded.
- def initialize_engine
+ def require_engine
return if defined? ::Mustache
require_library 'mustache'
end
end