Class: Zafu::Template
- Inherits:
-
Object
- Object
- Zafu::Template
- Defined in:
- lib/zafu/template.rb
Instance Method Summary collapse
-
#initialize(template, src_helper = nil, compiler = Zafu::Compiler) ⇒ Template
constructor
A new instance of Template.
- #to_erb(context = {}) ⇒ Object
- #to_ruby(context = {}) ⇒ Object
Constructor Details
#initialize(template, src_helper = nil, compiler = Zafu::Compiler) ⇒ Template
Returns a new instance of Template.
5 6 7 8 9 10 11 |
# File 'lib/zafu/template.rb', line 5 def initialize(template, src_helper = nil, compiler = Zafu::Compiler) if template.kind_of?(String) @ast = compiler.new(template) else @ast = compiler.new_with_url(template.path, :helper => src_helper) end end |
Instance Method Details
#to_erb(context = {}) ⇒ Object
13 14 15 |
# File 'lib/zafu/template.rb', line 13 def to_erb(context = {}) @ast.to_erb(context) end |
#to_ruby(context = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/zafu/template.rb', line 17 def to_ruby(context = {}) src = ::ERB.new("<% __in_erb_template=true %>#{to_erb(context)}", nil, '-').src # Ruby 1.9 prepends an encoding to the source. However this is # useless because you can only set an encoding on the first line RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src end |