Sha256: ac5c41221f679ddbf2f54b7a301febb1fc268615fe921d95b73f740e871b06e5

Contents?: true

Size: 750 Bytes

Versions: 5

Compression:

Stored size: 750 Bytes

Contents

# encoding: utf-8
require "erb"
require "active_support"

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

5 entries across 5 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.9 lib/templatable.rb
tbpgr_utils-0.0.8 lib/templatable.rb
tbpgr_utils-0.0.7 lib/templatable.rb
tbpgr_utils-0.0.6 lib/templatable.rb
tbpgr_utils-0.0.5 lib/templatable.rb