Class: Twiddler::Rendering

Inherits:
Object
  • Object
show all
Defined in:
lib/twiddler/rendering.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Rendering

Returns a new instance of Rendering.



5
6
7
# File 'lib/twiddler/rendering.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#embed(name) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/twiddler/rendering.rb', line 9

def embed(name)
  path = template_path(name)
  template = File::read(path)
  erb = ERB.new(template, nil, "%>")
  erb.filename = path
  mod = erb.def_module("render")
  @config.extend(mod)
end

#template_path(name) ⇒ Object



18
19
20
21
# File 'lib/twiddler/rendering.rb', line 18

def template_path(name)
  path = File::expand_path("../../templates/#{name}.erb", 
                           File::dirname(__FILE__))
end