/* -*- 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 #include #include #include "genimage.h" #include "highlight.h" static QString generateExamples(QVector &examples, lang_t lang) { QString out; QVector::iterator k = examples.begin(); while(k != examples.end()) { Example &e = *k; out += "
\n"; out += "
" + e.name + "
\n"; out += "
" + highlight(e.code, lang) + "
"; out += "
"; k++; } return out; } static QString function(QString f) { QString out; if(f.indexOf(" ") > f.indexOf("(") || f.indexOf(" ") == -1) { printf("MISSING return type in \"%s\".\n", f.toStdString().c_str()); return f; } QString ret = f.left(f.indexOf(" ")); QString name = f.mid(f.indexOf(" ") + 1, f.indexOf("(") - f.indexOf(" ") - 1); QString ps = f.mid(f.indexOf("(") + 1, f.indexOf(")") - f.indexOf("(") - 1); QStringList parms = ps.split(","); out += "" + ret + " "; out += "" + name + ""; out += "("; for(int i = 0; i < parms.size(); i++) { QStringList l = parms.at(i).split(" ", QString::SkipEmptyParts); if(l.length() != 2) { out += parms.at(i); continue; } QString type = l.at(0); QString name = l.at(1); if(i != 0) out += ", "; out += "" + type + ""; out += " " + name + ""; } out += ")"; return out; } static QString generateMethods(QVector meths) { QString out; foreach(Method meth, meths) { QString f = meth.name; QString name = f.mid(f.indexOf(" ") + 1, f.indexOf("(") - f.indexOf(" ") - 1); out += "
\n"; out += "
" + function(meth.name) + "
\n"; out += "
" + meth.description + "
\n"; out += generateExamples(meth.examples, lua); if(meth.parameters.size()) { out += "
\n"; foreach(Parameter parm, meth.parameters) { out += "
\n"; out += "
" + parm.name + "
\n"; out += "
" + parm.description + "
\n"; out += "
\n"; } out += "
\n"; } if(meth.returns != "") { out += "
Returns " + meth.returns + "
\n"; } out += "
\n"; } return out; } static QString generateAttributes(QVector attrs) { QString out; foreach(Attribute attr, attrs) { out += "
\n"; out += "
" + attr.name + "
\n"; out += "
" + attr.description + "
\n"; out += "
\n"; } return out; } static QString generateMethodOverview(Doc &doc, QMap > &imeths) { QString out; out += "

Method overview

\n"; QVector meths; meths += doc.methods; QMap >::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 += "
    \n"; foreach(Method meth, meths) { QString f = meth.name; QString name = f.mid(f.indexOf(" ") + 1, f.indexOf("(") - f.indexOf(" ") - 1); out += "
  • "+meth.name+" " + meth.description.left(meth.description.indexOf(".") + 1) + "
  • \n"; } out += "
\n"; return out; } static QString extendedBy(QString name, QMap &docs) { QString out; QMap::iterator i = docs.begin(); while(i != docs.end()) { Doc &d = i.value(); if(d.extends == name) { if(out != "") out += ", "; out += "" + d.name + ""; } i++; } if(out != "") out = "Extended by: " + out + "."; return out; } QString generate(Doc &doc, QMap > &meths, QMap > &atts, QMap &docs) { QString out; out += " \n"; out += "
\n"; out += "

" + doc.title + "

\n"; if(doc.tag != "" ){ out += "
" +
      highlight("<" + doc.tag + " />", xml) + "
\n"; } if(doc.serverside) out += "
Available serverside.
\n"; if(doc.clientside) out += "
Available clientside.
\n"; if(doc.classname != "" ){ out += "
Class
" +
      doc.classname + "
\n"; } if(doc.container) { out += "
Widget is a container.
\n"; } if(doc.extends != "") { out += " \n"; } out += extendedBy(doc.name, docs); int idx = 0; QVector::iterator si = doc.screenshots.begin(); while(si != doc.screenshots.end()) { Screenshot &s = *si; QString imgfile = genImage(s.xml, idx++); out += "
\n"; out += "
\n"; out += " "+s.caption+"\n"; out += "
\n"; si++; } out += "
\n"; out += doc.description; out += "
\n"; out += generateExamples(doc.examples, xml); if(doc.tag != "") { out += "

Attributes

\n"; out += "
\n"; if(doc.attributes.size()) { out += generateAttributes(doc.attributes); } QMap >::iterator i = atts.begin(); while(i != atts.end()) { out += "

Attributes inherited from "+i.key()+":

\n"; out += generateAttributes(i.value()); i++; } out += "
\n"; } out += generateMethodOverview(doc, meths); out += "

Methods

\n"; out += "
\n"; if(doc.methods.size()) { out += generateMethods(doc.methods); } QMap >::iterator j = meths.begin(); while(j != meths.end()) { out += "

Methods inherited from "+j.key()+":

\n"; out += generateMethods(j.value()); j++; } out += "
\n"; out += "
\n"; out += "
This documentation is generated for" " Pracro" " version "VERSION" at "+QDate::currentDate().toString()+"
\n"; return out; }