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.



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

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.



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

def args
  @args
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#extensionObject (readonly)

Returns the value of attribute extension.



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

def extension
  @extension
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#import_baseObject

Returns the value of attribute import_base.



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

def import_base
  @import_base
end

Instance Method Details

#render(args = {}) ⇒ Object



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

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