精简代码
This commit is contained in:
parent
7d14a5a207
commit
4ec73ffe6b
|
@ -534,6 +534,169 @@ QString printer::tools_printer::volumes_paint(const QList<std::shared_ptr<StoryV
|
||||||
return QString("graph scale{ %1 \n %2}").arg(clusters_description).arg(arrows_link);
|
return QString("graph scale{ %1 \n %2}").arg(clusters_description).arg(arrows_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTime>
|
||||||
|
#include <QDebug>
|
||||||
|
void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> access_ptr, const QDir& destination_dir) const
|
||||||
|
{
|
||||||
|
QTime time_stamp = QTime::currentTime();
|
||||||
|
auto tool = *this;
|
||||||
|
tool.build_fragments(access_ptr);
|
||||||
|
tool.build_refers_network(access_ptr);
|
||||||
|
|
||||||
|
tool.fragments_anchors_define(tool.fragment_defines.values(), destination_dir);
|
||||||
|
tool.storylines_anchors_define(tool.storyline_defines.values(), destination_dir);
|
||||||
|
tool.volumes_anchors_define(tool.volume_defines.values(), destination_dir);
|
||||||
|
|
||||||
|
std::function<void(std::shared_ptr<const printer::Access>)> html_output =
|
||||||
|
[](std::shared_ptr<const printer::Access> inst) {
|
||||||
|
auto target_path = inst->pageRefers();
|
||||||
|
QFile tfile(target_path);
|
||||||
|
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
||||||
|
auto html = doc_inst.createElement(u8"html");
|
||||||
|
doc_inst.appendChild(html);
|
||||||
|
|
||||||
|
auto body = doc_inst.createElement(u8"body");
|
||||||
|
html.appendChild(body);
|
||||||
|
|
||||||
|
inst->buildPageHTML(body);
|
||||||
|
|
||||||
|
QTextStream tout(&tfile);
|
||||||
|
doc_inst.save(tout, 2);
|
||||||
|
tout.flush();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto& node : tool.fragment_defines)
|
||||||
|
html_output(node);
|
||||||
|
for (auto& node : tool.storyline_defines)
|
||||||
|
html_output(node);
|
||||||
|
for (auto& node : tool.volume_defines)
|
||||||
|
html_output(node);
|
||||||
|
|
||||||
|
QDir::setCurrent(destination_dir.canonicalPath());
|
||||||
|
auto dot_src = tool.storylines_paint(tool.storyline_defines.values());
|
||||||
|
QFile dot_file(QDir::current().filePath(u8"relates.dot"));
|
||||||
|
if (dot_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QTextStream txt(&dot_file);
|
||||||
|
txt.setCodec(u8"UTF-8");
|
||||||
|
txt << dot_src;
|
||||||
|
txt.flush();
|
||||||
|
}
|
||||||
|
system("dot -Tsvg relates.dot -o relates.svg");
|
||||||
|
|
||||||
|
auto vols_src = tool.volumes_paint(tool.volume_defines.values(), tool.storyline_defines.values());
|
||||||
|
QFile vols_file(QDir::current().filePath(u8"volumes_group.dot"));
|
||||||
|
if (vols_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QTextStream txt(&vols_file);
|
||||||
|
txt.setCodec(u8"UTF-8");
|
||||||
|
txt << vols_src;
|
||||||
|
txt.flush();
|
||||||
|
}
|
||||||
|
system("fdp -Tsvg volumes_group.dot -o volumes_group.svg");
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
QFile tfile("./index.html");
|
||||||
|
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
||||||
|
auto html = doc_inst.createElement(u8"html");
|
||||||
|
doc_inst.appendChild(html);
|
||||||
|
|
||||||
|
auto body = doc_inst.createElement(u8"body");
|
||||||
|
html.appendChild(body);
|
||||||
|
|
||||||
|
auto dom_storyline = doc_inst.createElement("div");
|
||||||
|
auto dom_storyline_title = doc_inst.createElement("h2");
|
||||||
|
dom_storyline_title.appendChild(doc_inst.createTextNode(u8"故事脉络"));
|
||||||
|
dom_storyline.appendChild(dom_storyline_title);
|
||||||
|
body.appendChild(dom_storyline);
|
||||||
|
|
||||||
|
auto lines = tool.storyline_defines.values();
|
||||||
|
std::sort(lines.begin(), lines.end(), [](std::shared_ptr<printer::StoryLine> a, std::shared_ptr<printer::StoryLine> b)->bool {
|
||||||
|
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(a->accessPeers()->element());
|
||||||
|
auto b_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(b->accessPeers()->element());
|
||||||
|
return a_elm->sort() < b_elm->sort();
|
||||||
|
});
|
||||||
|
for (auto& inst_line : lines) {
|
||||||
|
auto dom_line = doc_inst.createElement("p");
|
||||||
|
dom_storyline.appendChild(dom_line);
|
||||||
|
|
||||||
|
auto line_href = doc_inst.createElement("a");
|
||||||
|
line_href.setAttribute(u8"href", u8"file:///" + inst_line->pageRefers());
|
||||||
|
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(inst_line->accessPeers()->element());
|
||||||
|
line_href.appendChild(doc_inst.createTextNode(QString(u8"%1.%2").arg(a_elm->sort()).arg(a_elm->signature())));
|
||||||
|
dom_line.appendChild(line_href);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dom_volume = doc_inst.createElement("div");
|
||||||
|
auto dom_volume_title = doc_inst.createElement("h2");
|
||||||
|
dom_volume_title.appendChild(doc_inst.createTextNode(u8"分卷内容"));
|
||||||
|
dom_volume.appendChild(dom_volume_title);
|
||||||
|
body.appendChild(dom_volume);
|
||||||
|
|
||||||
|
for (auto& inst_volume : tool.volume_defines) {
|
||||||
|
auto dom_volume_ref = doc_inst.createElement("p");
|
||||||
|
dom_volume.appendChild(dom_volume_ref);
|
||||||
|
|
||||||
|
auto volume_href = doc_inst.createElement("a");
|
||||||
|
volume_href.setAttribute(u8"href", u8"file:///" + inst_volume->pageRefers());
|
||||||
|
volume_href.appendChild(doc_inst.createTextNode(inst_volume->accessPeers()->element()->signature()));
|
||||||
|
dom_volume_ref.appendChild(volume_href);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dom_fragment = doc_inst.createElement("div");
|
||||||
|
auto dom_fragment_title = doc_inst.createElement("h2");
|
||||||
|
dom_fragment_title.appendChild(doc_inst.createTextNode(u8"情节集合"));
|
||||||
|
dom_fragment.appendChild(dom_fragment_title);
|
||||||
|
body.appendChild(dom_fragment);
|
||||||
|
|
||||||
|
auto table_cube = doc_inst.createElement(u8"table");
|
||||||
|
dom_fragment.appendChild(table_cube);
|
||||||
|
|
||||||
|
int row_ctrl = 0;
|
||||||
|
QDomElement elm_row;
|
||||||
|
for (auto& inst_frag : tool.fragment_defines) {
|
||||||
|
if (row_ctrl++ % 4 == 0) {
|
||||||
|
elm_row = doc_inst.createElement(u8"tr");
|
||||||
|
table_cube.appendChild(elm_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dom_fragment_ref = doc_inst.createElement("td");
|
||||||
|
elm_row.appendChild(dom_fragment_ref);
|
||||||
|
|
||||||
|
auto frag_href = doc_inst.createElement("a");
|
||||||
|
frag_href.setAttribute(u8"href", u8"file:///" + inst_frag->pageRefers());
|
||||||
|
frag_href.appendChild(doc_inst.createTextNode(inst_frag->accessPeers()->element()->signature()));
|
||||||
|
dom_fragment_ref.appendChild(frag_href);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dom_relate = doc_inst.createElement(u8"div");
|
||||||
|
auto dom_relate_title = doc_inst.createElement(u8"h2");
|
||||||
|
dom_relate_title.appendChild(doc_inst.createTextNode(u8"联系图"));
|
||||||
|
dom_relate.appendChild(dom_relate_title);
|
||||||
|
body.appendChild(dom_relate);
|
||||||
|
|
||||||
|
auto img = doc_inst.createElement(u8"img");
|
||||||
|
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"relates.svg"));
|
||||||
|
dom_relate.appendChild(img);
|
||||||
|
dom_relate.appendChild(doc_inst.createElement("br"));
|
||||||
|
img = doc_inst.createElement(u8"img");
|
||||||
|
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"volumes_group.svg"));
|
||||||
|
dom_relate.appendChild(img);
|
||||||
|
|
||||||
|
QTextStream tout(&tfile);
|
||||||
|
doc_inst.save(tout, 2);
|
||||||
|
tout.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto current_stamp = QTime::currentTime();
|
||||||
|
qDebug().noquote() << QString(u8"%html构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||||
|
qDebug().noquote() << u8"%编译成功:" << destination_dir.absoluteFilePath(u8"index.html");
|
||||||
|
}
|
||||||
|
|
||||||
void printer::AstGenerate::append_tokens(QDomElement _elm, std::shared_ptr<const ast_gen::SyntaxElement> inst) {
|
void printer::AstGenerate::append_tokens(QDomElement _elm, std::shared_ptr<const ast_gen::SyntaxElement> inst) {
|
||||||
auto dom_tokens = doc.createElement(u8"tokens");
|
auto dom_tokens = doc.createElement(u8"tokens");
|
||||||
_elm.appendChild(dom_tokens);
|
_elm.appendChild(dom_tokens);
|
||||||
|
|
|
@ -156,6 +156,8 @@ namespace printer {
|
||||||
|
|
||||||
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> &lines);
|
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> &lines);
|
||||||
QString volumes_paint(const QList<std::shared_ptr<StoryVolume>> &vols, const QList<std::shared_ptr<StoryLine>> &lines);
|
QString volumes_paint(const QList<std::shared_ptr<StoryVolume>> &vols, const QList<std::shared_ptr<StoryLine>> &lines);
|
||||||
|
|
||||||
|
void plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> root, const QDir &destinationdir) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AstGenerate : public lib_parse::TreeVisitor {
|
class AstGenerate : public lib_parse::TreeVisitor {
|
||||||
|
|
|
@ -93,162 +93,8 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html_opt->value().toInt() == 1 && access_ptr) {
|
if (html_opt->value().toInt() == 1 && access_ptr) {
|
||||||
QTime time_stamp = QTime::currentTime();
|
|
||||||
printer::tools_printer tool;
|
printer::tools_printer tool;
|
||||||
tool.build_fragments(access_ptr);
|
tool.plain_html_output(access_ptr, destination_dir);
|
||||||
tool.build_refers_network(access_ptr);
|
|
||||||
|
|
||||||
tool.fragments_anchors_define(tool.fragment_defines.values(), destination_dir);
|
|
||||||
tool.storylines_anchors_define(tool.storyline_defines.values(), destination_dir);
|
|
||||||
tool.volumes_anchors_define(tool.volume_defines.values(), destination_dir);
|
|
||||||
|
|
||||||
std::function<void(std::shared_ptr<const printer::Access>)> html_output =
|
|
||||||
[](std::shared_ptr<const printer::Access> inst) {
|
|
||||||
auto target_path = inst->pageRefers();
|
|
||||||
QFile tfile(target_path);
|
|
||||||
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
|
||||||
auto html = doc_inst.createElement(u8"html");
|
|
||||||
doc_inst.appendChild(html);
|
|
||||||
|
|
||||||
auto body = doc_inst.createElement(u8"body");
|
|
||||||
html.appendChild(body);
|
|
||||||
|
|
||||||
inst->buildPageHTML(body);
|
|
||||||
|
|
||||||
QTextStream tout(&tfile);
|
|
||||||
doc_inst.save(tout, 2);
|
|
||||||
tout.flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto& node : tool.fragment_defines)
|
|
||||||
html_output(node);
|
|
||||||
for (auto& node : tool.storyline_defines)
|
|
||||||
html_output(node);
|
|
||||||
for (auto& node : tool.volume_defines)
|
|
||||||
html_output(node);
|
|
||||||
|
|
||||||
QDir::setCurrent(destination_dir.canonicalPath());
|
|
||||||
auto dot_src = tool.storylines_paint(tool.storyline_defines.values());
|
|
||||||
QFile dot_file(QDir::current().filePath(u8"relates.dot"));
|
|
||||||
if (dot_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QTextStream txt(&dot_file);
|
|
||||||
txt.setCodec(u8"UTF-8");
|
|
||||||
txt << dot_src;
|
|
||||||
txt.flush();
|
|
||||||
}
|
|
||||||
system("dot -Tsvg relates.dot -o relates.svg");
|
|
||||||
|
|
||||||
auto vols_src = tool.volumes_paint(tool.volume_defines.values(), tool.storyline_defines.values());
|
|
||||||
QFile vols_file(QDir::current().filePath(u8"volumes_group.dot"));
|
|
||||||
if (vols_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QTextStream txt(&vols_file);
|
|
||||||
txt.setCodec(u8"UTF-8");
|
|
||||||
txt << vols_src;
|
|
||||||
txt.flush();
|
|
||||||
}
|
|
||||||
system("fdp -Tsvg volumes_group.dot -o volumes_group.svg");
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
QFile tfile("./index.html");
|
|
||||||
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
|
||||||
auto html = doc_inst.createElement(u8"html");
|
|
||||||
doc_inst.appendChild(html);
|
|
||||||
|
|
||||||
auto body = doc_inst.createElement(u8"body");
|
|
||||||
html.appendChild(body);
|
|
||||||
|
|
||||||
auto dom_storyline = doc_inst.createElement("div");
|
|
||||||
auto dom_storyline_title = doc_inst.createElement("h2");
|
|
||||||
dom_storyline_title.appendChild(doc_inst.createTextNode(u8"故事脉络"));
|
|
||||||
dom_storyline.appendChild(dom_storyline_title);
|
|
||||||
body.appendChild(dom_storyline);
|
|
||||||
|
|
||||||
auto lines = tool.storyline_defines.values();
|
|
||||||
std::sort(lines.begin(), lines.end(), [](std::shared_ptr<printer::StoryLine> a, std::shared_ptr<printer::StoryLine> b)->bool {
|
|
||||||
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(a->accessPeers()->element());
|
|
||||||
auto b_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(b->accessPeers()->element());
|
|
||||||
return a_elm->sort() < b_elm->sort();
|
|
||||||
});
|
|
||||||
for (auto& inst_line : lines) {
|
|
||||||
auto dom_line = doc_inst.createElement("p");
|
|
||||||
dom_storyline.appendChild(dom_line);
|
|
||||||
|
|
||||||
auto line_href = doc_inst.createElement("a");
|
|
||||||
line_href.setAttribute(u8"href", u8"file:///" + inst_line->pageRefers());
|
|
||||||
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(inst_line->accessPeers()->element());
|
|
||||||
line_href.appendChild(doc_inst.createTextNode(QString(u8"%1.%2").arg(a_elm->sort()).arg(a_elm->signature())));
|
|
||||||
dom_line.appendChild(line_href);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dom_volume = doc_inst.createElement("div");
|
|
||||||
auto dom_volume_title = doc_inst.createElement("h2");
|
|
||||||
dom_volume_title.appendChild(doc_inst.createTextNode(u8"分卷内容"));
|
|
||||||
dom_volume.appendChild(dom_volume_title);
|
|
||||||
body.appendChild(dom_volume);
|
|
||||||
|
|
||||||
for (auto& inst_volume : tool.volume_defines) {
|
|
||||||
auto dom_volume_ref = doc_inst.createElement("p");
|
|
||||||
dom_volume.appendChild(dom_volume_ref);
|
|
||||||
|
|
||||||
auto volume_href = doc_inst.createElement("a");
|
|
||||||
volume_href.setAttribute(u8"href", u8"file:///" + inst_volume->pageRefers());
|
|
||||||
volume_href.appendChild(doc_inst.createTextNode(inst_volume->accessPeers()->element()->signature()));
|
|
||||||
dom_volume_ref.appendChild(volume_href);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dom_fragment = doc_inst.createElement("div");
|
|
||||||
auto dom_fragment_title = doc_inst.createElement("h2");
|
|
||||||
dom_fragment_title.appendChild(doc_inst.createTextNode(u8"情节集合"));
|
|
||||||
dom_fragment.appendChild(dom_fragment_title);
|
|
||||||
body.appendChild(dom_fragment);
|
|
||||||
|
|
||||||
auto table_cube = doc_inst.createElement(u8"table");
|
|
||||||
dom_fragment.appendChild(table_cube);
|
|
||||||
|
|
||||||
int row_ctrl = 0;
|
|
||||||
QDomElement elm_row;
|
|
||||||
for (auto& inst_frag : tool.fragment_defines) {
|
|
||||||
if (row_ctrl++ % 4 == 0) {
|
|
||||||
elm_row = doc_inst.createElement(u8"tr");
|
|
||||||
table_cube.appendChild(elm_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dom_fragment_ref = doc_inst.createElement("td");
|
|
||||||
elm_row.appendChild(dom_fragment_ref);
|
|
||||||
|
|
||||||
auto frag_href = doc_inst.createElement("a");
|
|
||||||
frag_href.setAttribute(u8"href", u8"file:///" + inst_frag->pageRefers());
|
|
||||||
frag_href.appendChild(doc_inst.createTextNode(inst_frag->accessPeers()->element()->signature()));
|
|
||||||
dom_fragment_ref.appendChild(frag_href);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dom_relate = doc_inst.createElement(u8"div");
|
|
||||||
auto dom_relate_title = doc_inst.createElement(u8"h2");
|
|
||||||
dom_relate_title.appendChild(doc_inst.createTextNode(u8"联系图"));
|
|
||||||
dom_relate.appendChild(dom_relate_title);
|
|
||||||
body.appendChild(dom_relate);
|
|
||||||
|
|
||||||
auto img = doc_inst.createElement(u8"img");
|
|
||||||
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"relates.svg"));
|
|
||||||
dom_relate.appendChild(img);
|
|
||||||
dom_relate.appendChild(doc_inst.createElement("br"));
|
|
||||||
img = doc_inst.createElement(u8"img");
|
|
||||||
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"volumes_group.svg"));
|
|
||||||
dom_relate.appendChild(img);
|
|
||||||
|
|
||||||
QTextStream tout(&tfile);
|
|
||||||
doc_inst.save(tout, 2);
|
|
||||||
tout.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto current_stamp = QTime::currentTime();
|
|
||||||
qDebug().noquote() << QString(u8"%html构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
|
||||||
qDebug().noquote() << u8"%编译成功:" << destination_dir.absoluteFilePath(u8"index.html");
|
|
||||||
}
|
}
|
||||||
else if (access_ptr) {
|
else if (access_ptr) {
|
||||||
QTime time_stamp = QTime::currentTime();
|
QTime time_stamp = QTime::currentTime();
|
||||||
|
|
Loading…
Reference in New Issue