[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. 19cde9e2a1293fde74f69e165c6a9744658c2f6f
Stefan Hornburg
racke at rt.icdevgroup.org
Fri Feb 5 13:54:57 UTC 2010
via 19cde9e2a1293fde74f69e165c6a9744658c2f6f (commit)
from c741fbd5e80bbc38b0033b8cf5dda0496f429dcf (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 19cde9e2a1293fde74f69e165c6a9744658c2f6f
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date: Fri Feb 5 14:54:12 2010 +0100
[panel] tag added intended to supersede [table-editor] in later editions
-----------------------------------------------------------------------
Summary of changes and diff:
lib/Vend/Panel.pm | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
create mode 100644 lib/Vend/Panel.pm
diff --git a/lib/Vend/Panel.pm b/lib/Vend/Panel.pm
new file mode 100644
index 0000000..3101555
--- /dev/null
+++ b/lib/Vend/Panel.pm
@@ -0,0 +1,123 @@
+# Vend::Panel - Interchange Panels
+#
+# Copyright (C) 2010 Stefan Hornburg (Racke) <racke at linuxia.de>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Vend::Panel;
+
+use strict;
+use warnings;
+
+use Vend::Config;
+use Vend::Tags;
+use Vend::Data;
+
+# define [panel] tag
+Vend::Config::parse_tag('UserTag', 'panel Order table columns');
+Vend::Config::parse_tag('UserTag', 'panel HasEndTag');
+Vend::Config::parse_tag('UserTag', 'panel AddAttr');
+Vend::Config::parse_tag('UserTag', 'panel MapRoutine Vend::Panel::panel');
+
+sub new {
+ my ($class, @parms) = @_;
+ my $self = {@parms};
+
+ bless $self;
+}
+
+sub panel {
+ my ($table, $columns, $opt, $body) = @_;
+ my ($panel, $db, $set, @out, @cols, $colstr);
+
+ $panel = new Vend::Panel;
+
+ if ($body =~ /\S/) {
+ $panel->parse_simple($body);
+ }
+
+ unless ($columns) {
+ # pull up complete table
+ unless ($db = database_exists_ref($table)) {
+ die ::errmsg('[panel] cannot access table: %s', $table), "\n";
+ }
+
+ # derive columns from template variables
+ for (keys %{$panel->{variables}}) {
+ if ($db->column_exists($_)) {
+ push (@cols, $_);
+ }
+ }
+
+ if (@cols) {
+ $colstr = join(',', @cols);
+ }
+ else {
+ return $body;
+ }
+
+ $set = $db->query({sql => qq{select $colstr from $table}, hashref => 1});
+
+ for (@$set) {
+ push(@out, $panel->fill_simple($_));
+ }
+ }
+
+ return join('', @out);
+}
+
+sub parse_simple {
+ my ($self, $input) = @_;
+
+ pos $input = 0;
+
+ $self->{tokens} = [];
+ $self->{variables} = {};
+
+ while (pos $input < length $input) {
+ if ($input =~ m{ \G (.*?)?\{([A-Z_]+)\} }gcxms) {
+ if (defined $1) {
+ push (@{$self->{tokens}}, $1);
+ }
+ push (@{$self->{tokens}}, '');
+ push (@{$self->{variables}->{lc($2)}}, $#{$self->{tokens}});
+ }
+ else {
+ push (@{$self->{tokens}}, substr($input, pos($input)));
+ last;
+ }
+ }
+
+ return 1;
+}
+
+sub fill_simple {
+ my ($self, $hash) = @_;
+ my ($out, $tokref);
+
+ @$tokref = @{$self->{tokens}};
+
+ for (keys %{$self->{variables}}) {
+ for my $pos (@{$self->{variables}->{$_}}) {
+ $tokref->[$pos] = $hash->{$_};
+ }
+ }
+
+ return join('', @$tokref);
+}
+
+1;
+
hooks/post-receive
--
Interchange wellwell catalog
More information about the wellwell-devel
mailing list