Skip to content

Commit

Permalink
[Template] update class/namespace naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Feb 11, 2012
1 parent 09bc01e commit 144b6e1
Show file tree
Hide file tree
Showing 19 changed files with 696 additions and 750 deletions.
2 changes: 1 addition & 1 deletion src/filesystem/visitor/Function.winxed
Expand Up @@ -25,7 +25,7 @@ class Rosella.FileSystem.Visitor.Function : Rosella.FileSystem.Visitor
push(self.values, arg);
}

// Return the lits of results, if any
// Return the list of results, if any
function result()
{
return self.values;
Expand Down
2 changes: 0 additions & 2 deletions src/include/Core.winxed
@@ -1,5 +1,3 @@
$include_const "iglobals.pasm";

/* Forward declarations
*/
namespace Rosella {
Expand Down
107 changes: 52 additions & 55 deletions src/template/Context.winxed
@@ -1,65 +1,62 @@
namespace Rosella { namespace Template
/* Data Context Wrapper
Provides access to the user data. User data is considered read-only
during the evaluation of the template. Data set is stored in a
separate hash. When looking up a value to read, the temporary data
hash is searched first, followed by the user data.
*/
class Rosella.Template.Context
{
/* Data Context Wrapper
Provides access to the user data. User data is considered read-only
during the evaluation of the template. Data set is stored in a
separate hash. When looking up a value to read, the temporary data
hash is searched first, followed by the user data.
*/
class Context
{
var user_context;
var temps;
var path;
var user_context;
var temps;
var path;

// Constructor
function Context(var user_context)
{
self.user_context = user_context;
self.temps = {};
self.path = new Rosella.Path();
}
// Constructor
function Context(var user_context)
{
self.user_context = user_context;
self.temps = {};
self.path = new Rosella.Path();
}

// Set a temporary value by name
function set_temporary(string key, var value)
{
self.temps[key] = value;
}
// Set a temporary value by name
function set_temporary(string key, var value)
{
self.temps[key] = value;
}

// Get a value by name. Search local temporaries first, user data
// second
function get_value(string key)
{
if (exists self.temps[key])
return self.temps[key];
return self.path.get(self.user_context, key);
}
// Get a value by name. Search local temporaries first, user data
// second
function get_value(string key)
{
if (exists self.temps[key])
return self.temps[key];
return self.path.get(self.user_context, key);
}

// keyed access wrapper. Redirect to set_temporary
function set_pmc_keyed[vtable](var key, var value)
{
self.set_temporary(key, value);
}
// keyed access wrapper. Redirect to set_temporary
function set_pmc_keyed[vtable](var key, var value)
{
self.set_temporary(key, value);
}

// keyed access wrapper. Redirect to get_value
function get_pmc_keyed[vtable](var key)
{
return self.get_value(key);
}
// keyed access wrapper. Redirect to get_value
function get_pmc_keyed[vtable](var key)
{
return self.get_value(key);
}

function get_integer_keyed[vtable](var key)
{
return int(self.get_value(key));
}
function get_integer_keyed[vtable](var key)
{
return int(self.get_value(key));
}

function get_string_keyed[vtable](var key)
{
return string(self.get_value(key));
}
function get_string_keyed[vtable](var key)
{
return string(self.get_value(key));
}

function get_number_keyed[vtable](var key)
{
return float(self.get_value(key));
}
function get_number_keyed[vtable](var key)
{
return float(self.get_value(key));
}
}}
}
5 changes: 1 addition & 4 deletions src/template/Engine.winxed
@@ -1,9 +1,7 @@
namespace Rosella { namespace Template
{
/* Template Engine
This is the main driver type for generating output from templates
*/
class Engine
class Rosella.Template.Engine
{
const string DEFAULT_REGION_NAME = "!!!LiteralRegion!!!";
const int DEFAULT_RECURSE_LIMIT = 10;
Expand Down Expand Up @@ -180,4 +178,3 @@ namespace Rosella { namespace Template
return string(builder);
}
}
}}
111 changes: 54 additions & 57 deletions src/template/Handler.winxed
@@ -1,73 +1,70 @@
namespace Rosella { namespace Template
/* Handler abstract parent type
This is the abstract parent type of the logic handlers. Do not use
this class directly.
*/
class Rosella.Template.Handler
{
/* Handler abstract parent type
This is the abstract parent type of the logic handlers. Do not use
this class directly.
*/
class Handler
{
// Empty constructor.
function Handler(var tokens [optional]) { }
// Empty constructor.
function Handler(var tokens [optional]) { }

// Add a child node
function add_child(var node)
{
Rosella.Error.invalid(__FUNCTION__, "Default Template.Handler does not allow child nodes");
}
// Add a child node
function add_child(var node)
{
Rosella.Error.invalid(__FUNCTION__, "Default Template.Handler does not allow child nodes");
}

// Render contents
function render(var engine, var ctx, var sb)
{
Rosella.Error.must_subclass(__CLASS__);
}
// Render contents
function render(var engine, var ctx, var sb)
{
Rosella.Error.must_subclass(__CLASS__);
}

// This node can have children (Default)
function can_have_children() { return 0; }
// This node can have children (Default)
function can_have_children() { return 0; }

// Execute a routine, saving away a list of values from the context
// to prevent them from being clobbered
function __save_ctx_values(var func, var ctx, var keys [slurpy])
{
var saved = {};
for (string key in keys)
saved[key] = ctx.get_value(key);
// Execute a routine, saving away a list of values from the context
// to prevent them from being clobbered
function __save_ctx_values(var func, var ctx, var keys [slurpy])
{
var saved = {};
for (string key in keys)
saved[key] = ctx.get_value(key);

func();
func();

for (string key in keys)
ctx.set_temporary(key, saved[key]);
}
for (string key in keys)
ctx.set_temporary(key, saved[key]);
}
}

namespace Handler
namespace Rosella.Template.Handler
{
/* Handler type that is able to contain child nodes
*/
class Children : Rosella.Template.Handler
{
/* Handler type that is able to contain child nodes
*/
class Children : Rosella.Template.Handler
{
var children;
var children;

// Constructor.
function Children(var tokens [optional])
{
self.children = [];
}
// Constructor.
function Children(var tokens [optional])
{
self.children = [];
}

// This handler does have child nodes
function can_have_children() { return 1; }
// This handler does have child nodes
function can_have_children() { return 1; }

// Add a child node.
function add_child(var node)
{
push(self.children, node);
}
// Add a child node.
function add_child(var node)
{
push(self.children, node);
}

// Render the contents of all children
function __render_children(var engine, var ctx, var sb)
{
for (var child in self.children)
child.render(engine, ctx, sb);
}
// Render the contents of all children
function __render_children(var engine, var ctx, var sb)
{
for (var child in self.children)
child.render(engine, ctx, sb);
}
}
}}
}
59 changes: 28 additions & 31 deletions src/template/Node.winxed
@@ -1,37 +1,34 @@
namespace Rosella { namespace Template
/* Abstract parent type for Nodes.
Do not use this class directly. Use a subclass
*/
class Rosella.Template.Node
{
/* Abstract parent type for Nodes.
Do not use this class directly. Use a subclass
*/
class Node
{
var contents;
var type;
var contents;
var type;

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

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

// Render contents. Must be subclassed
function render(var engine, var context, var builder)
{
Rosella.Error.must_subclass(__CLASS__);
}
// Render contents. Must be subclassed
function render(var engine, var context, var builder)
{
Rosella.Error.must_subclass(__CLASS__);
}

// assemble this node.
function assemble(var parent_nodes, var current_node)
{
current_node.add_child(self);
return current_node;
}
// assemble this node.
function assemble(var parent_nodes, var current_node)
{
current_node.add_child(self);
return current_node;
}
}}
}
47 changes: 22 additions & 25 deletions src/template/Template.winxed
@@ -1,30 +1,27 @@
namespace Rosella
/* Helper routines for working with Templates
*/
namespace Rosella.Template
{
/* Helper routines for working with Templates
*/
namespace Template
{
const string TEMPLATE_PATH = "rosella/data/templates";
const string TEMPLATE_PATH = "rosella/data/templates";

// Get a standard template file, by looking in certain standard locations.
function get_standard_template_file(string shortname)
{
string filepath = Rosella.FileSystem.join_path_parts(TEMPLATE_PATH, shortname + ".template");
if (Rosella.FileSystem.is_file(filepath))
return filepath;
var config = Rosella.Parrot.get_config_hash();
filepath = Rosella.FileSystem.join_path_parts(config["datadir"], filepath);
if (Rosella.FileSystem.is_file(filepath))
return filepath;
Rosella.Error.invalid(__FUNCTION__, "Cannot find standard template '%s'", shortname);
}
// Get a standard template file, by looking in certain standard locations.
function get_standard_template_file(string shortname)
{
string filepath = Rosella.FileSystem.join_path_parts(TEMPLATE_PATH, shortname + ".template");
if (Rosella.FileSystem.is_file(filepath))
return filepath;
var config = Rosella.Parrot.get_config_hash();
filepath = Rosella.FileSystem.join_path_parts(config["datadir"], filepath);
if (Rosella.FileSystem.is_file(filepath))
return filepath;
Rosella.Error.invalid(__FUNCTION__, "Cannot find standard template '%s'", shortname);
}

// Get the text of a standard template
function get_standard_template_text(string shortname)
{
string filename = get_standard_template_file(shortname);
var file = new Rosella.FileSystem.File(filename);
return file.read_all_text();
}
// Get the text of a standard template
function get_standard_template_text(string shortname)
{
string filename = get_standard_template_file(shortname);
var file = new Rosella.FileSystem.File(filename);
return file.read_all_text();
}
}

0 comments on commit 144b6e1

Please sign in to comment.