Permalink
Browse files

register and render templates

  • Loading branch information...
1 parent d145403 commit bafbb4b5442312191eea1e7b612206dff954d7d6 @sconover sconover committed Dec 8, 2010
Showing with 82 additions and 4 deletions.
  1. +82 −0 specs/jaml_spec.js
  2. +0 −4 specs/template_spec.js
View
@@ -0,0 +1,82 @@
+require("./spec_helper.js");
+
+describe("Jaml (top-level)", function() {
+
+ beforeEach(function(){
+ Jaml.templates = {}
+ Jaml.helpers = {}
+ })
+
+ 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(){
+ ul(
+ li("red"),
+ li("green")
+ )
+ });
+
+ assert.equal("<ul>\n" +
+ " <li>red</li>\n" +
+ " <li>green</li>\n" +
+ "</ul>\n",
+ Jaml.render("color"));
+ });
+
+ it("works with data passed in", function(){
+ Jaml.register("color", function(widget){
+ ul(
+ li(widget.primaryColor),
+ li(widget.secondaryColor)
+ )
+ });
+
+ assert.equal("<ul>\n" +
+ " <li>red</li>\n" +
+ " <li>green</li>\n" +
+ "</ul>\n",
+ Jaml.render("color", {primaryColor:"red", secondaryColor:"green"} ));
+ });
+
+ it("can have multiple templates", function(){
+ Jaml.register("color", function(widget){
+ ul(
+ li(widget.primaryColor),
+ li(widget.secondaryColor)
+ )
+ });
+
+ Jaml.register("shape", function(widget){
+ p(widget.shape)
+ });
+
+ var christmasTree = {primaryColor:"red", secondaryColor:"green", shape:"round"}
+
+ assert.equal("<ul>\n" +
+ " <li>red</li>\n" +
+ " <li>green</li>\n" +
+ "</ul>\n",
+ Jaml.render("color", christmasTree ));
+
+ assert.equal("<p>round</p>\n",
+ Jaml.render("shape", christmasTree ));
+ });
+
+ it("can override a template by using the same name", function(){
+ var christmasTree = {shape:"round"}
+
+ Jaml.register("shape", function(widget){
+ p(widget.shape)
+ });
+ assert.equal("<p>round</p>\n", Jaml.render("shape", christmasTree ));
+
+ Jaml.register("shape", function(widget){
+ div(widget.shape)
+ });
+ assert.equal("<div>round</div>\n", Jaml.render("shape", christmasTree ));
+
+ });
+
+ });
+});
+
View
@@ -2,10 +2,6 @@ require("./spec_helper.js");
describe("Jaml.Template", function() {
- beforeEach(function(){
- // fooBar = new Jaml.Node("fooBar");
- });
-
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(){

0 comments on commit bafbb4b

Please sign in to comment.