Skip to content

Commit

Permalink
Change around Template.Node and subclasses so they take strings inste…
Browse files Browse the repository at this point in the history
…ad of a Token object
  • Loading branch information
Whiteknight committed Aug 24, 2011
1 parent 58eb23c commit 970809f
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 34 deletions.
12 changes: 7 additions & 5 deletions src/unstable/template/Node.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ namespace Rosella { namespace Template
*/
class Node
{
var token; // The String.Tokenizer.Token object
var contents;
var type;

// Constructor
function Node(var token)
function Node(string contents, string type)
{
self.token = token;
self.contents = contents;
self.type = type;
}

// Get the token type
function type()
{
return self.token.metadata();
return self.type;
}

// Render contents. Must be subclassed
Expand All @@ -25,7 +27,7 @@ namespace Rosella { namespace Template
Rosella.Error.must_subclass(__CLASS__);
}

// assemble this node. Must be subclassed
// assemble this node.
function assemble(var parent_nodes, var current_node)
{
current_node.add_child(self);
Expand Down
4 changes: 2 additions & 2 deletions src/unstable/template/node/Data.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Rosella { namespace Template { namespace Node
class Data : Rosella.Template.Node
{
// Constructor.
function Data(var token) { self.Node(token); }
function Data(string contents, string type) { self.Node(contents, type); }

// Get the value from the context and push it onto the output stream
function render(var engine, var context, var builder)
{
string key = Rosella.String.trim(self.token.data());
string key = Rosella.String.trim(self.contents);
string value = context.get_value(key);
push(builder, value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/unstable/template/node/Eval.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Rosella { namespace Template { namespace Node
const string EVAL_BASE_NAME = "Template_Node_Eval";

// Constructor
function Eval(var token)
function Eval(string contents, string type)
{
self.Node(token);
self.Node(contents, type);
self.func = null;
}

Expand All @@ -21,7 +21,7 @@ namespace Rosella { namespace Template { namespace Node
function render(var engine, var context, var builder)
{
if (self.func == null) {
string code = self.token.data();
string code = self.contents;
self.func = self.compile_func(code);
}
var func = self.func;
Expand Down
4 changes: 2 additions & 2 deletions src/unstable/template/node/Factory.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace Rosella { namespace Template { namespace Node
{
var node;
if (has_factory)
node = Rosella.construct(type_class, token, handler_factory);
node = Rosella.construct(type_class, token.data(), token.metadata(), handler_factory);
else
node = Rosella.construct(type_class, token);
node = Rosella.construct(type_class, token.data(), token.metadata());
return node;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/unstable/template/node/Literal.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Rosella { namespace Template { namespace Node
class Literal : Rosella.Template.Node
{
// Constructor.
function Literal(var token) { self.Node(token); }
function Literal(string contents, string type) { self.Node(contents, type); }

// Render, push the text to the output
function render(var engine, var context, var builder)
{
push(builder, self.token.data());
push(builder, self.contents);
}
}
}}}
6 changes: 3 additions & 3 deletions src/unstable/template/node/Logic.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace Rosella { namespace Template { namespace Node
var logic_name;

// Constructor
function Logic(var token, var handler_factory)
function Logic(string contents, string type, var handler_factory)
{
self.Node(token);
var tokens = self.parse(token.data());
self.Node(contents, type);
var tokens = self.parse(contents);
self.logic_name = tokens.shift();
self.handler = handler_factory.create(self.logic_name, tokens);
}
Expand Down
2 changes: 1 addition & 1 deletion src/unstable/template/node/Master.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Rosella { namespace Template { namespace Node
// Constructor
function Master()
{
self.Node(null);
self.Node("", "");
self.children = [];
}

Expand Down
1 change: 1 addition & 0 deletions t/template/Context.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Test_Rosella_Template_Context
var arg_0 = "foo";
var arg_1 = "bar";
obj.set_temporary(arg_0, arg_1);
self.assert.equal(obj["foo"], "bar");
}

function get_value_user_data() {
Expand Down
13 changes: 5 additions & 8 deletions t/template/Node.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ class Test_Rosella_Template_Node
{
function test_new()
{
var obj = new Rosella.Template.Node(null);
var obj = new Rosella.Template.Node("", "");
self.assert.not_null(obj);
self.assert.instance_of(obj, class Rosella.Template.Node);
}

function type()
{
self.status.verify("Test Rosella.Template.Node.type()");
var token = new Rosella.String.Tokenizer.Token("foo", "bar", "baz");
var obj = new Rosella.Template.Node(token);
var obj = new Rosella.Template.Node("foo", "bar");

var result = obj.type();
self.assert.equal(result, "baz");
self.assert.equal(result, "bar");
}

function render()
{
self.status.verify("Test Rosella.Template.Node.render()");
var token = new Rosella.String.Tokenizer.Token("foo", "bar", "baz");
var obj = new Rosella.Template.Node(token);
var obj = new Rosella.Template.Node("foo", "bar");

self.assert.throws(function() {
var arg_0 = null;
Expand All @@ -34,8 +32,7 @@ class Test_Rosella_Template_Node
function assemble()
{
self.status.verify("Test Rosella.Template.Node.assemble()");
var token = new Rosella.String.Tokenizer.Token("foo", "bar", "baz");
var obj = new Rosella.Template.Node(token);
var obj = new Rosella.Template.Node("foo", "bar");

var nodec = (new Rosella.MockObject.Factory()).create_typed(class Rosella.Template.Node);
nodec.expect_method("add_child").once().with_args(obj);
Expand Down
3 changes: 1 addition & 2 deletions t/template/node/Data.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Test_Rosella_Template_Node_Data
{
function test_new() {
var token = new Rosella.String.Tokenizer.Token("Foo", "Bar", "Baz");
var obj = new Rosella.Template.Node.Data(token);
var obj = new Rosella.Template.Node.Data("Foo", "Bar");
self.assert.not_null(obj);
self.assert.instance_of(obj, class Rosella.Template.Node.Data);
}
Expand Down
3 changes: 1 addition & 2 deletions t/template/node/Eval.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Test_Rosella_Template_Node_Eval
{
function test_new() {
var token = new Rosella.String.Tokenizer.Token("foo", "bar", "baz");
var obj = new Rosella.Template.Node.Eval(token);
var obj = new Rosella.Template.Node.Eval("foo", "bar");
self.assert.not_null(obj);
self.assert.instance_of(obj, class Rosella.Template.Node.Eval);
}
Expand Down
3 changes: 1 addition & 2 deletions t/template/node/Literal.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Test_Rosella_Template_Node_Literal
{
function test_new() {
var token = new Rosella.String.Tokenizer.Token("Foo", "Bar", "Baz");
var obj = new Rosella.Template.Node.Literal(token);
var obj = new Rosella.Template.Node.Literal("Foo", "Bar");
self.assert.not_null(obj);
self.assert.instance_of(obj, class Rosella.Template.Node.Literal);
}
Expand Down
3 changes: 1 addition & 2 deletions t/template/node/Logic.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ class Test_Rosella_Template_Node_Logic
{
function test_new() {
self.status.todo("Figure out how to test this correctly");
var token = new Rosella.String.Tokenizer.Token("Foo", "bar", "baz");
var factory = new Rosella.Template.Handler.Factory({"bar" : new Rosella.Template.Handler});
var obj = new Rosella.Template.Node.Logic(token, factory);
var obj = new Rosella.Template.Node.Logic("Foo", "bar", factory);
self.assert.not_null(obj);
self.assert.instance_of(obj, class Rosella.Template.Node.Logic);
}
Expand Down

0 comments on commit 970809f

Please sign in to comment.