class EZML::Engine
Attributes
indentation[RW]
options[RW]
Public Class Methods
new(template, options = {})
click to toggle source
# File lib/ezml/engine.rb, line 28 def initialize(template, options = {}) @options = Options.new(options) @template = check_ezml_encoding(template) do |msg, line| raise EZML::Error.new(msg, line) end @template_engine = TemplateEngine.new(options) @template_engine.compile(@template) end
Public Instance Methods
compiler()
click to toggle source
Deprecated
# File lib/ezml/engine.rb, line 40 def compiler @template_engine end
def_method(object, name, *local_names)
click to toggle source
# File lib/ezml/engine.rb, line 91 def def_method(object, name, *local_names) method = object.is_a?(Module) ? :module_eval : :instance_eval object.send(method, "def #{name}(_ezml_locals = {}); #{@template_engine.precompiled_with_ambles(local_names)}; end", @options.filename, @options.line) end
options_for_buffer()
click to toggle source
# File lib/ezml/engine.rb, line 24 def options_for_buffer @options.for_buffer end
render(scope = Object.new, locals = {}, &block)
click to toggle source
# File lib/ezml/engine.rb, line 44 def render(scope = Object.new, locals = {}, &block) parent = scope.instance_variable_defined?(:@ezml_buffer) ? scope.instance_variable_get(:@ezml_buffer) : nil buffer = EZML::Buffer.new(parent, @options.for_buffer) if scope.is_a?(Binding) scope_object = eval("self", scope) scope = scope_object.instance_eval{binding} if block_given? else scope_object = scope scope = scope_object.instance_eval{binding} end set_locals(locals.merge(:_ezmlout => buffer, :_erbout => buffer.buffer), scope, scope_object) scope_object.extend(EZML::Helpers) scope_object.instance_variable_set(:@ezml_buffer, buffer) begin eval(@template_engine.precompiled_with_return_value, scope, @options.filename, @options.line) rescue ::SyntaxError => e raise SyntaxError, e.message end ensure scope_object.instance_variable_set(:@ezml_buffer, buffer.upper) if buffer end
Also aliased as: to_html
render_proc(scope = Object.new, *local_names)
click to toggle source
# File lib/ezml/engine.rb, line 70 def render_proc(scope = Object.new, *local_names) if scope.is_a?(Binding) scope_object = eval("self", scope) else scope_object = scope scope = scope_object.instance_eval{binding} end begin str = @template_engine.precompiled_with_ambles(local_names) eval( "Proc.new { |*_ezml_locals| _ezml_locals = _ezml_locals[0] || {}; #{str}}\n", scope, @options.filename, @options.line ) rescue ::SyntaxError => e raise SyntaxError, e.message end end
Private Instance Methods
set_locals(locals, scope, scope_object)
click to toggle source
# File lib/ezml/engine.rb, line 100 def set_locals(locals, scope, scope_object) scope_object.instance_variable_set :@_ezml_locals, locals set_locals = locals.keys.map { |k| "#{k} = @_ezml_locals[#{k.inspect}]" }.join("\n") eval(set_locals, scope) end