Permalink
Browse files

CommonJS compatibility + Jakefile to automate building.

  • Loading branch information...
Tom Robinson authored and edspencer committed Jan 22, 2010
1 parent da2cc9c commit 69e82e1179f830cf221b0ce1a48c8ea3f23fcc43
Showing with 415 additions and 3 deletions.
  1. +24 −0 Jakefile
  2. +1 −3 Jaml-all.js
  3. +54 −0 examples/example.js
  4. +326 −0 lib/jaml.js
  5. +7 −0 package.json
  6. 0 { → src}/Jaml.js
  7. 0 { → src}/Node.js
  8. 0 { → src}/Template.js
  9. +3 −0 src/commonjs.js
@@ -0,0 +1,24 @@
var FILE = require("file");
var JAKE = require("jake");

JAKE.task("default", ["Jaml-all.js", "lib/jaml.js"]);

JAKE.file("Jaml-all.js", ["src/Jaml.js", "src/Node.js", "src/Template.js"], function(t) {
concat(t.name(), t.prerequisites());
});

JAKE.task("lib/jaml.js", ["Jaml-all.js", "src/commonjs.js"], function(t) {
concat(t.name(), t.prerequisites());
});

function concat(target, sources) {
var f = FILE.open(target, "w", { charset : "UTF-8" });
try {
sources.forEach(function(dep) {
FILE.open(dep, "r", { charset : "UTF-8" }).copy(f).close();
f.write("\n");
});
} finally {
f.close();
}
}
@@ -41,7 +41,6 @@ Jaml = function() {
}
};
}();

/**
* @constructor
* @param {String} tagName The tag name this node represents (e.g. 'p', 'div', etc)
@@ -190,7 +189,6 @@ Jaml.TextNode.prototype = {
return this.text;
}
};

/**
* Represents a single registered template. Templates consist of an arbitrary number
* of trees (e.g. there may be more than a single root node), and are not compiled.
@@ -321,4 +319,4 @@ Jaml.Template.prototype = {

Jaml.Template.prototype[tagName] = fn(tagName);
};
})();
})();
@@ -0,0 +1,54 @@
// CommonJS example

var Jaml = require("jaml").Jaml;

Jaml.register('simple', function() {
p("this is a test");
});

Jaml.register('multi', function() {
p("first sibling");
p("second sibling");
p("third sibling");
});

Jaml.register('nested', function() {
h1("some title");
div(
p("some stuff"),
ul(
li('list'),
li('of'),
li('items')
)
);
});

Jaml.register('product', function(data) {
h2(data.title);
div(
img({src: data.thumbnail}),
p(data.description),
form()
);
});

Jaml.register('category', function(category) {
h1(category.title);
div({cls: 'products'},
Jaml.render('product', category.products)
);
});

var product = {
title: 'My Product',
thumbnail: 'some.jpg',
description: 'It is great!'
};

var category = {
title: "DVDs",
products: [product, product]
};

print(Jaml.render('category', category));
Oops, something went wrong.

0 comments on commit 69e82e1

Please sign in to comment.