Class: FuzzBert::Template

Inherits:
Object
  • Object
show all
Includes:
Generation
Defined in:
lib/fuzzbert/template.rb

Defined Under Namespace

Classes: Identifier, Parser, Text

Instance Method Summary collapse

Methods included from Generation

#generator

Constructor Details

#initialize(template) ⇒ Template

Returns a new instance of Template.



6
7
8
9
# File 'lib/fuzzbert/template.rb', line 6

def initialize(template)
  @template = Parser.new(template).parse
  @callbacks = {}
end

Instance Method Details

#set(name, cb = nil, &blk) ⇒ Object



11
12
13
# File 'lib/fuzzbert/template.rb', line 11

def set(name, cb=nil, &blk)
  @callbacks[name] = cb || blk
end

#to_dataObject



15
16
17
18
19
# File 'lib/fuzzbert/template.rb', line 15

def to_data
  "".tap do |buf|
    @template.each { |t| buf << t.to_data(@callbacks).to_s }
  end
end