diff options
Diffstat (limited to 'client/docgen/generate.cc')
-rw-r--r-- | client/docgen/generate.cc | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/client/docgen/generate.cc b/client/docgen/generate.cc new file mode 100644 index 0000000..73734a5 --- /dev/null +++ b/client/docgen/generate.cc @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * generate.cc + * + * Thu Mar 24 12:09:33 CET 2011 + * Copyright 2011 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "generate.h" + +#include <QTextStream> +#include <QDate> + +#include "genimage.h" + +static QString generateMethods(QVector<Method> meths) +{ + QString out; + + foreach(Method meth, meths) { + out += " <div class=\"method\">\n"; + out += " <a name=\"" + meth.name + + "\"></a><div class=\"name\">" + meth.name + "</div>\n"; + out += " <div class=\"description\">" + meth.description + + "</div>\n"; + + if(meth.parameters.size()) { + out += " <div class=\"parameters\">\n"; + foreach(Parameter parm, meth.parameters) { + out += " <div class=\"parameter\">\n"; + out += " <div class=\"name\">" + parm.name + "</div>\n"; + out += " <div class=\"description\">" + + parm.description + "</div>\n"; + out += " </div>\n"; + } + out += " </div>\n"; + } + + if(meth.returns != "") { + out += " <div class=\"returns\"><strong>Returns</strong> " + + meth.returns + "</div>\n"; + } + + out += " </div>\n"; + } + + return out; +} + +static QString generateAttributes(QVector<Attribute> attrs) +{ + QString out; + + foreach(Attribute attr, attrs) { + out += " <div class=\"attribute\">\n"; + out += " <div class=\"name\">" + attr.name + "</div>\n"; + out += " <div class=\"description\">" + attr.description + + "</div>\n"; + out += " </div>\n"; + } + + return out; +} + +static QString generateMethodOverview(Doc &doc, + QMap<QString, QVector<Method> > &imeths) + +{ + QString out; + + out += "<h2>Method overview</h2>\n"; + + QVector<Method> meths; + + meths += doc.methods; + + QMap<QString, QVector<Method> >::iterator j = imeths.begin(); + while(j != imeths.end()) { + meths += j.value(); + j++; + } + + // sort + for(int i = 0; i < meths.size(); i++) { + for(int j = 0; j < meths.size(); j++) { + if(meths[i].name < meths[j].name) { + Method tmp = meths[i]; + meths[i] = meths[j]; + meths[j] = tmp; + } + } + } + + out += "<ul>\n"; + foreach(Method meth, meths) { + out += "<li><a href=\"#"+meth.name+"\">"+meth.name+"</a> " + + meth.description.left(meth.description.indexOf(".") + 1) + "</li>\n"; + } + out += "</ul>\n"; + + return out; +} + +QString generate(Doc &doc, QMap<QString, QVector<Method> > &meths, + QMap<QString, QVector<Attribute> > &atts) +{ + QString out; + + out += " <div class=\"header\"><a href=\"index.html\">Overview</a>" + "</div>\n"; + + out += " <div class=\"doc\">\n"; + out += " <h1>" + doc.title + "</h1>\n"; + if(doc.tag != "" ){ + out += " <div class=\"tagname\"><" + doc.tag + " /></div>\n"; + } + + if(doc.container) { + out += " <div class=\"container\">Widget is a container.</div>\n"; + } + + if(doc.extends != "") { + out += " <div class=\"extends\">Extends: <a href=\""+doc.extends+ + ".html\">" + doc.extends + "</a></div>\n"; + } + + if(doc.screenshot) { + genImage(doc.tag); + out += " <div class=\"screenshot\">\n"; + out += " <img src=\"gfx/" + doc.tag + ".png\"/>\n"; + out += " </div>\n"; + } + + out += " <div class=\"description\">\n"; + out += doc.description; + out += " </div>\n"; + + out += " <h2>Attributes</h2>\n"; + out += " <div class=\"attributes\">\n"; + if(doc.attributes.size()) { + out += generateAttributes(doc.attributes); + } + + QMap<QString, QVector<Attribute> >::iterator i = atts.begin(); + while(i != atts.end()) { + out += " <h3>Attributes inherited from <a href=\"" + i.key() + + ".html\">"+i.key()+"</a>:</h3>\n"; + out += generateAttributes(i.value()); + i++; + } + out += " </div>\n"; + + out += generateMethodOverview(doc, meths); + + out += " <h2>Methods</h2>\n"; + out += " <div class=\"methods\">\n"; + if(doc.methods.size()) { + out += generateMethods(doc.methods); + } + + QMap<QString, QVector<Method> >::iterator j = meths.begin(); + while(j != meths.end()) { + out += " <h3>Methods inherited from <a href=\"" + j.key() + + ".html\">"+j.key()+"</a>:</h3>\n"; + out += generateMethods(j.value()); + j++; + } + out += " </div>\n"; + + out += " </div>\n"; + + out += " <div class=\"footer\">This documentation is generated for" + " Pracro version "VERSION" at "+QDate::currentDate().toString()+"</div>\n"; + 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*/ |