Skip to content

Commit

Permalink
Merge dynatable sub-template into templates
Browse files Browse the repository at this point in the history
All the dynatable sub-templates were single-use in the sense that
they were included in exactly one top-level template.  Simplify
template setup *and* customization options for users by merging
the sub-templates into their parents.
  • Loading branch information
ehuelsmann committed Aug 21, 2024
1 parent c479363 commit 41d74f8
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 486 deletions.
50 changes: 47 additions & 3 deletions templates/demo/display_report.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
<?lsmb# This is a comment block; it's ignored by the template engine.

Version: 1.0
Date: 2021-01-04
Version: 1.1
Date: 2024-08-21
File: display_report.csv
Set: demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version Changes
1.1 Merged 'dynatable.csv' into this template


-?>
<?lsmb PROCESS 'dynatable.csv';
<?lsmb-

BLOCK do_quote ;
IF VALUE.to_output.defined();
value = VALUE.to_output();
ELSE;
value = VALUE;
END;

IF value.match('[^0-9.+-]'); # any non-digit means run escaping
'"'; value.replace('"', '""'); '"'; # " balance the double quotes
ELSE;
value;
END;
END;

BLOCK dynatable;
SKIP_TYPES = ['hidden', 'radio', 'checkbox'];

FOREACH COL IN columns;
IF SKIP_TYPES.grep(COL.type).empty();
UNLESS loop.first();
',';
END;
INCLUDE do_quote VALUE = COL.name;
END;
END;

FOREACH ROW IN tbody.rows;
FOREACH COL IN columns;
COL_ID = COL.col_id;
IF SKIP_TYPES.grep(COL.type).empty();
UNLESS loop.first();
',';
END;
INCLUDE do_quote VALUE = ROW.$COL_ID;
END;
END;
END;
END;


PROCESS dynatable tbody = {rows = rows };
?>
118 changes: 113 additions & 5 deletions templates/demo/display_report.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,127 @@
<?lsmb# This is a comment block; it's ignored by the template engine.

Version: 1.0
Date: 2021-01-04
Version: 1.1
Date: 2024-08-21
File: display_report.html
Set: demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version Changes
1.1 Merged 'dynatable.html' into this template


-?>
<?lsmb
<?lsmb-

# Simplified block from UI/lib/dynatable.html; see that file for docs
BLOCK dynatable -?>
<table id="<?lsmb attributes.id ?>"
class="dynatable <?lsmb attributes.class ?>"
width="<?lsmb attributes.width ?>">
<?lsmb- IF !hide_header -?>
<thead>
<tr>
<?lsmb- FOREACH COL IN columns;
IF COL.type != 'hidden'; -?>
<th class="<?lsmb COL.col_id _ ' ' _ COL.class _ ' ' _ COL.type | html ?>"><?lsmb COL.name | html ?>
</th>
<?lsmb- END; END; -?>
</tr>
</thead>
<?lsmb- END -?>
<tbody>
<?lsmb-
PFX = attributes.input_prefix;
FOREACH ROW IN tbody.rows; -?>
<tr class="<?lsmb ROW.html_class _ ' ' _ ROW.row_id ?>">
<?lsmb- FOREACH COL IN columns;
ROWSPANNED = COL.col_id _ "_ROWSPANNED";
IF ROW.$ROWSPANNED;
NEXT;
END;
ROWSPAN = COL.col_id _ "_ROWSPAN";
IF ROW.$ROWSPAN;
ROWSPAN=" rowspan=\"" _ ROW.$ROWSPAN _ "\"";
ELSE;
ROWSPAN="";
END;

TYPE = COL.type;
NOHREF = COL.col_id _ "_NOHREF";
IF (ROW.NOINPUT AND TYPE != 'href' AND TYPE != 'hidden')
OR (ROW.$NOHREF AND TYPE == 'href');
TYPE = 'text';
END;

NEXT IF TYPE == 'hidden'; -?>
<td class="<?lsmb COL.col_id _ ' ' _ COL.class _ ' ' _ COL.type | html ?>"<?lsmb ROWSPAN ?>>
<?lsmb- IF TYPE == 'boolean_checkmark' OR TYPE == 'checkbox' OR TYPE == 'radio';
IF ROW.${COL.col_id};
'✓';
END;

ELSIF TYPE == 'select';
# ROW is passed as an argument if COL.options is a callback
# function, which allows dropdown options to be dynamically
# customised to each row. The ROW argument is harmlessly
# ignored by Template Toolkit if COL.options is a static
# arrayref common to every row.
OPTION_LIST = COL.options(ROW);

PROCESS "dynatable.html";
FOREACH option IN OPTION_LIST;
IF (option.value | html) == ROW.${COL.col_id};
option.text | html;
END;
END;
ELSE -?>
<?lsmb ROW.${COL.col_id} ?>
<?lsmb- END -?>
</td>
<?lsmb- END; END -?>
</tr>
<?lsmb- END ?>
</tbody>
<?lsmb- IF tfoot -?>
<tfoot>
<?lsmb- FOREACH ROW IN tfoot.rows;
SPACECOUNT = 0 -?>
<tr>
<?lsmb- FOREACH COL IN columns;
COL_ID = COL.col_id;
IF tfoot.coltypes.$COL_ID;
TYPE = tfoot.coltypes.$COL_ID;
ELSE;
TYPE = COL.type;
END;

?>
DOJO = tfoot.dojo_type.$COL_ID;
DOJO_PROPS = tfoot.dojo_props.$COL_ID;
IF tfoot.coltypes.${COL.col_id} == 'spacer';
SPACECOUNT = SPACECOUNT + 1;
ELSE;
IF SPACECOUNT > 0 ?>
<td colspan="<?lsmb SPACECOUNT ?>">&nbsp;</td>
<?lsmb END;
NEXT IF TYPE == 'hidden';
-?>
<td class="<?lsmb COL.col_id | html ?>">
<?lsmb- IF TYPE == 'boolean_checkmark' OR TYPE == 'checkbox' OR TYPE == 'radio';
IF ROW.${COL.col_id};
'✓';
END;
ELSE -?>
<?lsmb ROW.${COL.col_id} ?>
<?lsmb- END -?>
</td>
<?lsmb- END -?>
</tr>
<?lsmb- END -?>
</tfoot>
<?lsmb- END -?>
</table>
<?lsmb- END; -?>
<!DOCTYPE html>
<html>
<head>
Expand Down
66 changes: 58 additions & 8 deletions templates/demo/display_report.odst
Original file line number Diff line number Diff line change
@@ -1,27 +1,77 @@
<?lsmb# This is a comment block; it's ignored by the template engine.

Version: 1.0
Date: 2021-01-04
Version: 1.1
Date: 2024-08-21
File: display_report.odst
Set: demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version Changes
1.1 Merged 'dynatable.odst' into this template

-?>
<?lsmb PROCESS "dynatable.odst"
<?lsmb-

HEADS 2;
BLOCK dynatable;
ROWCOUNT = 1;
IF tbody.rows.size;
ROWCOUNT = ROWCOUNT + tbody.rows.size;
END;
IF tfoot.rows.size;
ROWCOUNT = ROWCOUNT + tbody.rows.size;
END;

IF hlines.size;
-?>
<worksheet name="<?lsmb attributes.id | html ?>" rows="<?lsmb ROWCOUNT ?>" columns="<?lsmb columns.size + 1 ?>">
<format bottom="5" bg_color="lime" bottom_color="magenta">
<?lsmb IF !hide_header -?>
<row>
<?lsmb FOREACH COL IN columns;
IF COL.type != 'hidden'; -?>
<cell text="<?lsmb COL.name | html ?>" />
<?lsmb END; END; ?>
</row>
<?lsmb END -?>
</format>
<format align="right">
<?lsmb FOREACH ROW IN tbody.rows -?>
<row>
<?lsmb FOREACH COL IN columns -?>
<?lsmb IF COL.type != 'hidden'; -?>
<cell text="<?lsmb ROW.${COL.col_id} | html ?>" />
<?lsmb END;
END -?>
</row>
<?lsmb END -?>
<?lsmb- IF tfoot -?>
<?lsmb- FOREACH ROW IN tfoot.rows; ?>
<row>
<?lsmb FOREACH COL IN columns ?>
<?lsmb IF COL.type != 'hidden'; -?>
<cell text="<?lsmb ROW.${COL.col_id} | html ?>" />
<?lsmb END; END ?>
</row>
<?lsmb END;
END ?>
</format>
</worksheet>
<?lsmb

HEADS = HEADS + hlines.size;
END; # BLOCK dynatable


# MAIN template
HEADS = 2;

IF hlines.size;
HEADS = HEADS + hlines.size;
END;

?>
-?>
<workbook>
<worksheet name="<?lsmb text('Title Page') | html ?>" rows="<?lsmb HEADS ?>"
<worksheet name="<?lsmb text('Title Page') | html ?>" rows="<?lsmb HEADS ?>"
columns="2">
<row><cell text="<?lsmb text('Report Name') | html ?>:" />
<cell text="<?lsmb name | html ?>" />
Expand Down
94 changes: 90 additions & 4 deletions templates/demo/display_report.tex
Original file line number Diff line number Diff line change
@@ -1,19 +1,105 @@
<?lsmb# This is a comment block; it's ignored by the template engine.

Version: 1.2
Date: 2022-07-27
Version: 1.3
Date: 2024-08-21
File: display_report.tex
Set: demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version Changes
1.1 Merged xelatex targetting templates with those targetting pdflatex
1.3 Merged 'dynatable.html' into this template
1.2 Simplified report header generation factored out of dynatable
1.1 Merged xelatex targetting templates with those targetting pdflatex


-?>
<?lsmb- PROCESS 'dynatable.tex';
<?lsmb-

BLOCK dynatable;

TOTAL_WIDTH=14; # cm. using A4 as a basis because it is slightly narrower than
# US Letter. This way the dynatable works for both paper sizes.
# This assumes a 1cm margin on either side. --CT
DECLARED_WIDTH=0;

SKIP_TYPES = ['hidden', 'radio', 'checkbox'];


FOREACH COL IN columns;
DECLARED_WIDTH = DECLARED_WIDTH + COL.pwidth; # pwidth is arbitrary scale
END;

IF DECLARED_WIDTH > 0;
WIDTH_PER_P = TOTAL_WIDTH / DECLARED_WIDTH;
ELSE;
WIDTH_PER_P = 1;
END;
?>
\begin{longtable}{<?lsmb-
FOREACH COL IN columns;
IF COL.psep_before;
'|';
END;
IF 1 == SKIP_TYPES.grep(COL.type).size() or COL.html_only;
'';
ELSIF COL.pwidth;
"p{" _ (COL.pwidth * WIDTH_PER_P) _ "cm}";
ELSIF COL.palign;
COL.palign;
ELSE;
'l';
END;
IF COL.psep_after;
'|';
END;
END;
-?>}
<?lsmb
FOREACH COL IN columns;
IF 0 == SKIP_TYPES.grep(COL.type).size() AND ! COL.html_only;
UNLESS loop.first();
' & ';
END;
escape(COL.name);
END;
END;
-?>\tabularnewline
\hline\hline
\endfirsthead
<?lsmb
FOREACH COL IN columns;
IF 0 == SKIP_TYPES.grep(COL.type).size() AND ! COL.html_only;
UNLESS loop.first() ;
' & ';
END;
escape(COL.name);
END;
END;
-?>\tabularnewline
\hline\hline
\endhead
<?lsmb
FOREACH ROW IN tbody.rows;
FOREACH COL IN columns;
IF 0 == SKIP_TYPES.grep(COL.type).size() AND ! COL.html_only;
UNLESS loop.first();
' & ';
END;
?>\begin{tabular}[t]{@{}l@{}}<?lsmb
ROW.${COL.col_id};
?>\end{tabular}<?lsmb
END;
END;
?>\tabularnewline
<?lsmb
END; # FOREACH ?>
\end{longtable}
<?lsmb END; # block dynatable
# MAIN template
SKIP_TYPES = ['hidden', 'radio', 'checkbox'];
COLNUMBER = 0;
Expand Down
Loading

0 comments on commit 41d74f8

Please sign in to comment.