Permalink
Browse files

Add binary

  • Loading branch information...
1 parent e573bed commit 7d6644da0cf1c23d93bc25a80094670ba73c3223 @pvorb committed Dec 23, 2011
Showing with 83 additions and 0 deletions.
  1. +39 −0 bin/tpl
  2. +44 −0 tpl.js
View
39 bin/tpl
@@ -0,0 +1,39 @@
+#!/usr/bin/env node
+
+var optimist = require('optimist')
+ .usage('Usage: tpl [-v|--version] [-h|--help] [file]')
+ .options('v', {
+ alias: 'version',
+ describe: 'Show the version of this script'
+ })
+ .options('h', {
+ alias: 'help',
+ describe: 'This message'
+ });
+var argv = optimist.argv;
+
+var tpl = require('tpl');
+// Show version
+if (argv.v) {
+ console.log(tpl.version);
+}
+// Show help
+else if (argv.h) {
+ console.log(optimist.help());
+}
+// Show unknown command
+else if (Object.keys(argv).length > 2) {
+ console.error('Unknown command');
+}
+// Show help
+else if (argv._.length == 0) {
+ console.log(optimist.help());
+}
+// One file at a time
+else if (argv._.length > 1) {
+ console.error('tpl can only translate one file at a time.');
+}
+// Translate file
+else {
+ console.log(argv);
+}
View
44 tpl.js
@@ -0,0 +1,44 @@
+// tpl - a general purpose template cli
+// (c) 2011 Paul Vorbach. Licensed under MIT.
+;(function() {
+ var version = 'v0.0.0';
+
+ var fs = require('fs');
+ var path = require('path');
+ var confdir = require('confdir');
+ var append = require('append');
+
+ // default template engine
+ var ejs = require('ejs');
+ var tplEngine = ejs;
+
+ // default
+ var defaultConf = {
+ parsers: {
+ __default: 'markdown.js'
+ },
+ templates: {
+ __default: 'default.ejs'
+ },
+ extensions: {
+ __default: 'txt'
+ },
+ };
+
+ function apply(content, cb) {
+ // look for configuration directory
+ confdir(process.cwd(), 'tpl', function(err, dir) {
+ if (err) console.error(err);
+
+ var json = fs.readFileSync(path.resolve(dir, 'conf.json'), 'utf8');
+ var conf = JSON.parse(json);
+ conf = append(defaultConf, conf);
+
+ });
+ }
+
+ return {
+ apply: apply,
+ version: version
+ };
+}).call(this);

0 comments on commit 7d6644d

Please sign in to comment.