Commit c671e542 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5422] Template handling improved.

parent e833c576
......@@ -26,16 +26,26 @@ public:
try {
for (auto f : files) {
string cmd = f.substr(0, f.find("."));
cout << "Loading description of command " << cmd;
string cmd = f;
size_t pos = f.find_last_of('/');
if (pos != string::npos) {
cmd = f.substr(pos + 1, -1);
}
cmd = cmd.substr(0, cmd.find("."));
if (cmd == "_template") {
cout << "Skipping template file (_template.json)" << endl;
continue;
}
cout << "Loading description of command " << cmd << "... ";
ElementPtr x = Element::fromJSONFile(f, false);
cout << ".";
cout << "loaded, sanity check...";
sanityCheck(f, x);
cout << ".";
cmds_.insert(make_pair(cmd, x));
cout << "loaded" << endl;
cout << " looks ok." << endl;
cnt++;
}
......@@ -63,7 +73,7 @@ public:
"empty in file " + fname);
}
}
void requireList(const ElementPtr& x, const string& name, const string& fname) {
if (!x->contains(name)) {
isc_throw(Unexpected, "Mandatory '" + name + " field missing while "
......@@ -73,17 +83,17 @@ public:
isc_throw(BadValue, "'" + name + " field is present, but is not a list "
"in file " + fname);
}
ConstElementPtr l = x->get(name);
if (l->size() == 0) {
isc_throw(BadValue, "'" + name + " field is a list, but is empty in file "
+ fname);
}
// todo: check that every element is a string
}
void sanityCheck(const string& fname, const ElementPtr& x) {
requireString(x, "name", fname);
requireString(x, "brief", fname);
......@@ -107,42 +117,42 @@ public:
f << endl;
f << "<!-- autogenerated using cmd_docgen. Do not edit by hand! -->" << endl;
}
void generateOutput() {
stringstream f;
generateCopyright(f);
f << "<chapter xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\" xml:id=\"api\">"
<< endl;
f << " <title>Management API Reference</title>" << endl;
// Generate initial list of commands
f << " <para>Kea currently supports " << cmds_.size() << " commands:" << endl
<< " <orderedlist>" << endl;
for (auto cmd : cmds_) {
f << " <listitem><simpara>" << cmd.first << "</simpara></listitem>" << endl;
}
f << " </orderedlist>" << endl;
f << " </para>" << endl;
// Generate actual commands references.
generateCommands(f);
f << "</chapter>" << endl;
cout << "----------------" << endl;
ofstream file(OUTPUT.c_str(), ofstream::trunc);
file << f.str();
cout << f.str();
// cout << f.str();
cout << "----------------" << endl;
}
void generateCommands(stringstream& f){
for (auto cmd : cmds_) {
f << "<!-- start of " << cmd.first << " -->" << endl;
f << "<section xml:id=\"reference-" << cmd.first << "\">" << endl;
......@@ -163,7 +173,7 @@ void replaceAll(std::string& str, const std::string& from, const std::string& to
start_pos += to.length();
}
}
string escapeString(string txt) {
replaceAll(txt, "<", "&lt;");
......@@ -194,7 +204,7 @@ void generateCommand(stringstream& f, const ElementPtr& cmd) {
<< endl << endl;
// description and examples
f << "<para>Description and examples: See <xref linkend=\"cmd-"
f << "<para>Description and examples: See <xref linkend=\"cmd-"
<< cmd->get("name")->stringValue() << "\"/></para>" << endl << endl;
// Command syntax:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment