1 | :- module(pltables_export_html, [ | |
2 | html_header/2, | |
3 | html_footer/2, | |
4 | html_table_header/2, | |
5 | html_table_footer/2, | |
6 | html_table_rows/2 | |
7 | ]). | |
8 | ||
9 | :- use_module(pltables_export_tools). | |
10 | :- use_module(pltables). | |
11 | ||
12 | :- use_module(probsrc(module_information)). | |
13 | ||
14 | :- use_module(library(lists)). | |
15 | ||
16 | :- module_info(group,pltables). | |
17 | :- module_info(description,'This module is used to export coverage tables to html.'). | |
18 | ||
19 | % ---- | |
20 | % table headers | |
21 | % ---- | |
22 | html_header(S, TableName) :- | |
23 | pltable(TableName, Attributes), | |
24 | write(S,'<html>\n<head>\n'), | |
25 | write(S,'<style type="text/css">\n a {text-decoration: none; color:#000000;}\ntd {border:1px solid black;}\n</style>'), | |
26 | write(S,'</head>\n<body>\n'), | |
27 | ( | |
28 | member(headline(XH), Attributes) | |
29 | -> format(S, '<b>~w</b><br><br>', XH) | |
30 | ; true | |
31 | ), | |
32 | write(S,'<table>\n'). | |
33 | ||
34 | % ---- | |
35 | % table footers | |
36 | % ---- | |
37 | html_footer(S, _TableName) :- | |
38 | write(S,'</table>\n</body>\n</html>'). | |
39 | ||
40 | % ---- | |
41 | % table header / footer | |
42 | % ---- | |
43 | html_table_header(S, TableName) :- | |
44 | pltable(TableName, TableAttributes), | |
45 | pltable_header(TableName, Columns, Attributes), | |
46 | ( | |
47 | member(description(XD, DescAttrs), TableAttributes) | |
48 | -> length(Columns,NumColumns), | |
49 | format(S, '<tr><td colspan="~w" style="border:0px;">', [NumColumns]), | |
50 | (member(bold, DescAttrs) -> write(S, '<b>') ; true), | |
51 | format(S, '~w', [XD]), | |
52 | (member(bold, DescAttrs) -> write(S, '</b>') ; true), | |
53 | write(S, '</td></tr>\n') | |
54 | ; true | |
55 | ), | |
56 | write(S, '<tbody>\n'), | |
57 | write(S, '<tr>'), | |
58 | write_html_table_header(S, Columns, Attributes), | |
59 | write(S, '</tr>'). | |
60 | ||
61 | write_html_table_header(_S, [], []). | |
62 | write_html_table_header(S, [Column | Columns], [Attributes|TAttributes]) :- | |
63 | (member(align(left), Attributes) -> format(S, '<td align="left">~w</td>', [Column]) ; true), | |
64 | (member(align(right), Attributes) -> format(S, '<td align="right">~w</td>', [Column]) ; true), | |
65 | (member(align(center), Attributes) -> format(S, '<td align="center">~w</td>', [Column]) ; true), | |
66 | (\+member(align(_), Attributes) -> format(S, '<td>~w</td>', [Column]) ; true), | |
67 | write_html_table_header(S, Columns, TAttributes). | |
68 | ||
69 | html_table_footer(S, _TableName) :- | |
70 | write(S, '</tbody>\n'). | |
71 | ||
72 | % ---- | |
73 | % table rows | |
74 | % ---- | |
75 | html_table_rows(S, TableName) :- | |
76 | findall(Entries, pltables:pltable_row(TableName, Entries, Attributes), ListOfEntries), | |
77 | findall(Attributes, pltables:pltable_row(TableName, Entries, Attributes), ListOfAttributes), | |
78 | pltables:pltable(TableName, TableAttributes), | |
79 | pltables:pltable_header(TableName, _, ColumnsAttributes), | |
80 | write_html_table_rows(S, ListOfEntries, ListOfAttributes, TableAttributes, ColumnsAttributes). | |
81 | ||
82 | write_html_table_rows(_S, [], [], _TableAttributes, _ColumnsAttributes). | |
83 | write_html_table_rows(S, [Entries | MoreEntries], [RowAttributes | MoreAttributes], TableAttributes, ColumnsAttributes) :- | |
84 | write(S, '<tr>'), | |
85 | write_html_table_row(S, Entries, RowAttributes, TableAttributes, ColumnsAttributes), | |
86 | write(S, '</tr>\n'), | |
87 | write_html_table_rows(S, MoreEntries, MoreAttributes, TableAttributes, ColumnsAttributes). | |
88 | ||
89 | write_html_table_row(_S, [], _RowAttributes, _TableAttributes, []). | |
90 | write_html_table_row(S, [Entry | Entries], RowAttributes, TableAttributes, [ColumnAttribute | ColumnsAttributes]) :- | |
91 | merge_attributes(TableAttributes, ColumnAttribute, TmpAttributes), | |
92 | merge_attributes(TmpAttributes, RowAttributes, MergedAttributes), | |
93 | (member(align(left), MergedAttributes) -> write(S, '<td align="left">') ; true), | |
94 | (member(align(right), MergedAttributes) -> write(S, '<td align="right">') ; true), | |
95 | (member(align(center), MergedAttributes) -> write(S, '<td align="center">') ; true), | |
96 | (\+member(align(_), MergedAttributes) -> write(S, '<td>') ; true), | |
97 | (member(url(URL), MergedAttributes) -> format(S, '<a href="~w">', [URL]) ; true), | |
98 | write(S, '<div style="'), | |
99 | (member(color(C), MergedAttributes) -> format(S, 'color:#~w', [C]) ; true), | |
100 | write(S, '">'), | |
101 | (member(bold, MergedAttributes) -> write(S, '<b>') ; true), | |
102 | format(S, '~w', [Entry]), | |
103 | (member(bold, MergedAttributes) -> write(S, '</b>') ; true), | |
104 | write(S, '</div>'), | |
105 | (member(url(_), MergedAttributes) -> write(S, '</a>') ; true), | |
106 | write(S, '</td>'), | |
107 | write_html_table_row(S, Entries, RowAttributes, TableAttributes, ColumnsAttributes). |