Created
January 28, 2016 20:20
-
-
Save agentgt/1bc5f14e62bce11e2ceb to your computer and use it in GitHub Desktop.
A Groovy mustache(1) replacement
This file contains hidden or 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/env groovy | |
@Grab(group='com.github.jknack', module='handlebars', version='4.0.3') | |
@Grab(group='org.yaml', module='snakeyaml', version='1.16') | |
@Grab(group='org.slf4j', module='slf4j-simple', version='1.7.14') | |
import org.yaml.snakeyaml.Yaml; | |
import com.github.jknack.handlebars.Handlebars; | |
import com.github.jknack.handlebars.Template; | |
if (args.length == 2) { | |
String i = args[0]; | |
String t = args[1]; | |
if (i == t) return usage(); | |
Yaml yaml = new Yaml() | |
InputStream input = i == '-' ? System.in : new File(args[0]).newInputStream(); | |
String file = t == '-' ? System.in : new File(args[1]).text; | |
Object o = yaml.load(input) | |
Handlebars handlebars = new Handlebars(); | |
Template template = handlebars.compileInline(file); | |
Writer w = System.out.newWriter(); | |
template.apply(o, w); | |
w.flush(); | |
} | |
else { | |
return usage(); | |
} | |
def usage() { | |
println "Usage: Mustache.groovy INPUT FILE" | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment