Permalink
Browse files

Polish grain and make corn available via npm

Change-Id: I59ff79e615fced4cef22f8186b92e5b495c00391
  • Loading branch information...
1 parent 623563b commit 953df070c12d047f41f8893d38c23eda4a90b031 @creationix committed Dec 27, 2010
Showing with 27 additions and 11 deletions.
  1. +3 −3 README.markdown
  2. +1 −2 examples/corn.js
  3. +3 −3 { → examples}/testCorn.js
  4. +3 −3 {lib → }/grain.js
  5. +17 −0 package.json
View
@@ -59,9 +59,9 @@ The module itself will also have a `helpers` object that gets mixed into every l
Suppose this simple template language where `@foo` is the variable `foo` and `@bar()` calls the data provider `bar()` and inserts the result inline.
-I would require my compiler like this:
+I would require my compiler like this (corn is included as a sample):
- var compiler = require('./asyncCompiler');
+ var compiler = require('grain/corn');
Now let's suppose this simple template:
@@ -121,7 +121,7 @@ If I wanted a helper that did partials, I would add it like this:
var fs = require('fs');
compiler.helpers = {
partial: function (filename, data, callback) {
- fs.readFile(filename, function (err, text) {
+ fs.readFile(filename, 'utf8', function (err, text) {
if (err) { callback(err); return; }
compiler(text, data, callback);
});
View
@@ -1,5 +1,4 @@
-var grain = require('../lib/grain');
-var Buffer = require('buffer').Buffer;
+var grain = require('../grain');
module.exports = function compile(template, locals, callback) {
var regex = /@([a-z$_][a-z0-9$_]*)\(([^\)]*)\)/g,
@@ -1,4 +1,4 @@
-var Corn = require('./examples/corn');
+var Corn = require('./corn');
var fn = Corn("Hello @world, today is @today().");
console.log(fn +"");
@@ -7,6 +7,6 @@ fn({world:"Earth",today:function (callback) {
callback(null, new Date());
}, 100);
}}, function (err, text) {
- if (err) throw err;
+ if (err) { throw err; }
console.log(text);
-});
+});
@@ -19,12 +19,12 @@ function compile(locals, callback) {
position++;
}
if (stream && pieces.length > 0) {
- stream.emit('data', new Buffer(pieces.join("")));
+ stream.emit('data', pieces.join(""));
}
if (position === chunks.length) {
if (callback) {
- callback(null, new Buffer(chunks.join("")));
+ callback(null, chunks.join(""));
}
if (stream) {
stream.emit('end');
@@ -68,4 +68,4 @@ module.exports = function insert(parts) {
indent + parts.join("\n" + indent) + "\n" +
indent + "// END GENERATED CODE" +
base.substr(match.index + match[0].length);
-}
+}
View
@@ -0,0 +1,17 @@
+{
+ "name": "grain",
+ "description": "Grain is an async framework for node.js template languages",
+ "tags": ["stack", "template", "async"],
+ "version": "0.0.1",
+ "author": "Tim Caswell <tim@creationix.com>",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/creationix/grain.git"
+ },
+ "bugs": "http://github.com/creationix/grain/issues",
+ "engines": ["node >= 0.2.0"],
+ "main": "grain.js",
+ "modules": {
+ "corn": "examples/corn.js"
+ }
+}

0 comments on commit 953df07

Please sign in to comment.