1 | /*
|
2 | * Souffle - A Datalog Compiler
|
3 | * Copyright (c) 2016, The Souffle Developers. All rights reserved
|
4 | * Licensed under the Universal Permissive License v 1.0 as shown at:
|
5 | * - https://opensource.org/licenses/UPL
|
6 | * - <souffle root>/licenses/SOUFFLE-UPL.txt
|
7 | */
|
8 |
|
9 | #pragma once
|
10 |
|
11 | #include "souffle/profile/htmlCssChartist.h"
|
12 | #include "souffle/profile/htmlCssStyle.h"
|
13 | #include "souffle/profile/htmlJsChartistMin.h"
|
14 | #include "souffle/profile/htmlJsChartistPlugin.h"
|
15 | #include "souffle/profile/htmlJsMain.h"
|
16 | #include "souffle/profile/htmlJsTableSort.h"
|
17 | #include "souffle/profile/htmlJsUtil.h"
|
18 | #include "souffle/profile/htmlMain.h"
|
19 | #include <sstream>
|
20 | #include <string>
|
21 |
|
22 | namespace souffle {
|
23 | namespace profile {
|
24 |
|
25 | /*
|
26 | * Class linking the html, css, and js into one html file
|
27 | * so that a data variable can be inserted in the middle of the two strings and written to a file.
|
28 | *
|
29 | */
|
30 | class HtmlGenerator {
|
31 | public:
|
32 | static std::string getHtml(std::string json) {
|
33 | return getFirstHalf() + json + getSecondHalf();
|
34 | }
|
35 |
|
36 | protected:
|
37 | static std::string getFirstHalf() {
|
38 | std::stringstream ss;
|
39 | ss << html::htmlHeadTop << HtmlGenerator::wrapCss(html::cssChartist) << wrapCss(html::cssStyle)
|
40 | << html::htmlHeadBottom << html::htmlBodyTop << "<script>data=";
|
41 | return ss.str();
|
42 | }
|
43 | static std::string getSecondHalf() {
|
44 | std::stringstream ss;
|
45 | ss << "</script>" << wrapJs(html::jsTableSort) << wrapJs(html::jsChartistMin)
|
46 | << wrapJs(html::jsChartistPlugin) << wrapJs(html::jsUtil) << wrapJs(html::jsMain)
|
47 | << html::htmlBodyBottom;
|
48 | return ss.str();
|
49 | }
|
50 | static std::string wrapCss(const std::string& css) {
|
51 | return "<style>" + css + "</style>";
|
52 | }
|
53 | static std::string wrapJs(const std::string& js) {
|
54 | return "<script>" + js + "</script>";
|
55 | }
|
56 | };
|
57 |
|
58 | } // namespace profile
|
59 | } // namespace souffle
|