forked from mustache/mustache
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
mustache
script for rendering templates on the command line.
- Loading branch information
Showing
3 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/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 |