Class: Template
- Inherits:
-
Object
- Object
- Template
- Defined in:
- lib/template.rb,
lib/template/node.rb,
lib/template/parser.rb,
lib/template/node/part.rb,
lib/template/node/template.rb,
lib/template/node/code_part.rb,
lib/template/node/text_part.rb,
lib/template/parser/template.rb
Defined Under Namespace
Constant Summary collapse
- Version =
Gem::Version.new("0.2.4")
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, io: StringIO.new, timeout: 10) ⇒ Template
constructor
A new instance of Template.
- #render(context = "") ⇒ Object
Constructor Details
#initialize(input, io: StringIO.new, timeout: 10) ⇒ Template
Returns a new instance of Template.
2 3 4 5 6 7 8 9 10 |
# File 'lib/template.rb', line 2 def initialize(input, io: StringIO.new, timeout: 10) @input = input @parsed = Timeout.timeout(timeout) do ::Template::Parser::Template.new.parse(@input) end @io = io @timeout = timeout end |
Class Method Details
.render(input, context = "", io: StringIO.new, timeout: 10) ⇒ Object
12 13 14 |
# File 'lib/template.rb', line 12 def self.render(input, context = "", io: StringIO.new, timeout: 10) new(input, io: io, timeout: timeout).render(context) end |
Instance Method Details
#render(context = "") ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/template.rb', line 16 def render(context = "") Timeout.timeout(@timeout) do if context.present? context = ::Code.evaluate(context, timeout: @timeout) else context = ::Code::Object::Dictionnary.new end ::Template::Node::Template.new(@parsed).evaluate( context: context, io: @io, ) @io.is_a?(StringIO) ? @io.string : nil end end |