Class: Tilt::MarkabyTemplate

Inherits:
Template show all
Defined in:
lib/tilt/markaby.rb

Overview

Instance Attribute Summary

Attributes inherited from Template

#compiled_path, #data, #file, #line, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Template

#basename, #compiled_method, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Class Method Details

.builder_classObject



9
10
11
12
13
14
15
16
17
# File 'lib/tilt/markaby.rb', line 9

def self.builder_class
  @builder_class ||= Class.new(Markaby::Builder) do
    def __capture_markaby_tilt__(&block)
      __run_markaby_tilt__ do
        text capture(&block)
      end
    end
  end
end

Instance Method Details

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



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

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

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

  if block
    builder.__capture_markaby_tilt__(&block)
  else
    builder.__run_markaby_tilt__
  end

  builder.to_s
end