Mercurial > projects > dil
diff trunk/src/docgen/page/writer.d @ 466:db7e27b5c180
Fixed parts of HTML output, some reorganizing.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Wed, 31 Oct 2007 15:17:20 +0200 |
parents | 33a4cb255fcc |
children | 32f4c3cb6a41 |
line wrap: on
line diff
--- a/trunk/src/docgen/page/writer.d Tue Oct 30 20:27:24 2007 +0100 +++ b/trunk/src/docgen/page/writer.d Wed Oct 31 15:17:20 2007 +0200 @@ -13,18 +13,12 @@ import tango.io.Stdout; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +import tango.io.FilePath; +import tango.io.FileScan; public import docgen.misc.parser; const templateDir = "docgen/templates/"; -// template file names -const templateNames = [ - "firstpage"[], "toc"[], "modules"[], - "listings"[], "dependencies"[], "index"[], - "lastpage"[], "langdef"[], "makefile"[], - "graphics"[], "listing"[] -]; - /** * Writes the logical subcomponents of a document, * e.g. sections, embedded graphics, lists @@ -46,6 +40,11 @@ void generateTOC(Module[] modules); /** + * Generates class documentation section. + */ + void generateClassSection(); + + /** * Generates module documentation section. */ void generateModuleSection(); @@ -71,15 +70,11 @@ void generateLastPage(); /** - * Generates a language definition file [LaTeX]. - * Could be used for DTD too, I suppose. + * Generates a page using a custom template file. + * + * Some examples: style sheet, DTD files, makefiles. */ - void generateLangDef(); - - /** - * Generates a makefile used for document post-processing. - */ - void generateMakeFile(); + void generateCustomPage(char[] name, char[][] args ...); // --- page components // @@ -103,95 +98,116 @@ PageWriter createPageWriter(OutputStream[] outputs, DocFormat outputFormat); } - -char[] timeNow() { - auto date = Clock.toDate; - auto sprint = new Sprint!(char); - return sprint.format("{0} {1} {2} {3}", - date.asDay(), - date.asMonth(), - date.day, - date.year); -} +template AbstractPageWriter(char[] format, int n = 0) { + abstract class AbstractPageWriter : AbstractWriter!(PageWriterFactory, n), PageWriter { + protected: -char[] loadTemplate(char[] style, char[] format, char[] templateName) { - char[] fn = templateDir~style~"/"~format~"/"~templateName~".tpl"; - - scope(failure) { - Stderr("Warning: error opening template "~fn~"."); - return null; - } + char[][char[]] m_templates; + Print!(char) print; - auto file = new FileInput(fn); - auto content = new char[file.length]; - auto bytesRead = file.read(content); - - assert(bytesRead == file.length, "Error reading template"); - - file.close(); - - return content; -} - -template AbstractPageWriter(int n, char[] format) { - abstract class AbstractPageWriter : AbstractWriter!(PageWriterFactory, n), PageWriter { - protected char[][char[]] templates; - protected Print!(char) print; + public: this(PageWriterFactory factory, OutputStream[] outputs) { - super(factory, outputs); + this(factory); setOutput(outputs); - - foreach(tpl; templateNames) { - templates[tpl] = loadTemplate(factory.options.templates.templateStyle, format, tpl); - } } void setOutput(OutputStream[] outputs) { this.outputs = outputs; + static if (n > 0) + assert(outputs.length == n, "Incorrect number of outputs"); print = new Print!(char)(new Layout!(char), outputs[0]); } void generateTOC(Module[] modules) { - print.format(templates["toc"]); + print.format(getTemplate("toc")); + } + + void generateClassSection() { + print.format(getTemplate("classes")); } void generateModuleSection() { - print.format(templates["modules"]); + print.format(getTemplate("modules")); } void generateListingSection() { - print.format(templates["listings"]); + print.format(getTemplate("listings")); } void generateDepGraphSection() { - print.format(templates["dependencies"]); + print.format(getTemplate("dependencies")); } void generateIndexSection() { - print.format(templates["index"]); + print.format(getTemplate("index")); } void generateLastPage() { - print.format(templates["lastpage"]); - } - - void generateLangDef() { - print(templates["langdef"]); + print.format(getTemplate("lastpage")); } - void generateMakeFile() { - print(templates["makefile"]); + void generateCustomPage(char[] name, char[][] args ...) { + print.format(getTemplate(name), args); } + //--- void addGraphics(char[] imageFile) { - print.format(templates["graphics"], imageFile); + print.format(getTemplate("graphics"), imageFile); } void addListing(char[] moduleName, char[] contents, bool inline) { - print.format(templates["listing"], moduleName, contents); + print.format(getTemplate("listing"), moduleName, contents); + } + + protected: + + this(PageWriterFactory factory) { + super(factory); + + auto scan = new FileScan(); + scan(templateDir~factory.options.templates.templateStyle~"/"~format~"/", ".tpl"); + + debug Stdout(scan.files.length)(" template files loaded.\n"); + + foreach(tpl; scan.files) { + m_templates[tpl.name] = loadTemplate(tpl.toUtf8()); + } + } + + char[] getTemplate(char[] name) { + auto tpl = name in m_templates; + assert(tpl, "Error: template ["~format~"/"~name~"] not found!"); + return *tpl; + } + + char[] loadTemplate(char[] fn) { + scope(failure) { + Stderr("Warning: error opening template "~fn~"."); + return null; + } + + auto file = new FileInput(fn); + auto content = new char[file.length]; + auto bytesRead = file.read(content); + + assert(bytesRead == file.length, "Error reading template"); + + file.close(); + + return content; + } + + char[] timeNow() { + auto date = Clock.toDate; + auto sprint = new Sprint!(char); + return sprint.format("{0} {1} {2} {3}", + date.asDay(), + date.asMonth(), + date.day, + date.year); } } }