Sha256: 8384d9cdb9e91a962961d2a1cf31b082b3f31486861e3a4ae6f0fda20b34a2f2

Contents?: true

Size: 760 Bytes

Versions: 141

Compression:

Stored size: 760 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

141 entries across 141 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.70 lib/templatable.rb
tbpgr_utils-0.0.69 lib/templatable.rb
tbpgr_utils-0.0.68 lib/templatable.rb
tbpgr_utils-0.0.67 lib/templatable.rb
tbpgr_utils-0.0.66 lib/templatable.rb
tbpgr_utils-0.0.65 lib/templatable.rb
tbpgr_utils-0.0.64 lib/templatable.rb
tbpgr_utils-0.0.63 lib/templatable.rb
tbpgr_utils-0.0.62 lib/templatable.rb
tbpgr_utils-0.0.61 lib/templatable.rb
tbpgr_utils-0.0.60 lib/templatable.rb
tbpgr_utils-0.0.59 lib/templatable.rb
tbpgr_utils-0.0.58 lib/templatable.rb
tbpgr_utils-0.0.57 lib/templatable.rb
tbpgr_utils-0.0.56 lib/templatable.rb
tbpgr_utils-0.0.55 lib/templatable.rb
tbpgr_utils-0.0.54 lib/templatable.rb
tbpgr_utils-0.0.53 lib/templatable.rb
tbpgr_utils-0.0.52 lib/templatable.rb
tbpgr_utils-0.0.51 lib/templatable.rb