Sha256: 0781f229b520646ea88ca01de3c057cc710e50f810a3bc2c55e2963867ea3f2a
Contents?: true
Size: 771 Bytes
Versions: 17
Compression:
Stored size: 771 Bytes
Contents
# frozen_string_literal: true require 'hamster' require 'erb' module RakeDependencies class Template def initialize( template, parameters = {} ) @template = template @parameters = Hamster::Hash.new(parameters) end def with_parameter(key, value) Template.new(@template, @parameters.put(key, value)) end def with_parameters(pairs) pairs.to_a.reduce(self) do |memo, parameter| memo.with_parameter(*parameter) end end def render context = Object.new @parameters.each do |key, value| context.instance_variable_set("@#{key}", value) end context_binding = context.instance_eval { binding } ERB.new(@template).result(context_binding) end end end
Version data entries
17 entries across 17 versions & 1 rubygems