Class: MabTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/mab/tilt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.builder_classObject



2
3
4
5
6
7
8
9
10
# File 'lib/mab/tilt.rb', line 2

def self.builder_class
  @builder_class ||= Class.new(Mab::Builder) do
    def __capture_mab_tilt__(&block)
      __run_mab_tilt__ do
        text capture(&block)
      end
    end
  end
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mab/tilt.rb', line 15

def evaluate(scope, locals, &block)
  builder = self.class.builder_class.new({}, scope)

  locals.each do |local, value|
    (class << builder; self end).send(:define_method, local, Proc.new { value })
  end

  if data.kind_of? Proc
    (class << builder; self end).send(:define_method, :__run_mab_tilt__, &data)
  else
    builder.instance_eval <<-CODE, __FILE__, __LINE__
      def __run_mab_tilt__
        capture(&Proc.new {#{data}})
      end
    CODE
  end

  if block
    builder.__capture_mab_tilt__(&block)
  else
    builder.__run_mab_tilt__
  end

  builder
end

#prepareObject



12
13
# File 'lib/mab/tilt.rb', line 12

def prepare
end