Class: Utopia::Etanni
- Inherits:
-
Object
- Object
- Utopia::Etanni
- 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
-
#compiled ⇒ Object
readonly
Returns the value of attribute compiled.
Instance Method Summary collapse
- #compile! ⇒ Object
-
#initialize(template, compiled = false) ⇒ Etanni
constructor
A new instance of Etanni.
- #result(binding, filename = '<Etanni>') ⇒ Object
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
#compiled ⇒ Object (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 |