landline/lib/hyde/template/erb.rb

26 lines
590 B
Ruby

# frozen_string_literal: true
require 'erb'
require_relative '../template'
module Hyde
module Templates
# ERB Template language adapter
class ERB < Hyde::Template
# @see Hyde::Template#new
def initialize(input, toplevel: nil, locals: nil)
super
@template = ::ERB.new(@template)
@template.filename = input.is_a?(File) ? input.path : "(Inline)"
end
# Run the template.
def run
@context.instance_exec(@template,@binding) do |template, binding|
template.result binding
end
end
end
end
end