Class: RbTmpl::Tmpl

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-tmpl.rb

Defined Under Namespace

Classes: HashWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTmpl

Returns a new instance of Tmpl.



8
9
10
11
12
13
14
# File 'lib/rb-tmpl.rb', line 8

def initialize
	@template_search_paths = []
	@template_extensions = []

	@templates = {}
	@compiled_templates = {}
end

Instance Attribute Details

#template_extensionsObject (readonly)

Returns the value of attribute template_extensions.



6
7
8
# File 'lib/rb-tmpl.rb', line 6

def template_extensions
  @template_extensions
end

#template_search_pathsObject (readonly)

Returns the value of attribute template_search_paths.



5
6
7
# File 'lib/rb-tmpl.rb', line 5

def template_search_paths
  @template_search_paths
end

Instance Method Details

#add(name, template) ⇒ Object



16
17
18
19
20
# File 'lib/rb-tmpl.rb', line 16

def add(name, template)
	name = name.to_s
	@templates[name] = template
	@compiled_templates.delete(name)
end

#call(name, data = nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rb-tmpl.rb', line 22

def call(name, data = nil)
	name = name.to_s
	code = compiled(name)
	return '' if code.nil?
	data = HashWrapper.new(data) if data.kind_of?(Hash)
	bind = data.instance_eval{ binding } unless data.nil?
	eval(code, bind)
end