bin/mustache in mustache-0.6.0 vs bin/mustache in mustache-0.7.0

- old
+ new

@@ -1,25 +1,51 @@ #!/usr/bin/env ruby require 'mustache' require 'yaml' -if !$stdin.tty? - doc = $stdin.read - if doc =~ /^(\s*---(.*)---\s*)/m +def help + puts <<-usage +Usage: + $ cat data.yml template.mustache | mustache + $ mustache data.yml template.mustache + $ cat <<data | druby mustache - template.mustache +--- +name: Bob +age: 30 +--- +data + +See compiled Ruby string: + $ mustache -c FILE + +Help: + $ mustache -h + +See mustache(1) or http://defunkt.github.com/mustache/mustache.1.html +for an overview. +usage +end + +if (ARGV.delete('-c') || ARGV.delete('--compile')) && (file = ARGV[0]) + puts Mustache.compile(File.read(file)) + +elsif ($stdin.tty? && ARGV.empty?) || ARGV.delete('-h') || ARGV.delete('--help') + help + +else + # Not at a terminal, read from STDIN and print rendered templates to + # STDOUT. + doc = ARGF.read + + if doc =~ /^(\s*---(.+)---\s*)/m yaml = $2.strip template = doc.sub($1, '') YAML.each_document(yaml) do |data| puts Mustache.render(template, data) end else puts doc end -else - puts <<-usage -Usage: cat data.yml template.mustache | mustache - -See mustache(1) or http://defunkt.github.com/mustache/mustache.1.html -for an overview. -usage + exit end