diff options
Diffstat (limited to 'client/docgen/generate.cc')
-rw-r--r-- | client/docgen/generate.cc | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/client/docgen/generate.cc b/client/docgen/generate.cc index 5cff6b7..db7d0c9 100644 --- a/client/docgen/generate.cc +++ b/client/docgen/generate.cc @@ -32,6 +32,23 @@ #include <QStringList> #include "genimage.h" +#include "highlight.h" + +static QString generateExamples(QVector<Example> &examples, lang_t lang) +{ + QString out; + QVector<Example>::iterator k = examples.begin(); + while(k != examples.end()) { + Example &e = *k; + out += "<div class=\"example\">\n"; + out += " <div class=\"header\"><span class=\"name\">" + e.name + + "</span></div>\n"; + out += " <pre class=\"code\">" + highlight(e.code, lang) + "</pre>"; + out += "</div>"; + k++; + } + return out; +} static QString function(QString f) { @@ -75,12 +92,18 @@ static QString generateMethods(QVector<Method> meths) QString out; foreach(Method meth, meths) { + QString f = meth.name; + QString name = f.mid(f.indexOf(" ") + 1, + f.indexOf("(") - f.indexOf(" ") - 1); + out += " <div class=\"method\">\n"; - out += " <a name=\"" + meth.name + + out += " <a name=\"" + name + "\"></a><div class=\"name\">" + function(meth.name) + "</div>\n"; out += " <div class=\"description\">" + meth.description + "</div>\n"; - + + out += generateExamples(meth.examples, lua); + if(meth.parameters.size()) { out += " <div class=\"parameters\">\n"; foreach(Parameter parm, meth.parameters) { @@ -150,7 +173,10 @@ static QString generateMethodOverview(Doc &doc, out += "<ul>\n"; foreach(Method meth, meths) { - out += "<li><a href=\"#"+meth.name+"\">"+meth.name+"</a> " + + QString f = meth.name; + QString name = f.mid(f.indexOf(" ") + 1, + f.indexOf("(") - f.indexOf(" ") - 1); + out += "<li><a href=\"#"+name+"\">"+meth.name+"</a> " + meth.description.left(meth.description.indexOf(".") + 1) + "</li>\n"; } out += "</ul>\n"; @@ -158,8 +184,28 @@ static QString generateMethodOverview(Doc &doc, return out; } +static QString extendedBy(QString name, QMap<QString, Doc> &docs) +{ + QString out; + + QMap<QString, Doc>::iterator i = docs.begin(); + while(i != docs.end()) { + Doc &d = i.value(); + if(d.extends == name) { + if(out != "") out += ", "; + out += "<a href=\"" + d.name + ".html\">" + d.name + "</a>"; + } + i++; + } + + if(out != "") out = "Extended by: " + out + "."; + + return out; +} + QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, - QMap<QString, QVector<Attribute> > &atts) + QMap<QString, QVector<Attribute> > &atts, + QMap<QString, Doc> &docs) { QString out; @@ -169,7 +215,8 @@ QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, out += " <div class=\"doc\">\n"; out += " <h1>" + doc.title + "</h1>\n"; if(doc.tag != "" ){ - out += " <div class=\"tagname\"><" + doc.tag + " /></div>\n"; + out += " <div class=\"tagname\"><pre class=\"code\">" + + highlight("<" + doc.tag + " />", xml) + "</pre></div>\n"; } if(doc.container) { @@ -177,10 +224,12 @@ QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, } if(doc.extends != "") { - out += " <div class=\"extends\">Extends: <a href=\""+doc.extends+ + out += " <div class=\"extends\">Extends: <a href=\"" + doc.extends + ".html\">" + doc.extends + "</a></div>\n"; } + out += extendedBy(doc.name, docs); + if(doc.screenshot) { genImage(doc.tag); out += " <div class=\"screenshot\">\n"; @@ -192,6 +241,8 @@ QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, out += doc.description; out += " </div>\n"; + out += generateExamples(doc.examples, xml); + out += " <h2>Attributes</h2>\n"; out += " <div class=\"attributes\">\n"; if(doc.attributes.size()) { @@ -232,21 +283,3 @@ QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, return out; } - -#ifdef TEST_GENERATE -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). -TEST_TRUE(false, "No tests yet!"); - -TEST_END; - -#endif/*TEST_GENERATE*/ |