Class: DatabaseLoader::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/database_loader/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Template

Returns a new instance of Template.



5
6
7
# File 'lib/database_loader/template.rb', line 5

def initialize(contents)
  self.contents = contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



3
4
5
# File 'lib/database_loader/template.rb', line 3

def contents
  @contents
end

Instance Method Details

#render(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/database_loader/template.rb', line 9

def render(options = {})
  case DatabaseLoader.template_engine
  when :liquid
    require "liquid"
    Liquid::Template.parse(contents).render(options)
  when :erb
    require "erb"
    struct = OpenStruct.new(options)
    ERB.new(contents).result(struct.send(:binding))
  when :erubis
    require "erubis"
    struct = OpenStruct.new(options)
    Erubis::Eruby.new(contents).result(struct.send(:binding))
  else
    contents
  end
end