Skip to content

Instantly share code, notes, and snippets.

@armandocanals
Created March 6, 2015 19:44
Show Gist options
  • Save armandocanals/9fafaff671b2b20b7287 to your computer and use it in GitHub Desktop.
Save armandocanals/9fafaff671b2b20b7287 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
root = File.expand_path(ARGV[0] ? ARGV[0] : ".") + "/"
objectName = "JST"
templateDir = "templates/"
templates = Dir["#{root}#{templateDir}**/*.jst"]
contents = {}
templates.each do |path|
fileContents = File.readlines(path).map(&:strip)
key = path.sub!(/^#{root}#{templateDir}(.*)\.jst/, '\1').split("/").join("_")
contents[key] = fileContents.join("\n")
end
File.open(root + templateDir + "templates.js", "w") do |f|
f.write("var #{objectName} = " + JSON.dump(contents) + ";")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment