-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CommonJS compatibility + Jakefile to automate building.
- Loading branch information
Showing
9 changed files
with
415 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Oops, something went wrong.