Sha256: 55d9d664c8c91fc4802b9a3b4aa523e4f75b2820da648bbe2272ec77ec442715
Contents?: true
Size: 967 Bytes
Versions: 9
Compression:
Stored size: 967 Bytes
Contents
# frozen_string_literal: true class Template GLOBALS = %i[output error context object].freeze DEFAULT_TIMEOUT = 0 def initialize( input, output: StringIO.new, error: StringIO.new, timeout: DEFAULT_TIMEOUT ) @input = input @output = output @error = error @timeout = timeout || DEFAULT_TIMEOUT @context = ::Code::Object::Context.new end def self.parse(input, timeout: DEFAULT_TIMEOUT) Timeout.timeout(timeout) { Parser.parse(input).to_raw } end def self.evaluate( input, output: StringIO.new, error: StringIO.new, timeout: DEFAULT_TIMEOUT ) new(input, output:, error:, timeout:).evaluate end def evaluate Timeout.timeout(timeout) do parsed = Template.parse(input) Node::Template.new(parsed).evaluate(context:, output:, error:) output.is_a?(StringIO) ? output.string : "" end end private attr_reader :input, :timeout, :output, :error, :context end
Version data entries
9 entries across 9 versions & 1 rubygems