Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a standalone, command line, code generator script

Tags:

I'm looking for a library or command line script that will allow me to create custom templates that I can generate from the command line. The ruby on rails scaffolding generator is almost identical to what I am trying to do. I would even prefer that it be written in Ruby (yet it cannot require Rails because I may not be using it on a Ruby application). What sorts of scripts like this are already available?

like image 916
Andrew Avatar asked Sep 20 '11 20:09

Andrew


2 Answers

I've also been on the lookout for something like this -- haven't found what I hoped for. The two approaches I've used instead have been acceptable. But I'm still hoping to find the real thing.

  • obvious, but sed for simple use cases

  • for medium-complexity use cases, if you can assume some version of Python is present on the machine, string.Template in the standard library works well. You could write a small Python script that uses this function, and since it is Python, tests / looping etc. that might normally be provided by the template engine could pretty easily be handled in the Python code instead.

  • I've just discovered Mustache (see http://mustache.github.io/). Seems like a solid, purpose-built solution. From its web site, Mustache has implementations in Ruby, JavaScript, Python, Erlang, PHP, Perl, Objective-C, Java, .NET, Android, C++, Go, Lua, ActionScript, ColdFusion, Scala, Clojure, Fantom, CoffeeScript, D, and node.js. If those choices suit your environment, you could script or compile Mustache support to be a command line utility pretty easily.

UPDATE 15-OCT-2013

Now that I've used Mustache for a while -- it's a great tool, simple but powerful.

like image 127
Chris Johnson Avatar answered Sep 21 '22 17:09

Chris Johnson


Try this one: https://gomplate.hairyhenderson.ca Rich set of functions and just a stanalone binary (written in Go)

like image 38
Meow Kittey Avatar answered Sep 21 '22 17:09

Meow Kittey