Skip to content

Commit

Permalink
fixed jade(1) stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 26, 2011
1 parent 19ca1f2 commit 38fc7b4
Showing 1 changed file with 31 additions and 62 deletions.
93 changes: 31 additions & 62 deletions bin/jade
Expand Up @@ -10,13 +10,11 @@ var fs = require('fs')
, resolve = path.resolve
, basename = path.basename
, dirname = path.dirname
, jade;
, jade = require('../');

try {
jade = require('../lib/jade');
} catch (err) {
jade = require('jade');
}
// jade options

var options = {};

// options

Expand Down Expand Up @@ -45,62 +43,33 @@ program.on('--help', function(){

program.parse(process.argv);

//
// /**
// * Usage information.
// */
//
// var usage = ''
// + '\n'
// + ' Usage: jade [options]\n'
// + ' [path ...]\n'
// + ' < in.jade > out.jade'
// + ' \n'
// + ' Options:\n'
// + ' -o, --options <str> JavaScript options object passed\n'
// + ' -h, --help Output help information\n'
// + ' -w, --watch Watch file(s) or folder(s) for changes and re-compile\n'
// + ' -v, --version Output jade version\n'
// + ' --out <dir> Output the compiled html to <dir>\n';
// + '\n';
//
// // Parse arguments
//
// var arg
// , files = [];
// while (args.length) {
// arg = args.shift();
// switch (arg) {
// case '-h':
// case '--help':
// console.log(usage);
// process.exit(1);
// case '-v':
// case '--version':
// console.log(jade.version);
// process.exit(1);
// case '-o':
// case '--options':
// var str = args.shift();
// if (str) {
// options = eval('(' + str + ')');
// } else {
// console.error('-o, --options requires a string.');
// process.exit(1);
// }
// break;
// case '-w':
// case '--watch':
// watchers = {};
// break;
// case '--out':
// dest = args.shift();
// break;
// default:
// files.push(arg);
// }
// }
//
// left-over args are file paths

var files = program.args;

// compile files

if (files.length) {

// stdio
} else {
stdin();
}

/**
* Compile from stdin.
*/

function stdin() {
var buf = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){ buf += chunk; });
process.stdin.on('end', function(){
var fn = jade.compile(buf, options);
process.stdout.write(fn(options));
}).resume();
}

// // Watching and no files passed - watch cwd
// if (watchers && !files.length) {
// fs.readdirSync(process.cwd()).forEach(processFile);
Expand Down

0 comments on commit 38fc7b4

Please sign in to comment.