Class: H2o::Template
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, env = {}) ⇒ Template
constructor
A new instance of Template.
- #render(context = {}) ⇒ Object
Constructor Details
#initialize(file, env = {}) ⇒ Template
Returns a new instance of Template.
5 6 7 8 |
# File 'lib/h2o/template.rb', line 5 def initialize (file, env = {}) @file = file @nodelist = Template.load(@file, env) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/h2o/template.rb', line 3 def context @context end |
Class Method Details
.load(file, env = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/h2o/template.rb', line 22 def self.load file, env = {} unless H2o.loader env[:searchpath] ||= File.('../', file) H2o.loader = H2o::FileLoader.new(env[:searchpath]) end source = H2o.loader.read(file) parser = Parser.new(source, file, env) parser.parse end |
.parse(source, env = {}) ⇒ Object
17 18 19 20 |
# File 'lib/h2o/template.rb', line 17 def self.parse source, env = {} parser = Parser.new(source, false, env) parsed = parser.parse end |
Instance Method Details
#render(context = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/h2o/template.rb', line 10 def render (context = {}) @context = Context.new(context) output_stream = [] @nodelist.render(@context, output_stream) output_stream.join end |