Class: Kojo::Template

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

Overview

The Template class handles a single template file, and processes it for:

  • Variables (using %{var} syntax)

  • ERB

  • @import statements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Template

Returns a new instance of Template.



13
14
15
16
17
18
# File 'lib/kojo/template.rb', line 13

def initialize(file)
  @file = file
  @extension = File.extname file
  @dir = File.dirname file
  @import_base = dir
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/kojo/template.rb', line 10

def args
  @args
end

#dirObject (readonly)

Returns the value of attribute dir.



10
11
12
# File 'lib/kojo/template.rb', line 10

def dir
  @dir
end

#extensionObject (readonly)

Returns the value of attribute extension.



10
11
12
# File 'lib/kojo/template.rb', line 10

def extension
  @extension
end

#fileObject (readonly)

Returns the value of attribute file.



10
11
12
# File 'lib/kojo/template.rb', line 10

def file
  @file
end

#import_baseObject

Returns the value of attribute import_base.



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

def import_base
  @import_base
end

Instance Method Details

#render(args = {}) ⇒ Object



20
21
22
23
# File 'lib/kojo/template.rb', line 20

def render(args={})
  @args = args
  evaluate file
end