Skip to content

Commit

Permalink
Item13490: merge out from 2.0.0 core
Browse files Browse the repository at this point in the history
  • Loading branch information
Crawford Currie committed Jun 30, 2015
1 parent 7c96302 commit 39135f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion data/System/TablesContrib.txt
Expand Up @@ -7,7 +7,7 @@ One line description, required for extensions repository catalog.

%SHORTDESCRIPTION%

Foswiki 1.2.0 introduces a new internal API that supports the parsing and modelling of in-topic tables, designed to canonicalise the handling of tables in the core and extensions. This module makes this tables code available to extensions running under Foswiki versions prior to 1.2.
Foswiki 2.0 introduces a new internal API that supports the parsing and modelling of in-topic tables, designed to canonicalise the handling of tables in the core and extensions. This module makes this tables code available to extensions running under Foswiki versions prior to 1.2.

%TOC%

Expand Down
53 changes: 34 additions & 19 deletions lib/Foswiki/Tables/Reader.pm
Expand Up @@ -81,8 +81,16 @@ sub new {
}

my $this = {

# Class used to construct tables
table_class => $table_class,
macro => $table_class->getMacro()

# 'extra' macro, besides TABLE
macro => $table_class->getMacro(),

# List of lines waiting for inclusion in the output,
# as generated by the early_line handler.
waiting => undef
};

return bless( $this, $class );
Expand Down Expand Up @@ -147,25 +155,40 @@ sub parse {
# Parser event handler
# Detect and process the macro recognised by the table class (e.g. EDITTABLE).
# This is recorded as "pending" so it can be applied to the next table read.
# Also procss and remember attributes from the generic TABLE macro.
# Also process and remember attributes from the generic TABLE macro.
sub early_line {
my ( $this, $line ) = @_;
@{ $this->{waiting} } = ();

return 0 unless $this->{meta};

# Process the generic TABLE attributes, and replace whatever was
# there already
my $args = Foswiki::Attrs::findFirstOccurenceAttrs( 'TABLE', $line );
if ($args) {
$args = $this->{meta}->expandMacros($args);
$this->{TABLE} = Foswiki::Attrs->new($args);
# Process generic (EDIT)?TABLE attributes.
# There may be several on the line (yuck)
my $ok = 0;
while ( $line =~ /%(TABLE|$this->{macro})(\{.*?\})?%/s ) {
$ok = 1 if $this->_early_line( $line, $1 );
}
push( @{ $this->{waiting} }, $line ) if $ok && length($line);
return $ok;
}

sub _early_line {
my ( $this, $line, $macro ) = @_;

my $args = Foswiki::Attrs::findFirstOccurenceAttrs( $macro, $line );
return 0 unless defined $args; # whoops

# Remember leading junk, keep trailing for further processing
unless ( $_[1] =~ s/^(.*?)(\%$macro(?:\Q{$args}\E)?%)//s ) {
ASSERT( 0, "$macro in $line" ) if DEBUG;
}

# Can we get a balanced macro expression from the text?
$args = Foswiki::Attrs::findFirstOccurenceAttrs( $this->{macro}, $line );
return 0 unless ( defined $args );
my $spec = $2;
push( @{ $this->{waiting} }, $1 ) if length($1);

$args = $this->{meta}->expandMacros($args);
$this->{TABLE} = Foswiki::Attrs->new($args);

my $attrs = Foswiki::Attrs->new($args);

# Add attributes from the last TABLE macro seen
Expand All @@ -174,14 +197,6 @@ sub early_line {
delete $this->{TABLE};
}

# Remember leading and trailing junk
my $ok = $line =~ m/^(.*?)(\%$this->{macro}(?:\Q{$args}\E)?%)(.*)$/s;
ASSERT($ok) if DEBUG;

push( @{ $this->{waiting} }, $1 ) if defined($1) && length($1);
my $spec = $2;
push( @{ $this->{waiting} }, $3 ) if defined($3) && length($3);

my %read = ( $this->{meta}->getPath() => 1 );
my $session = $this->{meta}->session;
while ( $attrs->{include} ) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Foswiki/Tables/Row.pm
Expand Up @@ -121,7 +121,7 @@ sub isHeader {
}
}
}
return $this->{isHeader};
return $this->{isHeader} || 0;
}

=begin TML
Expand All @@ -136,7 +136,7 @@ sub isFooter {
if ($set) {
$this->{isFooter} = $set;
}
return $this->{isFooter};
return $this->{isFooter} || 0;
}

=begin TML
Expand Down Expand Up @@ -195,8 +195,8 @@ sub setRow {
if ( $n < scalar( @{ $this->{cols} } ) ) {

# Restore the EDITCELL from the old value, if present
if ( $val !~ /%EDITCELL{.*?}%/
&& $this->{cols}->[$n]->{text} =~ m/(%EDITCELL{.*?}%)/ )
if ( $val !~ /%EDITCELL\{.*?\}%/
&& $this->{cols}->[$n]->{text} =~ m/(%EDITCELL\{.*?\}%)/ )
{
$val .= $1;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Foswiki/Tables/Table.pm
Expand Up @@ -76,7 +76,6 @@ The following entries in attrs are supported:

sub new {
my ( $class, $spec, $attrs ) = @_;

my $this = bless(
{
spec => $spec,
Expand Down Expand Up @@ -182,8 +181,8 @@ sub makeConsistent {

my $minRows = $this->getHeaderRows() + $this->getFooterRows();
if ( $this->totalRows() < $minRows ) {
if ( defined $this->{headerrows} ) {
while ( $this->totalRows() < $this->{headerrows} ) {
if ( $this->getHeaderRows() ) {
while ( $this->totalRows() < $this->getHeaderRows() ) {
my @vals =
map { "*$_->{initial_value}*" } @{ $this->{colTypes} };
push( @vals, '*?*' ) unless scalar(@vals);
Expand Down

0 comments on commit 39135f8

Please sign in to comment.