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(filename, env = {}) ⇒ Template
constructor
A new instance of Template.
- #render(context = {}) ⇒ Object
Constructor Details
#initialize(filename, env = {}) ⇒ Template
Returns a new instance of Template.
7 8 9 10 11 |
# File 'lib/h2o.rb', line 7 def initialize (filename, env = {}) @file = Pathname.new(filename) env[:search_path] = @file.dirname @nodelist = Template.load(@file, env) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/h2o.rb', line 5 def context @context end |
Class Method Details
.load(file, env = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/h2o.rb', line 25 def self.load file, env = {} file = env[:search_path] + file if file.is_a? String parser = Parser.new(file.read, file, env) parser.parse end |
.parse(source, env = {}) ⇒ Object
20 21 22 23 |
# File 'lib/h2o.rb', line 20 def self.parse source, env = {} parser = Parser.new(source, false, env) parsed = parser.parse end |
Instance Method Details
#render(context = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/h2o.rb', line 13 def render (context = {}) @context = Context.new(context) output_stream = [] @nodelist.render(@context, output_stream) output_stream.join end |