Permalink
Browse files

Added generating template files and reading templates from disk if pr…

…esent
  • Loading branch information...
Dimitri van Heesch
Dimitri van Heesch committed Feb 28, 2016
1 parent f7a0514 commit d38d33cef2241cd8d29c99f519d21ae225453357
Showing with 64 additions and 7 deletions.
  1. +20 −2 src/context.cpp
  2. +1 −0 src/context.h
  3. +7 −0 src/doxygen.cpp
  4. +5 −2 src/resourcemgr.cpp
  5. +2 −2 src/resourcemgr.h
  6. +26 −1 src/template.cpp
  7. +3 −0 src/template.h
@@ -46,12 +46,11 @@
#include "arguments.h"
#include "groupdef.h"
#include "searchindex.h"
#include "resourcemgr.h"
// TODO: pass the current file to Dot*::writeGraph, so the user can put dot graphs in other
// files as well
#define ADD_PROPERTY(name) addProperty(#name,this,&Private::name);
enum ContextOutputFormat
{
ContextOutputFormat_Unspecified=0,
@@ -10168,6 +10167,7 @@ void generateOutputViaTemplate()
//if (Config_getBool(GENERATE_HTML))
{ // render HTML output
e.setTemplateDir("templates/html"); // TODO: make template part user configurable
Template *tpl = e.loadByName("htmllayout.tpl",1);
if (tpl)
{
@@ -10192,6 +10192,7 @@ void generateOutputViaTemplate()
//if (Config_getBool(GENERATE_LATEX))
if (0)
{ // render LaTeX output
e.setTemplateDir("templates/latex"); // TODO: make template part user configurable
Template *tpl = e.loadByName("latexlayout.tpl",1);
if (tpl)
{
@@ -10241,3 +10242,20 @@ void generateOutputViaTemplate()
#endif
}
void generateTemplateFiles(const char *templateDir)
{
if (!templateDir) return;
QDir thisDir;
if (!thisDir.exists(templateDir) && !thisDir.mkdir(templateDir))
{
err("Failed to create output directory '%s'\n",templateDir);
return;
}
QCString outDir = QCString(templateDir)+"/html";
if (!thisDir.exists(outDir) && !thisDir.mkdir(outDir))
{
err("Failed to create output directory '%s'\n",templateDir);
return;
}
ResourceMgr::instance().writeCategory("html",outDir);
}
@@ -1347,5 +1347,6 @@ class SearchIndicesContext : public RefCountedContext, public TemplateListIntf
//----------------------------------------------------
void generateOutputViaTemplate();
void generateTemplateFiles(const char *templateDir);
#endif
@@ -10417,6 +10417,13 @@ void readConfiguration(int argc, char **argv)
Config::init();
if (genConfig && g_useOutputTemplate)
{
generateTemplateFiles("templates");
cleanUpDoxygen();
exit(0);
}
if (genConfig)
{
generateConfigFile(configName,shortList);
@@ -56,16 +56,19 @@ void ResourceMgr::registerResources(const Resource resources[],int numResources)
}
}
bool ResourceMgr::copyCategory(const char *categoryName,const char *targetDir) const
bool ResourceMgr::writeCategory(const char *categoryName,const char *targetDir) const
{
QDictIterator<Resource> it(p->resources);
const Resource *res;
for (it.toFirst();(res=it.current());++it)
{
if (qstrcmp(res->category,categoryName)==0)
{
if (!copyResource(res->name,targetDir))
QCString pathName = QCString(targetDir)+"/"+res->name;
QFile f(pathName);
if (!f.open(IO_WriteOnly) || f.writeBlock((const char *)res->data,res->size)!=res->size)
{
err("Failed to write resource '%s' to directory '%s'\n",res->name,targetDir);
return FALSE;
}
}
@@ -38,8 +38,8 @@ class ResourceMgr
/** Registers an array of resources */
void registerResources(const Resource resources[],int numResources);
/** Copies all resource belonging to a given category to a given target directory */
bool copyCategory(const char *categoryName,const char *targetDir) const;
/** Writes all resource belonging to a given category to a given target directory */
bool writeCategory(const char *categoryName,const char *targetDir) const;
/** Copies a registered resource to a given target directory */
bool copyResource(const char *name,const char *targetDir) const;
@@ -5027,8 +5027,23 @@ class TemplateEngine::Private
//printf("loadByName(%s,%d) {\n",fileName.data(),line);
m_includeStack.append(new IncludeEntry(IncludeEntry::Template,fileName,QCString(),line));
Template *templ = m_templateCache.find(fileName);
if (templ==0)
if (templ==0) // first time template is referenced
{
QCString filePath = m_templateDirName+"/"+fileName;
QFile f(filePath);
if (f.open(IO_ReadOnly))
{
QFileInfo fi(filePath);
int size=fi.size();
QCString data(size+1);
if (f.readBlock(data.rawData(),size)==size)
{
templ = new TemplateImpl(m_engine,filePath,data,m_extension);
m_templateCache.insert(fileName,templ);
return templ;
}
}
// fallback to default built-in template
const QCString data = ResourceMgr::instance().getAsString(fileName);
if (!data.isEmpty())
{
@@ -5101,12 +5116,18 @@ class TemplateEngine::Private
return m_extension;
}
void setTemplateDir(const char *dirName)
{
m_templateDirName = dirName;
}
private:
QDict<Template> m_templateCache;
//mutable int m_indent;
TemplateEngine *m_engine;
QList<IncludeEntry> m_includeStack;
QCString m_extension;
QCString m_templateDirName;
};
TemplateEngine::TemplateEngine()
@@ -5164,5 +5185,9 @@ QCString TemplateEngine::outputExtension() const
return p->outputExtension();
}
void TemplateEngine::setTemplateDir(const char *dirName)
{
p->setTemplateDir(dirName);
}
@@ -590,6 +590,9 @@ class TemplateEngine
/** Prints the current template file include stack */
void printIncludeContext(const char *fileName,int line) const;
/** Sets the search directory where to look for template files */
void setTemplateDir(const char *dirName);
private:
friend class TemplateNodeBlock;
friend class TemplateNodeCreate;

0 comments on commit d38d33c

Please sign in to comment.