lib/malt/engines/markaby.rb in malt-0.3.0 vs lib/malt/engines/markaby.rb in malt-0.4.0
- old
+ new
@@ -2,50 +2,72 @@
module Malt::Engine
# Markaby
#
- # http://markaby.rubyforge.org/
+ # @see http://markaby.rubyforge.org/
#
+ # Markaby doesn't support template caching b/c the the initializer
+ # takes the local variable settings.
+ #
class Markaby < Abstract
- default :markaby, :mab
+ default :markaby, :mab
+ register :rbml, :builder
#
- #def intermediate(params)
- # text = params[:text]
- # eval("lambda{ #{text} }")
- #end
+ def render(params={}, &content)
+ into = parameters(params, :to) || :html
- #
- def render(params, &yld)
- into = params[:to]
case into
- when :html, nil
- render_html(params, &yld)
+ when :html, :xml, :xhtml
+ prepare_engine(params, &content).to_s
else
- super(params, &yld)
+ super(params, &content)
end
end
+ # TODO: Prefix support ?
+
#
- def render_html(params={}, &yld)
- text = params[:text]
- file = params[:file]
- data = params[:data]
- data = make_hash(data, &yld)
- builder = ::Markaby::Builder.new(data)
- builder.instance_eval(text).to_s
+ def prepare_engine(params={}, &content)
+ prefix, text, file, scope, locals, prefix = parameters(params, :prefix, :text, :file, :scope, :locals)
+
+ file = file || "(markaby)"
+
+ if prefix
+ raise NotImplmentedError, "Markaby doesn't support prefix templates."
+ #scope, locals = scope_and_locals(data, &content)
+ #scope, locals = split_data(data)
+
+ scope ||= Object.new
+ locals ||= {}
+
+ mab = ::Markaby::Builder.new(locals) #, scope)
+
+ code = %{
+ lambda do |#{prefix}|
+ #{text}
+ end
+ }
+
+ eval(code, scope.to_binding, file).call(mab)
+ else
+ scope, locals = make_external(scope, locals, &content)
+
+ mab = ::Markaby::Builder.new(locals, scope)
+ mab.instance_eval(text, file)
+ mab
+ end
end
- private
+ private
# Load Markaby library if not already loaded.
- def initialize_engine
+ def require_engine
return if defined? ::Markaby
require_library 'markaby'
end
end
end
-