1 /**
2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 */
10 module dextool.plugin.mutate.backend.report.html.tmpl;
11 
12 import arsd.dom : Document, Element, require, Table;
13 
14 @safe:
15 
16 immutable tmplIndexStyle = import("source.css");
17 
18 immutable tmplIndexBody = import("source.html");
19 
20 Document tmplBasicPage() @trusted {
21     auto doc = new Document(`<html lang="en">
22 <head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head>
23 <body></body>
24 </html>
25 `);
26     tmplDefaultCss(doc);
27     return doc;
28 }
29 
30 /// Add the CSS style after the head element.
31 void tmplDefaultCss(Document doc) @trusted {
32     auto s = doc.root.childElements("head")[0].addChild("style");
33     s.appendText(import("default.css"));
34 }
35 
36 Table tmplDefaultTable(Element n, string[] header) @trusted {
37     import std.algorithm : map;
38     import std.array : array;
39     import std.range : enumerate;
40     import std.format : format;
41     import dextool.plugin.mutate.backend.report.html.constants;
42 
43     auto tbl = n.addChild("table").require!Table;
44     tbl.addClass(tableStyle);
45 
46     auto tr = n.parentDocument.createElement("tr");
47     foreach (h; header.enumerate) {
48         auto th = tr.addChild("th", h.value);
49         th.addClass(tableColumnHdrStyle);
50         th.setAttribute("id", format("%s-%d", "col", h.index));
51         th.appendText(" ");
52         th.addChild("i").addClass("right");
53     }
54 
55     tbl.addChild("thead").appendChild(tr);
56 
57     return tbl;
58 }
59 
60 Table tmplDefaultMatrixTable(Element n, string[] header) @trusted {
61     import std.algorithm : map;
62     import std.array : array;
63     import dextool.plugin.mutate.backend.report.html.constants;
64 
65     auto tbl = n.addChild("table").require!Table;
66     tbl.addClass(matrixTableStyle);
67 
68     auto tr = n.parentDocument.createElement("tr");
69     foreach (h; header) {
70         auto th = tr.addChild("th", h);
71         th.addClass(matrixTableHdrStyle);
72     }
73 
74     tbl.addChild("thead").appendChild(tr);
75 
76     return tbl;
77 }