Created
March 10, 2011 05:47
-
-
Save DamonOehlman/863632 to your computer and use it in GitHub Desktop.
Rake task that will combine a number of HTML (or Handlebars) files into an object literal in a single JS file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :resources => [] do | |
resources = {} | |
basepath = 'src/resources/' | |
files = FileList.new | |
.include("%s**/*.html" % basepath) | |
.include("%s**/*.handlebars" % basepath) | |
.sub(basepath, '') | |
files.each do |src| | |
File.open(basepath + src, 'r') do |resfile| | |
resid = src.gsub(/.(html|handlebars)/i, '') | |
# update the resource in the resources list | |
resources[resid] = resfile.read().gsub(/[\n\r\t]/, '').gsub(/\'/, '"') | |
end | |
end | |
File.open("src/resources.js", "w") do |resjs| | |
counter = 0 | |
resjs.write("var htmlResources = {\n") | |
resources.each do |k, v| | |
if (counter > 0) | |
resjs.write(",\n") | |
end | |
resjs.write(" '%s': '%s'" % [k, v]) | |
counter += 1 | |
end | |
resjs.write("\n};\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment