/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** * docgen.cc * * Tue Mar 15 11:20:09 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 #include #include #include #include #include #include #include #include #include "doc.h" #include "parse.h" #include "generate.h" #define WIDGETS_DIR "../widgets" #define SERVER_DIR "../../server/src" #define CLIENT_DIR ".." #define OUTPUT "html" QString output; QString header; QString footer; void getInheritedAttributes(QMap > &atts, QMap &docs, QString name) { if(name == "" || atts.contains(name)) return; atts[name] = docs[name].attributes; getInheritedAttributes(atts, docs, docs[name].extends); } void getInheritedMethods(QMap > &meths, QMap &docs, QString name) { if(name == "" || meths.contains(name)) return; meths[name] = docs[name].methods; getInheritedMethods(meths, docs, docs[name].extends); } void writeDoc(QMap &docs, QString name) { Doc doc = docs[name]; QMap > atts; getInheritedAttributes(atts, docs, doc.extends); QMap > meths; getInheritedMethods(meths, docs, doc.extends); QString out = generate(doc, meths, atts, docs); QFile::remove(output + "/" + name + ".html"); QFile ofile(output + "/" + name + ".html"); ofile.open(QIODevice::ReadWrite | QIODevice::Text); ofile.write(header.toStdString().c_str(), header.length()); ofile.write(out.toStdString().c_str()), out.length(); ofile.write(footer.toStdString().c_str(), footer.length()); ofile.close(); } void writeIndex(QMap &docs) { QString out; out += "

Pracro "VERSION" Documentation

\n"; out += "

Overview

\n"; out += "

Clientside

\n"; out += "

Widgets

\n"; out += "
    \n"; QMap::iterator i = docs.begin(); while(i != docs.end()) { Doc &doc = *i; if(doc.tag != "") { out += "
  • ["+doc.name+"] - "+ doc.title+"
  • \n"; } i++; } out += "
\n"; out += "

Classes

\n"; out += "
    \n"; i = docs.begin(); while(i != docs.end()) { Doc &doc = *i; if(doc.classname != "" && doc.clientside) { out += "
  • ["+doc.name+"] - "+ doc.title+"
  • \n"; } i++; } out += "
\n"; out += "

Serverside

\n"; out += "
    \n"; i = docs.begin(); while(i != docs.end()) { Doc &doc = *i; if(doc.classname != "" && doc.serverside) { out += "
  • ["+doc.name+"] - "+ doc.title+"
  • \n"; } i++; } out += "
\n"; QFile::remove(output + "/index.html"); QFile ofile(output + "/index.html"); ofile.open(QIODevice::ReadWrite | QIODevice::Text); ofile.write(header.toStdString().c_str()); ofile.write(out.toStdString().c_str()); ofile.write(footer.toStdString().c_str()); ofile.close(); } int main(int argc, char *argv[]) { QApplication app(argc, argv); output = OUTPUT; QMap docs; QFile hfile("header.html"); hfile.open(QIODevice::ReadOnly | QIODevice::Text); header = hfile.readAll(); QFile ffile("footer.html"); ffile.open(QIODevice::ReadOnly | QIODevice::Text); footer = ffile.readAll(); QDir d; d.mkdir(output); QFile::remove(output + "/style.css"); QFile::copy("style.css", output + "/style.css"); QStringList files; // Widgets { QDir dir(WIDGETS_DIR); QStringList filter; filter << "*.h"; dir.setNameFilters(filter); if(!dir.exists()) return 1; QFileInfoList inflst = dir.entryInfoList(QDir::Files); foreach(QFileInfo inf, inflst) { files.append(inf.absoluteFilePath()); } } // Client { QDir dir(CLIENT_DIR); QStringList filter; filter << "*.h"; dir.setNameFilters(filter); if(!dir.exists()) return 1; QFileInfoList inflst = dir.entryInfoList(QDir::Files); foreach(QFileInfo inf, inflst) { files.append(inf.absoluteFilePath()); } } // Server { QDir dir(SERVER_DIR); QStringList filter; filter << "*.h"; dir.setNameFilters(filter); if(!dir.exists()) return 1; QFileInfoList inflst = dir.entryInfoList(QDir::Files); foreach(QFileInfo inf, inflst) { files.append(inf.absoluteFilePath()); } } foreach(QString file, files) { Doc doc = parse(file); if(doc.title != "" || doc.tag != "" || doc.classname != "") docs[doc.name] = doc; } writeIndex(docs); QMap::iterator i = docs.begin(); while(i != docs.end()) { QString name = i.key(); writeDoc(docs, name); i++; } // return app.exec(); return 0; }