[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. 985e5b0f96e6c358f158b2dd34465978463305e4
Stefan Hornburg
racke at rt.icdevgroup.org
Fri Feb 6 15:59:13 UTC 2009
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Interchange wellwell catalog".
The branch, master has been updated
via 985e5b0f96e6c358f158b2dd34465978463305e4 (commit)
from 4e231341ff74388440111e2006bd8ab68ed48fda (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 985e5b0f96e6c358f158b2dd34465978463305e4
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date: Fri Feb 6 16:58:39 2009 +0100
auxiliary tags for building category hierarchies
-----------------------------------------------------------------------
Summary of changes and diff:
code/category_master.tag | 30 +++++++++++++++++++++
code/category_path.tag | 66 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 0 deletions(-)
create mode 100644 code/category_master.tag
create mode 100644 code/category_path.tag
diff --git a/code/category_master.tag b/code/category_master.tag
new file mode 100644
index 0000000..4f291bd
--- /dev/null
+++ b/code/category_master.tag
@@ -0,0 +1,30 @@
+UserTag category_master Order name parent type
+UserTag category_master AddAttr
+UserTag category_master Routine <<EOR
+sub {
+ my ($name, $parent, $type, $opt) = @_;
+ my ($cat_q, $set, $code, $uri);
+
+ $parent ||= 0;
+ $type ||= '';
+
+ $Tag->perl({tables => 'categories'});
+
+ $cat_q = $Db{categories}->quote($name);
+ $set = $Db{categories}->query(qq{select code from categories where name = $cat_q and parent = $parent});
+
+ if (@$set) {
+ return $set->[0]->[0];
+ }
+
+ # create category
+ $code = $Db{categories}->set_slice('', [qw/name parent type/], [$name, $parent, $type]);
+
+ # determine URI for category
+ $uri = $Tag->category_path({code => $code, showname => 1,
+ filter => 'category_uri', joiner => '/', prefix => $opt->{prefix}});
+ $Db{categories}->set_field($code, 'uri', $uri);
+
+ return $code;
+}
+EOR
diff --git a/code/category_path.tag b/code/category_path.tag
new file mode 100644
index 0000000..db5cd3b
--- /dev/null
+++ b/code/category_path.tag
@@ -0,0 +1,66 @@
+UserTag category_path Order code
+UserTag category_path AddAttr
+UserTag category_path Routine <<EOR
+sub {
+ my ($code, $opt) = @_;
+ my ($parent, @path, $joiner);
+
+ return () unless $code;
+
+ $Tag->perl({tables => 'categories'});
+
+ $path[0] = $code;
+
+ while ($parent = $Db{categories}->field($code, 'parent')) {
+ unshift(@path, $parent);
+ $code = $parent;
+
+ # avoid infinite loop
+ last if @path > 5;
+ }
+
+ if ($opt->{showname}) {
+ my @names;
+
+ for (@path) {
+ push(@names, $Db{categories}->field($_, 'name'));
+ }
+
+ if (ref $opt->{filter} eq 'ARRAY') {
+ for (my $i = 0; $i < @names; $i++) {
+ if ($opt->{filter}[$i]) {
+ $names[$i] = $Tag->filter($opt->{filter}[$i], $names[$i]);
+ }
+ }
+ }
+ elsif ($opt->{filter}) {
+ @names = map {$Tag->filter($opt->{filter}, $_)} @names;
+ }
+
+ if ($opt->{showuri}) {
+ my $uri;
+
+ for (my $i = 0; $i < @path; $i++) {
+ my $uri;
+
+ $uri = $Tag->area($Db{categories}->field($path[$i], 'uri'));
+
+ $names[$i] = qq{<a href="$uri">$names[$i]</a>};
+ }
+ }
+
+ @path = @names;
+ }
+
+ if ($opt->{prefix}) {
+ unshift(@path, $opt->{prefix});
+ }
+
+ if (wantarray()) {
+ return @path;
+ } else {
+ $joiner = $opt->{joiner} || ' ';
+ return join($joiner, @path);
+ }
+}
+EOR
hooks/post-receive
--
Interchange wellwell catalog
More information about the wellwell-devel
mailing list