class Malt::Engine::Nokogiri
Nokogiri
builder-like templates.
@see nokogiri.org/
Constants
- DOCUMENT_HEADER_HTML
- DOCUMENT_HEADER_XML
Public Instance Methods
create_engine(params={})
click to toggle source
Nokogiri
engine cannot be cached as it keeps a copy the rendering internally. (Unless there is a way to clear it?)
# File lib/malt/engines/nokogiri.rb, line 60 def create_engine(params={}) into = parameters(params, :to) || :html opts = engine_options(params) #cached(into, opts) do case into when :html ::Nokogiri::HTML::Builder.new(opts) else ::Nokogiri::XML::Builder.new(opts) end #end end
prepare_engine(params={}, &content)
click to toggle source
# File lib/malt/engines/nokogiri.rb, line 35 def prepare_engine(params={}, &content) text, file, scope, locals = parameters(params, :text, :file, :scope, :locals) scope, locals = make_external(scope, locals, &content) engine = create_engine(params) locals.each do |k,v| engine.instance_eval("@#{k} = v") end scope.instance_variables.each do |k| next if k == "@target" v = scope.instance_variable_get(k) engine.instance_eval("#{k} = v") end engine.instance_eval(text, file || inspect) engine end
render(params={}, &content)
click to toggle source
Calls superclass method
Malt::Engine::Abstract#render
# File lib/malt/engines/nokogiri.rb, line 21 def render(params={}, &content) into = parameters(params, :to) || :html case into.to_sym when :html prepare_engine(params, &content).to_html.sub(DOCUMENT_HEADER_HTML,'') when :xml, :xhtml prepare_engine(params, &content).to_xml.sub(DOCUMENT_HEADER_XML,'') else super(params, &content) end end
Private Instance Methods
require_engine()
click to toggle source
Load Nokogiri
library if not already loaded.
# File lib/malt/engines/nokogiri.rb, line 78 def require_engine return if defined? ::Nokogiri require_library 'nokogiri' ::Nokogiri::XML::Builder.class_eval do undef_method :p end end