Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from Gozala/dynamic-vars

Making it possible to define dynamic variables
  • Loading branch information...
commit 5b656f1471951c7b71d3724e3fbac4dbcfbb6b2f 2 parents e7799fa + 3cbc918
@tj authored
View
26 bin/ngen
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+// vim:ft=javascript:
/**
* Module dependencies.
@@ -88,14 +89,21 @@ Template.prototype.init = function(dest){
function next() {
var desc
, key = keys.shift();
+
+ function yield(value) {
+ self.values[key] = String(value).trim();
+ next();
+ }
+
if (key) {
desc = vars[key];
- process.stdout.write(' \033[90m' + desc + '\033[0m');
- process.stdin.setEncoding('utf8');
- process.stdin.once('data', function(str){
- self.values[key] = str.trim();
- next();
- }).resume();
+ // If `desc` is a function executing it so that it can read a value.
+ if (typeof desc === "function") {
+ desc(self.values, yield);
+ // Otherwise falling back to CLI.
+ } else {
+ ask(desc, yield);
+ }
} else {
process.stdin.destroy();
self.create();
@@ -189,6 +197,12 @@ function requireArgument(flag) {
}
}
+function ask(desc, callback) {
+ process.stdout.write(' \033[90m' + desc + '\033[0m');
+ process.stdin.setEncoding('utf8');
+ process.stdin.once('data', callback).resume();
+}
+
// parse arguments
var arg;
View
5 package.json
@@ -7,8 +7,11 @@
"url": "git://github.com/visionmedia/ngen.git"
},
"author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "contributors": [
+ "Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)"
+ ],
"bin": { "ngen": "./bin/ngen" },
"engines": {
"node": "*"
}
-}
+}
View
3  templates/git/content/.npmignore
@@ -0,0 +1,3 @@
+support
+test
+examples
View
5 templates/git/content/History.md
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
View
5 templates/git/content/Makefile
@@ -0,0 +1,5 @@
+
+test:
+ @echo "populate me"
+
+.PHONY: test
View
29 templates/git/content/Readme.md
@@ -0,0 +1,29 @@
+
+# {{project}}
+
+ {{description}}
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 {{name}} &lt;{{email}}&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
2  templates/git/content/index.js
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/{{project}}');
View
12 templates/git/content/lib/{{project}}.js
@@ -0,0 +1,12 @@
+
+/*!
+ * {{project}}
+ * Copyright(c) 2011 {{name}} <{{email}}>
+ * MIT Licensed
+ */
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.0.1';
View
10 templates/git/content/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "{{project}}",
+ , "version": "0.0.1",
+ , "description": "{{description}}",
+ , "keywords": [],
+ , "author": "{{name}} <{{email}}>",
+ , "dependencies": {}
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}
View
13 templates/git/content/test/{{project}}.test.js
@@ -0,0 +1,13 @@
+
+/**
+ * Module dependencies.
+ */
+
+var mini = require('{{project}}')
+ , should = require('should');
+
+module.exports = {
+ 'test .version': function(){
+ {{project}}.version.should.match(/^\d+\.\d+\.\d+$/);
+ }
+};
View
22 templates/git/index.js
@@ -0,0 +1,22 @@
+var spawn = require('child_process').spawn;
+
+exports.variables = {
+ project: 'Project name: ',
+ description: 'Project description: ',
+ name: function(values, callback) {
+ spawn('git', [
+ '--bare',
+ 'config',
+ '--global',
+ 'user.name'
+ ]).stdout.once('data', callback);
+ },
+ email: function(values, callback) {
+ spawn('git', [
+ '--bare',
+ 'config',
+ '--global',
+ 'user.email'
+ ]).stdout.once('data', callback);
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.