The documentation states that
TWiki:Plugins/EditRowPlugin
is meant to be object-oriented so that it can be easily reused and subclassed.
There is a small code change which would make that goal even easier: Allow a string to be passed into TWiki::Plugins::EditRowPlugin::Table::parseTables as parameter which indicates the Table class to be created. That way, the parseTables routine could be reused by subclasses while currently this routine has to be rewritten for subclasses just so that the proper subclass of Table is created.
--
TWiki:Main/ThomasWeigert
- 14 Aug 2008
Excellent idea!
--
TWiki:Main.CrawfordCurrie
- 14 Aug 2008
We would need a few small changes for
EditRowPlugin to be highly reusable:
- Allow a tag to be passed into Table::parseTables as optional argument, so that we can use other tags to do our custom handling; if no tag is passed, then use EDITABLE
- Allow the erp_active_table parameter to be dependent on the type of table we are handling so that these can be intermixed on a topic
- Do not throw away the attributes from the EDITTABLE. Currently, only the included attributes (and attributes passed as urps are kept. But the attributes in the tag may have additional information or override the included tag).
- For the last option in renderForDisplay, do not hardwire EditRowPlugin as the rest handler. Let that be passed as argument also.
With these two changes, we can write our own driver and use the facilities of this plugin to parse and edit tables.
I have used this to build a frontend that edits tables in an sql data base. It would be great if we had these generic table facilities as Contrib and then many could use them...
--
ThomasWeigert - 29 Sep 2008
I think something along these lines would do. This covers only 1 + 2 above, as I have not figured out yet where 3 is actually showing up...
*** Table.pm.orig 2008-09-28 21:28:16.000000000 -0500
--- Table.pm 2008-09-29 00:04:44.000000000 -0500
***************
*** 23,29 ****
# Returns an array of lines, with those lines that represent editable
# tables plucked out and replaced with references to table objects
sub parseTables {
! my ($text, $web, $topic, $meta, $urps) = @_;
my $active_table = undef;
my $hasRows = 0;
my @tables;
--- 23,29 ----
# Returns an array of lines, with those lines that represent editable
# tables plucked out and replaced with references to table objects
sub parseTables {
! my ($text, $web, $topic, $meta, $urps, $tag, $prefix) = @_;
my $active_table = undef;
my $hasRows = 0;
my @tables;
***************
*** 31,36 ****
--- 31,37 ----
my $disable = 0;
my $openRow = undef;
my @comments;
+ $tag ||= 'EDITTABLE';
$text =~ s/()/
push(@comments, $1); "\001-".scalar(@comments)."-\001"/seg;
***************
*** 59,65 ****
# Process an EDITTABLE. The tag will be associated with the
# next table encountered in the topic.
! if (!$disable && $line =~ s/(%EDITTABLE{(.*)}%)// ) {
my $spec = $1;
my $attrs = new TWiki::Attrs(
TWiki::Func::expandCommonVariables($2, $web, $topic));
--- 60,66 ----
# Process an EDITTABLE. The tag will be associated with the
# next table encountered in the topic.
! if (!$disable && $line =~ s/(%${tag}{(.*)}%)// ) {
my $spec = $1;
my $attrs = new TWiki::Attrs(
TWiki::Func::expandCommonVariables($2, $web, $topic));
***************
*** 113,119 ****
}
$active_table =
new TWiki::Plugins::EditRowPlugin::Table(
! $nTables, 1, $spec, $attrs, $web, $topic);
push(@tables, $active_table);
$hasRows = 0;
next;
--- 114,120 ----
}
$active_table =
new TWiki::Plugins::EditRowPlugin::Table(
! $nTables, 1, $spec, $attrs, $web, $topic, $prefix);
push(@tables, $active_table);
$hasRows = 0;
next;
***************
*** 135,141 ****
my $attrs => new TWiki::Attrs('');
$active_table =
new TWiki::Plugins::EditRowPlugin::Table(
! $nTables, 0, $line, $attrs, $web, $topic);
push(@tables, $active_table);
}
# Note use of LIMIT=-1 on the split so we don't lose empty columns
--- 136,142 ----
my $attrs => new TWiki::Attrs('');
$active_table =
new TWiki::Plugins::EditRowPlugin::Table(
! $nTables, 0, $line, $attrs, $web, $topic, $prefix);
push(@tables, $active_table);
}
# Note use of LIMIT=-1 on the split so we don't lose empty columns
***************
*** 192,202 ****
}
sub new {
! my ($class, $tno, $editable, $spec, $attrs, $web, $topic) = @_;
my $this = bless({}, $class);
$this->{editable} = $editable;
! $this->{number} = $tno;
$this->{spec} = $spec;
$this->{rows} = [];
$this->{topic} = $topic;
--- 193,203 ----
}
sub new {
! my ($class, $tno, $editable, $spec, $attrs, $web, $topic, $prefix) = @_;
my $this = bless({}, $class);
$this->{editable} = $editable;
! $this->{number} = $prefix.$tno;
$this->{spec} = $spec;
$this->{rows} = [];
$this->{topic} = $topic;