Skip to content

Instantly share code, notes, and snippets.

@briandonahue
Created November 2, 2009 21:10
Show Gist options
  • Save briandonahue/224463 to your computer and use it in GitHub Desktop.
Save briandonahue/224463 to your computer and use it in GitHub Desktop.
require 'yaml'
require 'fileutils'
@config = YAML::load_file "local.properties.yml"
desc "Building config files from templates..."
task :expand_template_files do
expand_template(WEBSITE_CONFIG_TEMPLATE, WEBSITE_SRC + "web.config")
end
def expand_template( template_file, output_file)
puts "Building #{output_file}"
template = File.open(template_file, "r")
output = File.open(output_file, "w")
template.each_line do |template_line|
template_line.gsub(/@([^@]+)@/) do |token|
value = @config[$1.downcase]
unless value.nil?
template_line = template_line.gsub(token, value.to_s)
end
end
output.write(template_line)
end
template.close
output.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment