Sha256: 3f355f245e4f8596fcc084a3059321abf94aba18eb7d3f73c905c4d3b73f139d
Contents?: true
Size: 724 Bytes
Versions: 6
Compression:
Stored size: 724 Bytes
Contents
require 'hamster' 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
6 entries across 6 versions & 1 rubygems