Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Created December 13, 2012 09:06
Show Gist options
  • Save jorinvo/4275139 to your computer and use it in GitHub Desktop.
Save jorinvo/4275139 to your computer and use it in GitHub Desktop.
Generate file from YAML data with mustache layout.
#!/usr/bin/ruby
require 'mustache'
require 'yaml'
LAYOUT = 'layout.html'
DATA = 'data.yaml'
OUT = 'index.html'
class File
def self.read(path)
File.open(path) { |f| f.read }
end
def self.write(path, content)
File.open(path, 'w') { |f| f.write(content) }
end
end
task :default => [:build]
task :build do
print "generating #{OUT} ..."
layout = File.read(LAYOUT)
data = YAML.load_file(DATA)
content = Mustache.render(layout, data)
File.write(OUT, content)
print ' done!'
end
@jorinvo
Copy link
Author

jorinvo commented Dec 13, 2012

You need to run gem install mustache to use this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment