Created
November 13, 2014 22:27
-
-
Save willmitchell/e367b5a668ce24f271b2 to your computer and use it in GitHub Desktop.
This is a simple code generator for Meteor. It generates HTML, LESS, and CSS template files when given a name.
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 | |
// Written by Will Mitchell. | |
// In the public domain. Use as you wish, at your own risk. | |
// This is a simple code generator for Meteor. It generates HTML, LESS, and CSS template files when given a name. | |
String singular | |
String plural | |
switch (args.size()) { | |
case 1: | |
singular = args[0] | |
plural = "${singular}s" | |
break; | |
case 2: | |
singular = args[0] | |
plural = args[1] | |
default: | |
println "Usage: gen_view_scaf.groovy name [pluralname]" | |
System.exit(-1) | |
} | |
html = """<template name="${plural}"> | |
<div class="${plural}"> | |
<div class="page-header"> | |
<h1>${plural}</h1> | |
</div> | |
<ul class="list-group"> | |
{{#each ${plural}}} | |
<li class="${singular}-group-item">{{ _id }}</li> | |
{{/each}} | |
</ul> | |
</div> | |
{{> quickForm collection="${plural}" id="insert${singular.capitalize()}Form" type="insert"}} | |
</template> | |
""" | |
print html | |
less = """@import '../../stylesheets/mixins.import.less'; | |
@import '../../stylesheets/variables.import.less'; | |
.${plural} { | |
} | |
""" | |
print less | |
js = """Template.${plural}.rendered = function() { | |
console.log("${plural} rendered"); | |
}; | |
//Template.${plural}.helpers = { | |
// ${plural}: function () { | |
// return ${plural.capitalize()}.find({}) | |
// } | |
//} | |
""" | |
print js | |
new File("${plural}.html").bytes = html.bytes | |
new File("${plural}.less").bytes = less.bytes | |
new File("${plural}.js").bytes = js.bytes | |
print "Done." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment