Sha256: 8e3daab5dbeeaa92e2bfb71e22d03e519046464c5546a1b6dc132ac592b0970d
Contents?: true
Size: 738 Bytes
Versions: 62
Compression:
Stored size: 738 Bytes
Contents
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
62 entries across 62 versions & 2 rubygems