# HG changeset patch # User Jari-Matti M?kel? # Date 1192579966 -10800 # Node ID 0bda71dc9c4f4294bab3890109e220c6f8ed8bef # Parent 87c36c5ed434c707f57d51a597dc7cac62f4b998 More document template and source listing code. diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/docgen.d --- a/trunk/src/docgen/docgen.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/docgen.d Wed Oct 17 03:12:46 2007 +0300 @@ -5,10 +5,14 @@ module docgen.docgen; import docgen.modulegraph.writer; +import docgen.sourcelisting.writer; +import docgen.templates.writer; +import docgen.graphutils.writer; struct DocGeneratorOptions { - GraphWriterOptions graph; - ListingsOptions listings; + GraphOptions graph; + ListingOptions listings; + TemplateOptions templates; CommentFormat commentFormat; } diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/graphutils/dotwriter.d --- a/trunk/src/docgen/graphutils/dotwriter.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.dotwriter; import docgen.graphutils.writer; -import tango.io.protocol.Writer : Writer; import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/graphutils/modulenamewriter.d --- a/trunk/src/docgen/graphutils/modulenamewriter.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.modulenamewriter; import docgen.graphutils.writer; -import tango.io.protocol.Writer : Writer; import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; @@ -21,7 +20,7 @@ } void generateGraph(Vertex[] vertices, Edge[] edges) { - auto output = new Writer(outputs[0]); + auto output = new Print!(char)(new Layout!(char), outputs[0]); void doList(Vertex[] v, uint level, char[] indent = "") { if (!level) return; diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/graphutils/modulepathwriter.d --- a/trunk/src/docgen/graphutils/modulepathwriter.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.modulepathwriter; import docgen.graphutils.writer; -import tango.io.protocol.Writer : Writer; import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; @@ -20,7 +19,7 @@ } void generateGraph(Vertex[] vertices, Edge[] edges) { - auto output = new Writer(outputs[0]); + auto output = new Print!(char)(new Layout!(char), outputs[0]); void doPaths(Vertex[] v, uint level, char[] indent = "") { if (!level) return; diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/graphutils/writers.d --- a/trunk/src/docgen/graphutils/writers.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/graphutils/writers.d Wed Oct 17 03:12:46 2007 +0300 @@ -22,6 +22,8 @@ return &((new ModuleNameWriter(this, outputs)).generateGraph); case GraphFormat.ModulePaths: return &((new ModulePathWriter(this, outputs)).generateGraph); + default: + throw new Exception("Graph writer type does not exist!"); } } } \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/misc/misc.d --- a/trunk/src/docgen/misc/misc.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/misc/misc.d Wed Oct 17 03:12:46 2007 +0300 @@ -4,6 +4,8 @@ */ module docgen.misc.misc; +char[] docgen_version = "Dil document generator 0.1"; + enum DocFormat { LaTeX, XML, diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/modulegraph/writer.d --- a/trunk/src/docgen/modulegraph/writer.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/modulegraph/writer.d Wed Oct 17 03:12:46 2007 +0300 @@ -29,11 +29,12 @@ Edge[] edges; Vertex[] vertices; - + /* loadModules(null, null, null, gwf.options.IncludeUnlocatableModules, vertices, edges); writer(vertices, edges); + */ } } diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/htmlwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,26 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.sourcelisting.htmlwriter; + +public import docgen.sourcelisting.writer; +import dil.Parser; +import tango.io.protocol.Writer : Writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + + +/** + * TODO + */ +class HTMLWriter : AbstractListingWriter { + this(ListingWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 2, "Wrong number of outputs"); + } + + void generateListing(Parser parser) { /* TODO */ } + void generateListing(InputStream input) { /* TODO */ } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/latexwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,42 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.sourcelisting.latexwriter; + +public import docgen.sourcelisting.writer; +import dil.Parser; +import tango.io.protocol.Writer : Writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Buffer : Buffer; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * Adds a code listing section for the given file. + */ +class LaTeXWriter : AbstractListingWriter { + this(ListingWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 2, "Wrong number of outputs"); + } + + void generateListing(Parser parser) { + auto output2 = new Print!(char)(new Layout!(char), outputs[0]); + auto output = new Print!(char)(new Layout!(char), outputs[1]); + /* TODO */ + } + + void generateListing(InputStream input) { + auto output2 = new Print!(char)(new Layout!(char), outputs[0]); + + if (cast(FileConduit)outputs[1]) { + char[] fn = (cast(FileConduit)outputs[1]).toUtf8(); + output2.format("\\lstinputlisting[language=d]{{{0}}", fn); + } + + auto buf = new Buffer(256); + buf.output = outputs[1]; + buf.copy(input); + } +} diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/plaintextwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,25 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.sourcelisting.plaintextwriter; + +public import docgen.sourcelisting.writer; +import dil.Parser; +import tango.io.protocol.Writer : Writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * TODO + */ +class PlainTextWriter : AbstractListingWriter { + this(ListingWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 2, "Wrong number of outputs"); + } + + void generateListing(Parser parser) { /* TODO */ } + void generateListing(InputStream input) { /* TODO */ } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/writer.d --- a/trunk/src/docgen/sourcelisting/writer.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 03:12:46 2007 +0300 @@ -10,6 +10,7 @@ struct ListingOptions { DocFormat docFormat; + bool enableListings; } interface ListingWriter { diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/writers.d --- a/trunk/src/docgen/sourcelisting/writers.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/sourcelisting/writers.d Wed Oct 17 03:12:46 2007 +0300 @@ -5,7 +5,10 @@ module docgen.sourcelisting.writers; public import docgen.sourcelisting.writer; -import dil.Parser; +import docgen.sourcelisting.latexwriter; +import docgen.sourcelisting.htmlwriter; +import docgen.sourcelisting.xmlwriter; +import docgen.sourcelisting.plaintextwriter; class DefaultListingWriterFactory : AbstractListingWriterFactory { this(ListingOptions options) { @@ -22,62 +25,8 @@ return new HTMLWriter(this, outputs); case DocFormat.PlainText: return new PlainTextWriter(this, outputs); + default: + throw new Exception("Listing writer type does not exist!"); } } -} - - -/** - * TODO - */ -class LaTeXWriter : AbstractListingWriter { - this(ListingWriterFactory factory, OutputStream[] outputs) { - super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); - } - - void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } -} - - -/** - * TODO - */ -class XMLWriter : AbstractListingWriter { - this(ListingWriterFactory factory, OutputStream[] outputs) { - super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); - } - - void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } -} - - -/** - * TODO: add support for html/xml/latex? - */ -class HTMLWriter : AbstractListingWriter { - this(ListingWriterFactory factory, OutputStream[] outputs) { - super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); - } - - void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } -} - - -/** - * TODO - */ -class PlainTextWriter : AbstractListingWriter { - this(ListingWriterFactory factory, OutputStream[] outputs) { - super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); - } - - void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } } \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/sourcelisting/xmlwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,25 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.sourcelisting.xmlwriter; + +public import docgen.sourcelisting.writer; +import dil.Parser; +import tango.io.protocol.Writer : Writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * TODO + */ +class XMLWriter : AbstractListingWriter { + this(ListingWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 2, "Wrong number of outputs"); + } + + void generateListing(Parser parser) { /* TODO */ } + void generateListing(InputStream input) { /* TODO */ } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/htmlwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/htmlwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,50 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.htmlwriter; + +import docgen.templates.writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * Writes a HTML document skeleton. + */ +class HTMLWriter : AbstractTemplateWriter { + this(TemplateWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 1, "Wrong number of outputs"); + } + + void generateTemplate() { + auto output = new Print!(char)(new Layout!(char), outputs[0]); + + output(` + + + + ` ~ factory.options.title ~ ` Reference Manual + + + + + + +

` ~ factory.options.title ~ ` Reference Manual

+

` ~ factory.options.versionString ~ `

+

Generated by ` ~ docgen_version ~ `

+

` ~ timeNow() ~ `

+
+

Table of Contents

+
+

Module documentation

+
+

File listings

+
+

Dependency diagram

+ + `); + } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/latexwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,95 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.latexwriter; + +import docgen.templates.writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * Writes a LaTeX document skeleton. + */ +class LaTeXWriter : AbstractTemplateWriter { + this(TemplateWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 1, "Wrong number of outputs"); + } + + void generateTemplate() { + auto output = new Print!(char)(new Layout!(char), outputs[0]); + + output(` + \documentclass[` ~ factory.options.paperSize ~ `]{book} + \usepackage{a4wide} + \usepackage{makeidx} + \usepackage{fancyhdr} + \usepackage{graphicx} + \usepackage{multicol} + \usepackage{float} + \usepackage{textcomp} + \usepackage{alltt} + \usepackage[utf8]{inputenc} + \usepackage{listings} + \lstnewenvironment{dcode} + { \lstset{language=d} } + {} + \lstset{` ~ + (factory.options.literateStyle ? ` + literate= + {<=}{{$\leq$}}1 + {>=}{{$\geq$}}1 + {!=}{{$\neq$}}1 + {...}{{$\dots$}}1 + {~}{{$\sim$}}1,` : ``) ~ ` + stringstyle=\ttfamily, + inputencoding=utf8, + extendedchars=false, + columns=fixed, + basicstyle=\small + } + \makeindex + \setcounter{tocdepth}{1} + \newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}} + \def\thechapter{\Roman{chapter}} + % \renewcommand{\footrulewidth}{0.4pt} + + \begin{document} + + \begin{titlepage} + \vspace*{7cm} + \begin{center} + {\Large ` ~ factory.options.title ~ ` Reference Manual\\[1ex]\large ` ~ + factory.options.versionString ~ ` }\\ + \vspace*{1cm} + {\large Generated by ` ~ docgen_version ~ `}\\ + \vspace*{0.5cm} + {\small ` ~ timeNow() ~ `}\\ + \end{center} + \end{titlepage} + + \clearemptydoublepage + + \tableofcontents + \thispagestyle{empty} + + \clearemptydoublepage + + \setcounter{page}{1} + \chapter{Module documentation} + \input{modules} + + \chapter{File listings} + \input{files} + + \chapter{Dependency diagram} + \input{dependencies} + + \printindex + + \end{document} + `); + } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/plaintextwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/plaintextwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,46 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.plaintextwriter; + +import docgen.templates.writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + + +/** + * Writes a plain text document skeleton. + */ +class PlainTextWriter : AbstractTemplateWriter { + this(TemplateWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 1, "Wrong number of outputs"); + } + + void generateTemplate() { + auto output = new Print!(char)(new Layout!(char), outputs[0]); + + char[] line, line2; + line.length = line2.length = 80; + line[] = "="; + line2[] = "-"; + + char[] h(char[] s) { + return s ~ \n ~ line[0..s.length] ~ \n; + } + + output( + h(factory.options.title ~ " Reference Manual") ~ \n ~ + factory.options.versionString ~ \n ~ + "Generated by " ~ docgen_version ~ \n ~ + timeNow() ~ \n \n \n ~ + line2 ~ \n \n \n ~ + h("Table of Contents") ~ \n \n ~ + h("Module documentation") ~ \n \n ~ + h("File listings") ~ \n \n ~ + h("Dependency diagram") ~ \n \n + ); + } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/writer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/writer.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,58 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.writer; + +public import docgen.misc.misc; +import tango.io.model.IConduit : OutputStream, InputStream; +import tango.util.time.Date; +import tango.util.time.Clock; +import tango.text.convert.Sprint; + +struct TemplateOptions { + DocFormat docFormat; + char[] title = "Test project"; + char[] versionString = "1.0"; + char[] copyright; + char[] paperSize = "a4paper"; + bool literateStyle = true; +} + +interface TemplateWriter { + void generateTemplate(); +} + +abstract class AbstractTemplateWriter : TemplateWriter { + protected TemplateWriterFactory factory; + protected OutputStream[] outputs; + + this(TemplateWriterFactory factory, OutputStream[] outputs) { + this.factory = factory; + this.outputs = outputs; + } + + protected static 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).dup; + } +} + +interface TemplateWriterFactory { + TemplateOptions *options(); + TemplateWriter createTemplateWriter(OutputStream[] outputs); +} + +abstract class AbstractTemplateWriterFactory : TemplateWriterFactory { + protected TemplateOptions m_options; + + public TemplateOptions *options() { + return &m_options; + } +} + diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/writers.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/writers.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,32 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.writers; + +public import docgen.templates.writer; +import docgen.templates.htmlwriter; +import docgen.templates.xmlwriter; +import docgen.templates.plaintextwriter; +import docgen.templates.latexwriter; + +class DefaultTemplateWriterFactory : AbstractTemplateWriterFactory { + this(TemplateOptions options) { + m_options = options; + } + + TemplateWriter createTemplateWriter(OutputStream[] outputs) { + switch (m_options.docFormat) { + case DocFormat.LaTeX: + return new LaTeXWriter(this, outputs); + case DocFormat.XML: + return new XMLWriter(this, outputs); + case DocFormat.HTML: + return new HTMLWriter(this, outputs); + case DocFormat.PlainText: + return new PlainTextWriter(this, outputs); + default: + throw new Exception("Template writer type does not exist!"); + } + } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/templates/xmlwriter.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/xmlwriter.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,22 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.templates.xmlwriter; + +import docgen.templates.writer; +import tango.io.FileConduit : FileConduit; +import tango.io.Print: Print; +import tango.text.convert.Layout : Layout; + +/** + * TODO + */ +class XMLWriter : AbstractTemplateWriter { + this(TemplateWriterFactory factory, OutputStream[] outputs) { + super(factory, outputs); + assert(outputs.length == 1, "Wrong number of outputs"); + } + + void generateTemplate() { /* TODO */ } +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/tests/doctemplate.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/tests/doctemplate.d Wed Oct 17 03:12:46 2007 +0300 @@ -0,0 +1,27 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.tests.doctemplate; + +import docgen.templates.writers; +import tango.io.Stdout; +import tango.io.FileConduit; +import tango.io.protocol.Writer : Writer; + + +// doc template +//@unittest +void doctemplate1() { + TemplateOptions test; + test.docFormat = DocFormat.LaTeX; + auto fname = "doctemplate.tex"; + + auto gwf = new DefaultTemplateWriterFactory(test); + auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); + auto writer = gwf.createTemplateWriter( [ file ] ); + + writer.generateTemplate(); + + file.close(); +} \ No newline at end of file diff -r 87c36c5ed434 -r 0bda71dc9c4f trunk/src/docgen/testsuite.d --- a/trunk/src/docgen/testsuite.d Tue Oct 16 22:20:37 2007 +0200 +++ b/trunk/src/docgen/testsuite.d Wed Oct 17 03:12:46 2007 +0300 @@ -6,6 +6,7 @@ import docgen.tests.graphs; import docgen.tests.parse; +import docgen.tests.doctemplate; import tango.io.Stdout; /** @@ -21,5 +22,7 @@ graph4(); parse1(); parse2(); + doctemplate1(); + Stdout("done.\n"); }