Class: DevelopWithPassion::Expander::ERBTemplateFile
- Defined in:
- lib/developwithpassion_expander/erb_template_file.rb
Instance Method Summary collapse
- #prepare_template(template) ⇒ Object
- #process(args) ⇒ Object
- #process_template(template, binding) ⇒ Object
Instance Method Details
#prepare_template(template) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/developwithpassion_expander/erb_template_file.rb', line 4 def prepare_template(template) token_regex = /(@\w[\w\.\_]+\w@)/ hits = template.scan(token_regex) = hits.map do |item| item[0].gsub(/@/,'').squeeze end = .map{|tag| tag.to_sym}.uniq .inject(template) do |text, tag| text.gsub /@#{tag.to_s}@/, "<%= #{tag.to_s} %>" end end |
#process(args) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/developwithpassion_expander/erb_template_file.rb', line 23 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) ⇒ Object
18 19 20 21 |
# File 'lib/developwithpassion_expander/erb_template_file.rb', line 18 def process_template(template,binding) erb = ERB.new(template, 0, "%") erb.result(binding) end |