Class: Malt::Engine::Markaby

Inherits:
Abstract show all
Defined in:
lib/malt/engines/markaby.rb

Overview

Markaby

Markaby doesn’t support template caching b/c the the initializer takes the local variable settings.

Instance Attribute Summary

Attributes inherited from Abstract

#settings

Instance Method Summary collapse

Methods inherited from Abstract

#cache?, #create_engine, default, #initialize, register, type

Constructor Details

This class inherits a constructor from Malt::Engine::Abstract

Instance Method Details

#prepare_engine(params = {}, &content) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/malt/engines/markaby.rb', line 32

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

#render(params = {}, &content) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/malt/engines/markaby.rb', line 18

def render(params={}, &content)
  into = parameters(params, :to) || :html

  case into
  when :html, :xml, :xhtml
    prepare_engine(params, &content).to_s
  else
    super(params, &content)
  end
end