diff --git a/specs/index.html b/specs/index.html
index ecde449..f1ee616 100644
--- a/specs/index.html
+++ b/specs/index.html
@@ -2,16 +2,16 @@
"http://www.w3.org/TR/html4/loose.dtd">
- Jasmine Test Runner
-
-
-
+ Jasmine Test Runner
+
+
+
-
+
diff --git a/specs/jaml_spec.js b/specs/jaml_spec.js
index 448edc5..adfc142 100644
--- a/specs/jaml_spec.js
+++ b/specs/jaml_spec.js
@@ -5,7 +5,7 @@ describe("Jaml (top-level)", function() {
beforeEach(function(){
Jaml.templates = {};
})
-
+
describe("you can register a template and then use it to render", function() {
it("works with no data passed in (very simple)", function(){
Jaml.register("color", function(){
@@ -14,11 +14,11 @@ describe("Jaml (top-level)", function() {
li("green")
)
});
-
+
expect(Jaml.render("color")).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n");
});
@@ -29,11 +29,11 @@ describe("Jaml (top-level)", function() {
li(widget.secondaryColor)
)
});
-
+
expect(Jaml.render("color", {primaryColor:"red", secondaryColor:"green"} )).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n");
});
@@ -44,32 +44,32 @@ describe("Jaml (top-level)", function() {
li(widget.secondaryColor)
)
});
-
+
Jaml.register("shape", function(widget){
p(widget.shape)
});
-
+
var christmasTree = {primaryColor:"red", secondaryColor:"green", shape:"round"};
-
+
expect(Jaml.render("color", christmasTree )).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n");
-
+
expect(Jaml.render("shape", christmasTree )).
- toEqual("round
\n");
+ toEqual("round
\n");
});
-
+
it("can override a template by using the same name", function(){
var christmasTree = {shape:"round"};
-
+
Jaml.register("shape", function(widget){
p(widget.shape)
});
expect(Jaml.render("shape", christmasTree )).
toEqual("round
\n");
-
+
Jaml.register("shape", function(widget){
div(widget.shape)
});
@@ -77,7 +77,29 @@ describe("Jaml (top-level)", function() {
toEqual("round
\n");
});
-
- });
+
+
+
+ it("can use a template without registering it", function() {
+ var christmasTree = {shape:"round"};
+ expect(Jaml.render(function(widget){
+ p(widget.shape)
+ }, christmasTree )).
+ toEqual("round
\n");
+ });
+
+ it("can override templates without registering them", function() {
+ var christmasTree = {shape:"round"};
+ expect(Jaml.render({
+ shape: function(widget){
+ p(widget.shape)
+ },
+ div: function(widget){
+ div(render('shape', widget))
+ }
+ }, "div", christmasTree )).
+ toEqual("\n");
+ });
+ });
});
diff --git a/specs/template_spec.js b/specs/template_spec.js
index 43e3d52..4a8d216 100644
--- a/specs/template_spec.js
+++ b/specs/template_spec.js
@@ -1,10 +1,10 @@
require("./spec_helper.js");
describe("Jaml.Template", function() {
-
+
describe("all html tags", function() {
it("a giant integration test for all html tags, so we see what we're allowing." +
- " intentionally locating this at the top of this spec file.", function(){
+ " intentionally locating this at the top of this spec file.", function(){
expect(new Jaml.Template(function(){
html(
head(
@@ -17,7 +17,7 @@ describe("Jaml.Template", function() {
thead(tr(th())),
tfoot(tr(td())),
tbody(tr(td()))
-
+
),
ul(li(), ol()),
dl(), dt(), dd(),
@@ -32,7 +32,7 @@ describe("Jaml.Template", function() {
)
)
)
- }).render()).
+ })._render()).
toEqual("\n" +
" \n" +
" \n \n \n \n" +
@@ -62,7 +62,7 @@ describe("Jaml.Template", function() {
"\n");
});
});
-
+
describe("basic", function() {
it("renders", function(){
expect(new Jaml.Template(function(){
@@ -70,29 +70,29 @@ describe("Jaml.Template", function() {
li("red"),
li("green")
)
- }).render()).
+ })._render()).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n");
});
-
+
it("renders with data", function(){
var theWidget = {primaryColor: "red", secondaryColor: "green"}
-
+
expect(new Jaml.Template(function(widget){
ul(
li(widget.primaryColor),
li(widget.secondaryColor)
)
- }).render(theWidget)).
+ })._render(theWidget)).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n");
- });
+ });
});
-
+
describe("array data", function() {
it("renders the template for each item in the array", function(){
expect(new Jaml.Template(function(widget, i){
@@ -100,22 +100,22 @@ describe("Jaml.Template", function() {
li(widget.primaryColor),
li(widget.secondaryColor)
)
- }).render([
+ })._render([
{primaryColor: "red", secondaryColor: "green"},
{primaryColor: "orange", secondaryColor: "blue"},
{primaryColor: "yellow", secondaryColor: "purple"}
])).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n" +
"\n" +
" orange \n" +
- " blue \n" +
+ " blue \n" +
" \n" +
"\n" +
" yellow \n" +
- " purple \n" +
+ " purple \n" +
" \n");
});
it("renders the template for each item in the array, using thisObj", function(){
@@ -124,26 +124,26 @@ describe("Jaml.Template", function() {
li(widget.primaryColor),
li(widget.secondaryColor)
)
- }).render({data: "test"}, [
+ })._render({data: "test"}, [
{primaryColor: "red", secondaryColor: "green"},
{primaryColor: "orange", secondaryColor: "blue"},
{primaryColor: "yellow", secondaryColor: "purple"}
])).
toEqual("\n" +
" red \n" +
- " green \n" +
+ " green \n" +
" \n" +
"\n" +
" orange \n" +
- " blue \n" +
+ " blue \n" +
" \n" +
"\n" +
" yellow \n" +
- " purple \n" +
+ " purple \n" +
" \n");
});
});
-
-
+
+
});
diff --git a/src/Jaml.js b/src/Jaml.js
index 72e4cb9..f2180ee 100644
--- a/src/Jaml.js
+++ b/src/Jaml.js
@@ -6,9 +6,18 @@
* Introduction: http://edspencer.net/2009/11/jaml-beautiful-html-generation-for-javascript.html
*/
Jaml = function() {
+ var merge = function() {
+ var obj = {};
+ for(var x=0;x