#!/usr/bin/env ruby require 'mustache' require 'yaml' if STDIN.stat.size > 0 doc = STDIN.read if doc =~ /^(\s*---(.*)---\s*)/m data = YAML.load($2.strip) puts Mustache.render(doc.sub($1, ''), data) else puts doc end else puts <<-usage Usage: cat data.yml template.mustache | mustache Expects a single Mustache template on STDIN complete with YAML frontmatter. Runs template.mustache through Mustache, using the data in data.yml to replace sections and variables. Useful when developing templates before hooking them into your website or whatnot. The data.yml file should start with --- on a single line and end with --- on a single line, e.g. --- names: [ {name: chris}, {name: mark}, {name: scott} ] --- The converted document will be printed on STDOUT. usage end