Skip to content

Commit

Permalink
Change/test to support VARIABLES config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulous committed Jul 18, 2011
1 parent c38ae3d commit 2f6fc16
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/js/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"plugins.t.html",
"set.t.html",
"stash.t.html",
"string.t.html"
"string.t.html",
"variables.t.html"
);
</script>
</body>
Expand Down
43 changes: 43 additions & 0 deletions tests/t/variables.t.js
Original file line number Diff line number Diff line change
@@ -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.