Skip to content

Commit

Permalink
Several fixes during testing.
Browse files Browse the repository at this point in the history
in FileSystem.FilePath don't prepend the current working directory if it's a root path. In Template, set the __KEY__ context var when iterating an array. Add additional accessors for Template.Context. Some fixes to Iterable.Shuffle
  • Loading branch information
Whiteknight committed Dec 30, 2011
1 parent 058c486 commit 5af6a1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/filesystem/FilePath.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Rosella.FileSystem.FilePath
self.details["shortname"] = entryname;
self.details["pathseparator"] = pathsep;
self.details["basepath_parts"] = pathparts;
self.details["basepath"] = join(pathsep, pathparts);
self.details["basepath"] = join(pathsep, pathparts) + pathsep;
}

// The file extension, without "."
Expand All @@ -37,8 +37,12 @@ class Rosella.FileSystem.FilePath
// starting at the file system root.
function full_base_path()
{
// TODO: Fix for windows
string base_path = string(self.details["basepath"]);
if (substr(base_path, 0, 1) == "/")
return base_path;
var cwd = Rosella.FileSystem.Directory.current_directory();
return string(cwd) + string(self.details["basepath"]);
return string(cwd) + base_path;
}

// The base path of the file starting from the current working
Expand Down
14 changes: 7 additions & 7 deletions src/query/iterable/Iterators.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ class Rosella.Query.Iterable.Sort : Rosella.Query.Iterable
if (self.sorted == null) {
int is_sorted = int(self.is_sorted);
var d = self.source.to_array();
var f = self.func;
Rosella.Query.sort_array(d, 0, elements(d), f, is_sorted:[named("is_sorted")]);
self.sorted = new Rosella.Query.Iterable.Array(d);
}
Expand Down Expand Up @@ -481,14 +482,13 @@ class Rosella.Query.Iterable.Shuffle : Rosella.Query.Iterable

function next()
{
if (self.shuffled != null) {
if (self.shuffled.has_more())
return self.shuffled.next();
self.__empty();
if (self.shuffled == null) {
var d = self.source.to_array();
Rosella.Random.shuffle_array(d);
self.shuffled = new Rosella.Query.Iterable.Array(d);
}
var d = self.to_array();
Rosella.Random.shuffle_array(d);
self.shuffled = new Rosella.Query.Iterable.Array(d);
if (!self.shuffled.has_more())
self.__empty();
return self.shuffled.next();
}

Expand Down
15 changes: 15 additions & 0 deletions src/template/Context.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,20 @@ namespace Rosella { namespace Template
{
return 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_number_keyed[vtable](var key)
{
return float(self.get_value(key));
}
}
}}
10 changes: 6 additions & 4 deletions src/template/handler/For.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Rosella { namespace Template { namespace Handler
*/
class For : Rosella.Template.Handler.Children
{
const string HASH_KEY_VARNAME = "__KEY__";
const string KEY_VARNAME = "__KEY__";
const string FIRST_VARNAME = "__FIRST__";
const string LAST_VARNAME = "__LAST__";
var varname;
Expand Down Expand Up @@ -41,7 +41,7 @@ namespace Rosella { namespace Template { namespace Handler
else
self.__render_scalar(engine, ctx, sb, values);
}
}, ctx, HASH_KEY_VARNAME, FIRST_VARNAME, LAST_VARNAME);
}, ctx, KEY_VARNAME, FIRST_VARNAME, LAST_VARNAME);
}

/* Internal Helper Routines
Expand All @@ -57,7 +57,7 @@ namespace Rosella { namespace Template { namespace Handler
for (string key in values) {
var value = values[key];
ctx.set_temporary(self.varname, value);
ctx.set_temporary(HASH_KEY_VARNAME, key);
ctx.set_temporary(KEY_VARNAME, key);
ctx.set_temporary(FIRST_VARNAME, is_first);
ctx.set_temporary(LAST_VARNAME, is_last);
self.__render_children(engine, ctx, sb);
Expand All @@ -73,15 +73,17 @@ namespace Rosella { namespace Template { namespace Handler
int is_first = 1;
int num_items = elements(values);
int is_last = num_items == 1;
ctx.set_temporary(HASH_KEY_VARNAME, "");
int idx = 0;
for (var value in values) {
ctx.set_temporary(self.varname, value);
ctx.set_temporary(KEY_VARNAME, idx);
ctx.set_temporary(FIRST_VARNAME, is_first);
ctx.set_temporary(LAST_VARNAME, is_last);
self.__render_children(engine, ctx, sb);
num_items--;
is_last = num_items == 1;
is_first = 0;
idx++;
}
}

Expand Down

0 comments on commit 5af6a1d

Please sign in to comment.