Class: Rdm::Support::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmpl_path = nil) ⇒ Template

Returns a new instance of Template.



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

def initialize(tmpl_path = nil)
  @tmpl_path = construct_path(tmpl_path)
end

Instance Attribute Details

#tmpl_pathObject

Returns the value of attribute tmpl_path.



4
5
6
# File 'lib/rdm/support/template.rb', line 4

def tmpl_path
  @tmpl_path
end

Instance Method Details

#construct_path(some_path = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rdm/support/template.rb', line 15

def construct_path(some_path = nil)
  Pathname.new(
    File.expand_path(
      (some_path || default_templates_path)
    )
  )
end

#content(file, locals = {}) ⇒ Object



9
10
11
12
13
# File 'lib/rdm/support/template.rb', line 9

def content(file, locals = {})
  path    = tmpl_path.join(file)
  content = File.read(path)
  Rdm::Support::Render.render(content, locals)
end

#default_templates_pathObject



23
24
25
26
27
# File 'lib/rdm/support/template.rb', line 23

def default_templates_path
  File.expand_path(
    File.join(File.dirname(__FILE__), '..', 'templates')
  )
end