Skip to content
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 6a5a3fa683b5bad21e0db325db503f22db19a165 @kevinswiber kevinswiber committed Oct 17, 2013
Showing with 61 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +34 −0 handlebars.js
  3. +22 −0 package.json
5 .gitignore
@@ -0,0 +1,5 @@
+*.swo
+*.swp
+.DS_Store
+node_modules
+.tern-port
34 handlebars.js
@@ -0,0 +1,34 @@
+var fs = require('fs');
+var Handlebars = require('handlebars');
+
+var HandlebarsEngine = function() {
+ this.name = 'handlebars';
+ this.mediaTypes = ['text/html'];
+ this.extension = '.handlebars';
+ this.subdirectory = '/html';
+ this.cache = {};
+};
+
+HandlebarsEngine.prototype.format = function(filename, locals, cb) {
+ if (this.cache.hasOwnProperty(filename)) {
+ var template = this.cache[filename];
+ var body = template(locals);
+ return cb(null, body);
+ }
+
+ var self = this;
+ fs.readFile(filename, function(err, contents) {
+ if (err) {
+ return cb(err);
+ }
+
+ var template = Handlebars.compile(contents.toString());
+ self.cache[filename] = template;
+
+ var body = template(locals);
+ return cb(null, body);
+ });
+};
+
+module.exports = new HandlebarsEngine();
+
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "argo-formatter-handlebars",
+ "version": "0.0.0",
+ "description": "A Handlebars engine for Argo formatter.",
+ "main": "handlebars.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/argo/argo-formatter-handlebars.git"
+ },
+ "keywords": [
+ "handlebars",
+ "formatter"
+ ],
+ "author": "Kevin Swiber <kswiber@gmail.com>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/argo/argo-formatter-handlebars/issues"
+ }
+}

0 comments on commit 6a5a3fa

Please sign in to comment.
Something went wrong with that request. Please try again.