Sha256: 5b0893c9fa9c2aa1d3df9ce779c697780fa9794a889a67440e024ccbf0535dea
Contents?: true
Size: 761 Bytes
Versions: 1
Compression:
Stored size: 761 Bytes
Contents
# encoding: utf-8 require 'erb' require 'active_support/concern' module Templatable extend ActiveSupport::Concern module ClassMethods def template(template) define_method :get_template do template end define_method :get_placeholders do ret = template.scan(/<%=placeholders\[:(.*)\]%>/) ret_hash = {} ret.each { |v| ret_hash[v.first.to_sym] = v.first } ret_hash end end end def initialize(materials) @materials = materials end def result placeholders = get_placeholders placeholders.each do |key, value| placeholders[key] = method("manufactured_#{value}").call end ERB.new(get_template).result(binding) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tbpgr_utils-0.0.151 | lib/templatable.rb |