lib/malt/engines/erubis.rb in malt-0.3.0 vs lib/malt/engines/erubis.rb in malt-0.4.0
- old
+ new
@@ -8,56 +8,66 @@
#
# Erubis is essentially compatibel with ERB, but it is faster.
#
class Erubis < Abstract
- register :erb, :rhtml
+ register :erb, :rhtml, :eruby
# Render template.
- def render(params, &yld)
- text = params[:text]
- data = params[:data]
- data = make_binding(data, &yld)
- intermediate(params).result(data)
- end
+ def render(params, &content)
+ text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
- # Compile template into Ruby source code.
- def compile(params)
- text = params[:text]
- file = params[:file]
- intermediate(text, file).src
- end
+ # NOTE: Erubis can handle hash data via result(:list=>data).
+ # Would it be better to use that?
- #
- def intermediate(params)
- text = params[:text]
- file = params[:file]
+ bind = make_binding(scope, locals, &content)
- opts = {}
-
- if params[:escape_html] || settings[:escape_html]
- ::Erubis::EscapedEruby.new(text, settings)
- else
- ::Erubis::Eruby.new(text, settings)
- end
+ prepare_engine(params).result(bind)
end
#
- def safe
- options[:safe]
- end
+ #def prepare_eninge(params={})
+ # create_engine(params)
+ #end
#
- def trim
- options[:trim]
+ def create_engine(params={})
+ text, file, esc = parameters(params, :text, :file, :escape_html)
+
+ opts = engine_options(params)
+
+ cached(text, file, esc, opts) do
+ if esc
+ ::Erubis::EscapedEruby.new(text, opts)
+ else
+ ::Erubis::Eruby.new(text, opts)
+ end
+ end
end
- ;;;; private ;;;;
+ # Compile template into Ruby source code.
+ #def compile(params)
+ # if cache?
+ # @source[params] ||= intermediate(params).src
+ # else
+ # intermediate(params).src
+ # end
+ #end
+ private
+
# Load ERB library if not already loaded.
- def initialize_engine
+ def require_engine
return if defined? ::Erubius
require_library('erubis')
+ end
+
+ #
+ ENGINE_OPTION_NAMES = %w{safe trim pattern preamble postable}
+
+ #
+ def engine_option_names
+ ENGINE_OPTION_NAMES
end
end
end