Sha256: d06a3f49615532ec9e7c2a029bcf15cd00e025249412317d09a918c3ab3bb398

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

#!/usr/bin/env ruby

require 'mustache'
require 'yaml'

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
  exit
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mustache-0.7.0 bin/mustache