Class: Newgem::QuickTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/newgem/quick_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ QuickTemplate

Returns a new instance of QuickTemplate.



6
7
8
9
# File 'lib/newgem/quick_template.rb', line 6

def initialize(file)
  @file = file
  @text = File.read(file)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/newgem/quick_template.rb', line 5

def args
  @args
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/newgem/quick_template.rb', line 5

def file
  @file
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/newgem/quick_template.rb', line 5

def text
  @text
end

Instance Method Details

#exec(b) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/newgem/quick_template.rb', line 10

def exec(b)
  begin
    # b = binding
    template = ERB.new(@text, 0, "%<>")
    result = template.result(b)
    # Chomp the trailing newline
    result.gsub(/\n$/,'')
  rescue NameError
    puts "Error found for #{file}"
    raise $!
  end
end