Skip to content

Commit

Permalink
CommonJS compatibility + Jakefile to automate building.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Robinson authored and edspencer committed Jan 23, 2010
1 parent da2cc9c commit 69e82e1
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Jakefile
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 1 addition & 3 deletions Jaml-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Jaml = function() {
}
};
}();

/**
* @constructor
* @param {String} tagName The tag name this node represents (e.g. 'p', 'div', etc)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -321,4 +319,4 @@ Jaml.Template.prototype = {

Jaml.Template.prototype[tagName] = fn(tagName);
};
})();
})();
54 changes: 54 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -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));
Loading

0 comments on commit 69e82e1

Please sign in to comment.