Skip to content

Commit

Permalink
Removed tools folder
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Jan 24, 2014
1 parent 536d0fc commit d3b5cb0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
94 changes: 47 additions & 47 deletions Tools/Rake/quicktemplate.rb → quicktemplate.rb
@@ -1,48 +1,48 @@
require 'rake'
require 'erb'

class QuickTemplate
attr_reader :args, :file

def initialize(file)
raise "The template file to process must be given" if file.nil?

@file = file
end

def exec(args = {})
template = prepare_template File.read(@file)
result = exec_erb template, args

resultFile = @file.ext('')
File.open(resultFile, 'w') do
|f| f.write(result)
end

puts "Created file #{resultFile}"
end

def prepare_template(template)
tag_regex = /(@\w[\w\.]+\w@)/

hits = template.scan(tag_regex)
tags = hits.map do |item|
item[0].chomp('@').reverse.chomp('@').reverse.strip
end

tags.map! do |a|
a.to_sym
end
tags.uniq!

tags.inject(template) do |text, tag|
text.gsub /@#{tag.to_s}@/, "<%= #{tag.to_s} %>"
end
end

def exec_erb(template, args)
b = binding
erb = ERB.new(template, 0, "%")
erb.result(b)
end
require 'rake'
require 'erb'

class QuickTemplate
attr_reader :args, :file

def initialize(file)
raise "The template file to process must be given" if file.nil?

@file = file
end

def exec(args = {})
template = prepare_template File.read(@file)
result = exec_erb template, args

resultFile = @file.ext('')
File.open(resultFile, 'w') do
|f| f.write(result)
end

puts "Created file #{resultFile}"
end

def prepare_template(template)
tag_regex = /(@\w[\w\.]+\w@)/

hits = template.scan(tag_regex)
tags = hits.map do |item|
item[0].chomp('@').reverse.chomp('@').reverse.strip
end

tags.map! do |a|
a.to_sym
end
tags.uniq!

tags.inject(template) do |text, tag|
text.gsub /@#{tag.to_s}@/, "<%= #{tag.to_s} %>"
end
end

def exec_erb(template, args)
b = binding
erb = ERB.new(template, 0, "%")
erb.result(b)
end
end
2 changes: 1 addition & 1 deletion rakefile.rb
Expand Up @@ -3,7 +3,7 @@
require 'albacore'
require 'configatron'
require 'fileutils'
require File.dirname(__FILE__) + "/Tools/Rake/quicktemplate.rb"
require './quicktemplate.rb'
require './rakefile.include.rb'

rescue LoadError
Expand Down

0 comments on commit d3b5cb0

Please sign in to comment.