Sha256: d54f36e711438b87bb1c521df702f12c79b45fdbf8fe64394eb79ff9bbe5a641

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

class Template
  VERSION = Gem::Version.new("0.2.3")

  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

  def self.render(input, context = "", io: StringIO.new, timeout: 10)
    new(input, io: io, timeout: timeout).render(context)
  end

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
template-ruby-0.2.3 lib/template.rb