Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Template] update class/namespace naming conventions
- Loading branch information
1 parent
09bc01e
commit 144b6e1
Showing
19 changed files
with
696 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
$include_const "iglobals.pasm"; | ||
|
||
/* Forward declarations | ||
*/ | ||
namespace Rosella { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.