Permalink
Browse files

Change/test to support VARIABLES config option.

  • Loading branch information...
1 parent c38ae3d commit 2f6fc16a37997a898e87cc3fe39be3c49bfe968f @nebulous nebulous committed Jul 18, 2011
Showing with 48 additions and 4 deletions.
  1. +3 −3 src/js/kernel.js
  2. +2 −1 tests/index.html
  3. +43 −0 tests/t/variables.t.js
View
@@ -374,9 +374,9 @@ if (typeof Jemplate.Stash == 'undefined') {
Jemplate.Stash = function(stash, config) {
this.__config__ = config;
- this.data = {
- GLOBAL : this.__config__.SCOPE
- };
+ this.data = config["VARIABLES"];
+ this.data["GLOBAL"] = this.__config__.SCOPE;
+
this.LOCAL_ANCHOR = {};
this.data.LOCAL = this.LOCAL_ANCHOR;
View
@@ -25,7 +25,8 @@
"plugins.t.html",
"set.t.html",
"stash.t.html",
- "string.t.html"
+ "string.t.html",
+ "variables.t.html"
);
</script>
</body>
View
@@ -0,0 +1,43 @@
+var t = new Test.Jemplate();
+
+t.plan(3);
+
+t.compile();
+
+var j = new Jemplate();
+var jVAR = new Jemplate({VARIABLES:{who:'Beaver'}});
+
+var test1 = t.state.blocks.shift();
+t.is(
+ j.process('hello', {who: 'Wally'}),
+ test1.data.output,
+ test1.name
+);
+
+var test2 = t.state.blocks.shift();
+t.is(
+ jVAR.process('hello',{}),
+ test2.data.output,
+ test2.name
+);
+
+var test3 = t.state.blocks.shift();
+t.is(
+ jVAR.process('hello', {who: 'Wally'}),
+ test3.data.output,
+ test3.name
+);
+
+
+/* Test
+=== Test without VARIABLES set in config hash
+--- output
+Hello, Wally!
+=== Test with VARIABLES set in config hash
+--- output
+Hello, Beaver!
+=== Test with VARIABLES set in config hash being overridden by local var
+--- output
+Hello, Wally!
+
+*/

0 comments on commit 2f6fc16

Please sign in to comment.