Class: REGO::Block::Template

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

Direct Known Subclasses

Body, Head, Html

Instance Method Summary collapse

Constructor Details

#initialize(env, &block) ⇒ Template

Returns a new instance of Template.



10
11
12
13
14
15
# File 'lib/rego/block/template.rb', line 10

def initialize( env, &block )
	@env = env
	@child = []
	instance_eval( &block ) if block_given?
	self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rego/block/template.rb', line 21

def method_missing( name, *args, &block )
	if block
		begin
			klass = REGO::Block::const_get( name.to_s.capitalize )
			@child << klass::new( @env, &block ).result
		rescue NameError
			begin
				require name.to_s
			rescue LoadError
				require "rego/block/#{name}"
			end
			retry
		end
	else
		instance_variable_set "@#{name}", args[0]
	end
	self
end

Instance Method Details

#resultObject



17
18
19
# File 'lib/rego/block/template.rb', line 17

def result
	@child.join( "\n" )
end