Created
December 13, 2012 09:06
-
-
Save jorinvo/4275139 to your computer and use it in GitHub Desktop.
Generate file from YAML data with mustache layout.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to run
gem install mustache
to use this script.