This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / rt / html / Elements / CollectionAsTable / ParseFormat
1 %# BEGIN LICENSE BLOCK;
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24
25 <%ARGS>
26 $Format
27 </%ARGS>
28
29 <%init>
30 use Regexp::Common qw(delimited);
31 my @Columns;
32 #my $quoted = qr[$RE{delimited}{-delim=>qq{\'\"}}|(?:\{|\}|\w|\.)+];
33 my $justquoted = qr[$RE{delimited}{-delim=>qq{\'\"}}];
34 #my $quoted =        $RE{quoted}{-esc};
35 my $word = qr [(?:\{|\}|\w|\.)+];
36
37 while ($Format =~ /($justquoted|$word)/igx) {
38     my $col = $1;
39
40     if ($col =~ /^$RE{quoted}{-esc}$/) {
41         substr($col,0,1) = "";
42         substr($col,-1,1) = "";
43     }
44
45     my $colref;
46     if ( $col =~ s/\/STYLE:(.*?)$//io ) {
47         $colref->{'style'} = $1;
48     }
49     if ( $col =~ s/\/CLASS:(.*?)$//io ) {
50         $colref->{'class'} = $1;
51     }
52     if ( $col =~ s/\/TITLE:(.*?)$//io ) {
53         $colref->{'title'} = $1;
54     }
55     if ( $col =~ /__(.*?)__/gio ) {
56         my @subcols;
57         while ( $col =~ s/^(.*?)__(.*?)__//o ) {
58             push ( @subcols, $1 ) if ($1);
59             push ( @subcols, "__$2__" );
60             $colref->{'attribute'} = $2;
61         }
62         push ( @subcols, $col );
63         @{ $colref->{'output'} } = @subcols;
64     }
65     else {
66         @{ $colref->{'output'} } = ( "__" . $col . "__" );
67         $colref->{'attribute'} = $col;
68     }
69     
70     if ( !$colref->{'title'} && grep { /^__(.*?)__$/io }
71         @{ $colref->{'output'} } )
72     {   
73         $colref->{'title'}     = $1;
74         $colref->{'attribute'} = $1;
75     }
76
77
78     push @Columns, $colref;
79 }
80     return(@Columns);
81 </%init>