Class: Utopia::Etanni

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/etanni.rb

Constant Summary collapse

SEPARATOR =
Digest::MD5.hexdigest(Time.new.to_s)
START =
"\n_out_ << <<#{SEPARATOR}.chomp!\n"
STOP =
"\n#{SEPARATOR}\n"
REPLACEMENT =
"#{STOP}\\1#{START}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, compiled = false) ⇒ Etanni

Returns a new instance of Etanni.



34
35
36
37
38
39
40
41
# File 'lib/utopia/etanni.rb', line 34

def initialize(template, compiled = false)
	if compiled
		@compiled = template
	else
		@template = template
		compile!
	end
end

Instance Attribute Details

#compiledObject (readonly)

Returns the value of attribute compiled.



54
55
56
# File 'lib/utopia/etanni.rb', line 54

def compiled
  @compiled
end

Instance Method Details

#compile!Object



43
44
45
46
47
48
# File 'lib/utopia/etanni.rb', line 43

def compile!
	temp = @template.dup
	temp.strip!
	temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, REPLACEMENT)
	@compiled = "_out_ = [<<#{SEPARATOR}.chomp!]\n#{temp}#{STOP}_out_"
end

#result(binding, filename = '<Etanni>') ⇒ Object



50
51
52
# File 'lib/utopia/etanni.rb', line 50

def result(binding, filename = '<Etanni>')
	eval(@compiled, binding, filename).join
end