问题
Is there a simple, standalone, portable, existing distribution of Mustache for windows that lets me invoke Mustache exactly as specified (or as close as possible) in the mustache(1) manual?
cat data.yml template.mustache | mustache
I can't find any explanation of how to actually acquire an executable called mustache
to use mustache in this way - on any platform, although I'm primarily interested in Windows right now.
As far as I can tell, the various implementations of mustache listed on the mustache homepage are mostly libraries, rather than standalone applications that can be invoked in this way.
Ideally, I'm looking for something that's:
- Standalone - I am looking for something I can invoke from the command line, not a library. I am planning to generate output as part of my automated CI build.
- Portable - I should be able to bundle everything I need into source control, without having to preinstall anything (since my build may run on one of many build agents, I do not wish to maintain a suite of preinstalled software on multiple agents); nor can I connect to the internet to download libraries. Ideally the portable packaging should be fairly straightforward to bundle.
If this isn't available then I'm interested in getting as close as possible - e.g. if I have to preinstall python but not needing to run an installer which connects to the internet.
I'm prepared to concede on the "no preinstall" if it's something I have a cat in hell's chance of already having packaged up at our organisation (e.g. python or ruby) but not for individual libraries.
回答1:
From the docs:
INSTALLATION
If you have RubyGems installed:
gem install mustache
See https://mustache.github.io/mustache.1.html bottom of page
回答2:
Well if you have Groovy installed on your Windows machine you can just run this script: https://gist.github.com/agentgt/1bc5f14e62bce11e2ceb . You do not need to download anything else as the script will automatically download the correct dependencies so no dep hell.
The Groovy version is slightly more cross platform (although one could argue about that) than the Ruby version albeit it requires Java and is slower. If your a JVM shop this is usually not a problem.
You could take the above script and turn it into Java and create single executable Jar with all the dependencies that will work anywhere Java is installed. If interested just add a comment and I'll make a quick project.
回答3:
(Full disclosure: I am the maintainer of this project.)
I have written mo, which is a Bash port of the mustache templating system. Its major caveat is that it uses environment variables instead of reading from a .json
file.
$ export name="John Doe"
$ cat template.mo
Hello {{name}}.
{{^name2}}The variable name2 is not defined.{{/name2}}
$ mo template.mo
Hello John Doe.
The variable name2 is not defined.
It also works with arrays, but Bash can not export arrays to other functions. So, to have arrays work you will need to either source another file or source mo
itself into the environment and then call the mo
function.
The repository contains tests and examples to help illustrate how to use this tool.
来源:https://stackoverflow.com/questions/21625582/is-there-a-standalone-portable-command-line-implementation-of-mustache-for-wind