File tree 1 file changed +59
-0
lines changed
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ sub _PGMLTables_init {
2
+ main::PG_restricted_eval(' sub PGMLTable { PGMLTables::PGMLTable(@_) }' );
3
+ }
4
+
5
+ loadMacros(' PGML.pl' );
6
+
7
+ package PGMLTables ;
8
+
9
+ sub wrapTeX { return ' [`' . shift . ' `]' }
10
+
11
+ sub arrayString {
12
+ my $array = shift ;
13
+ for (@$array ) {s / '/ \\ '/ g }
14
+ return " ['" . join (" ','" , @$array ) . " ']" ;
15
+ }
16
+
17
+ sub PGMLopts {
18
+ my $opts = shift ;
19
+ for (keys %$opts ) {
20
+ if (ref ($opts -> {$_ }) eq ' ARRAY' ) {
21
+ $opts -> {$_ } = arrayString($opts -> {$_ });
22
+ } else {
23
+ $opts -> {$_ } =~ s / '/ \\ '/ g ;
24
+ $opts -> {$_ } = " '$opts ->{$_ }'" ;
25
+ }
26
+ }
27
+ return ' {' . join (' , ' , map {" $_ => $opts ->{$_ }" } keys %$opts ) . ' }' ;
28
+ }
29
+
30
+ sub wrapCell {
31
+ my $cell = shift ;
32
+ my $opts ;
33
+ if (ref $cell eq ' ARRAY' ) {
34
+ my $data = shift @$cell ;
35
+ $opts = {@$cell };
36
+ $cell = $data ;
37
+ }
38
+ my $string = " [.$cell .]" ;
39
+ $string .= PGMLopts($opts ) if $opts ;
40
+ return $string ;
41
+ }
42
+
43
+ sub convertRow {
44
+ my $row = shift ;
45
+ return join (' ' , map { wrapCell($_ ) } @$row ) . ' * ' ;
46
+ }
47
+
48
+ sub PGMLTable {
49
+ my $rows = shift ;
50
+ my %opts = @_ ;
51
+ my $table = ' [#' . join (' ' , map { convertRow($_ ) } @$rows ) . ' #]' ;
52
+ if ($opts {layout }) {
53
+ $table .= ' *' ;
54
+ delete $opts {layout };
55
+ }
56
+ $table .= PGMLopts(\%opts ) if %opts ;
57
+ return $table ;
58
+ }
59
+
You can’t perform that action at this time.
0 commit comments