lib/malt/engines/haml.rb in malt-0.3.0 vs lib/malt/engines/haml.rb in malt-0.4.0
- old
+ new
@@ -7,58 +7,34 @@
class Haml < Abstract
default :haml
#
- def render(params, &yld)
- into = params[:to]
+ def render(params={}, &content)
+ into, scope, locals = parameters(params, :to, :scope, :locals)
+
+ scope, locals = make_ready(scope, locals, &content)
+
case into
when :html, nil
- render_html(params, &yld)
+ prepare_engine(params, &content).render(scope, locals, &content)
else
- super(params, &yld)
+ super(params, &content)
end
end
#
- def render_html(params, &yld)
- text = params[:text]
- file = params[:file]
- data = params[:data]
-
- engine = intermediate(params)
- case data
- when Binding
- html = engine.render(make_object(data), &yld)
- when Hash
- html = engine.render(Object.new, data, &yld)
- else
- if data.respond_to?(:to_hash)
- data = data.to_hash
- html = engine.render(Object.new, data, &yld)
- else
- html = engine.render(data || Object.new, &yld)
- end
+ def create_engine(params={})
+ text, file = parameters(params, :text, :file)
+ cached(text, file) do
+ ::Haml::Engine.new(text, :filename=>file)
end
- html
end
- #
- #def compile(text, file)
- # intermediate # ??
- #end
+ private
- #
- def intermediate(params)
- text = params[:text]
- file = params[:file]
- ::Haml::Engine.new(text, :filename=>file)
- end
-
- private
-
# Load Haml library if not already loaded.
- def initialize_engine
+ def require_engine
return if defined? ::Haml::Engine
require_library 'haml'
end
end