module Expansions::ERBTemplateFile

Public Instance Methods

prepare_template(template) click to toggle source
# File lib/expansions/erb_template_file.rb, line 5
def prepare_template(template)
  token_regex = /(@\w[\w\.\_]+\w@)/

  hits = template.scan(token_regex)
  tags = hits.map do |item|
    item[0].gsub(/@/,'').squeeze
  end
  tags = tags.map{|tag| tag.to_sym}.uniq

  tags.inject(template) do |text, tag|
    text.gsub /@#{tag.to_s}@/, "<%= #{tag.to_s} %>"
  end
end
process(args) click to toggle source
# File lib/expansions/erb_template_file.rb, line 24
def process(args)
  template = prepare_template(File.read(args[:input]))
  result = process_template(template,args[:binding])

  File.open_for_write(args[:output]) do|file|
    file.write(result)
  end
end
process_template(template,binding) click to toggle source
# File lib/expansions/erb_template_file.rb, line 19
def process_template(template,binding)
  erb = ERB.new(template, 0, "%")
  erb.result(binding)
end