Mercurial > projects > dil
changeset 446:49f3afd6a0e8
Refactored writers.
line wrap: on
line diff
--- a/trunk/src/docgen/docgen.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/docgen.d Wed Oct 17 18:41:46 2007 +0300 @@ -8,19 +8,20 @@ import docgen.sourcelisting.writer; import docgen.templates.writer; import docgen.graphutils.writer; +import docgen.misc.misc; -struct DocGeneratorOptions { - GraphOptions graph; - ListingOptions listings; - TemplateOptions templates; - CommentFormat commentFormat; -} /** * Main routine for doc generation. */ -class DocGenerator { - public static void generate() { +class DefaultDocGenerator : DocGenerator { + DocGeneratorOptions m_options; + + public void generate() { } + + public DocGeneratorOptions *options() { + return &m_options; + } } \ No newline at end of file
--- a/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,7 +9,6 @@ import tango.io.Print: Print; import tango.text.convert.Layout : Layout; - /** * Creates a graph rule file for the dot utility. * @@ -26,12 +25,12 @@ auto output = new Print!(char)(new Layout!(char), outputs[1]); Vertex[][char[]] verticesByPckgName; - if (factory.options.GroupByFullPackageName) + if (factory.options.graph.GroupByFullPackageName) foreach (module_; vertices) verticesByPckgName[module_.name] ~= module_; // FIXME: is it name or loc? - if (factory.options.HighlightCyclicVertices || - factory.options.HighlightCyclicEdges) + if (factory.options.graph.HighlightCyclicVertices || + factory.options.graph.HighlightCyclicEdges) findCycles(vertices, edges); if (cast(FileConduit)outputs[1]) { @@ -39,7 +38,7 @@ char[] fn = (cast(FileConduit)outputs[1]).toUtf8(); // .dot -> .svg/.png/.gif/... - fn = fn[0..$-3] ~ imageFormatExts[factory.options.imageFormat]; + fn = fn[0..$-3] ~ imageFormatExts[factory.options.graph.imageFormat]; switch(factory.options.docFormat) { case DocFormat.LaTeX: @@ -58,7 +57,7 @@ output("Digraph ModuleDependencies {\n"); - if (factory.options.HighlightCyclicVertices) + if (factory.options.graph.HighlightCyclicVertices) foreach (module_; vertices) output.format( ` n{0} [label="{1}"{2}];`\n, @@ -78,7 +77,7 @@ (edge.isCyclic ? "[color=red]" : "") ); - if (factory.options.GroupByFullPackageName) + if (factory.options.graph.GroupByFullPackageName) foreach (packageName, vertices; verticesByPckgName) { output.format( ` subgraph "cluster_{0}" {{`\n` label="{0}";color=blue;`\n` `,
--- a/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,7 +9,6 @@ import tango.io.Print: Print; import tango.text.convert.Layout : Layout; - /** * TODO: add support for html/xml/latex? */ @@ -32,6 +31,6 @@ } } - doList(vertices, factory.options.depth); + doList(vertices, factory.options.graph.depth); } } \ No newline at end of file
--- a/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -31,6 +31,6 @@ } } - doPaths(vertices, factory.options.depth); + doPaths(vertices, factory.options.graph.depth); } } \ No newline at end of file
--- a/trunk/src/docgen/graphutils/writer.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/graphutils/writer.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,32 +9,6 @@ import tango.io.model.IConduit : OutputStream; debug import tango.io.Stdout; -enum ImageFormat { - PNG, - SVG, - GIF -} - -const imageFormatExts = [ "png", "svg", "gif" ]; - -enum GraphFormat { - Dot, - ModuleNames, - ModulePaths -} - -struct GraphOptions { - GraphFormat graphFormat; - ImageFormat imageFormat; - DocFormat docFormat; - uint depth; - bool IncludeUnlocatableModules; - bool HighlightCyclicEdges; - bool HighlightCyclicVertices; - bool GroupByPackageNames; - bool GroupByFullPackageName; -} - interface GraphWriter { void generateGraph(Vertex[], Edge[]); } @@ -162,15 +136,6 @@ +/ } -interface GraphWriterFactory { - GraphOptions *options(); +interface GraphWriterFactory : WriterFactory { GraphWriterDg createGraphWriter(OutputStream[] outputs); -} - -abstract class AbstractGraphWriterFactory : GraphWriterFactory { - protected GraphOptions m_options; - - public GraphOptions *options() { - return &m_options; - } } \ No newline at end of file
--- a/trunk/src/docgen/graphutils/writers.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/graphutils/writers.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,13 +9,13 @@ import docgen.graphutils.modulepathwriter; import docgen.graphutils.modulenamewriter; -class DefaultGraphWriterFactory : AbstractGraphWriterFactory { - this(GraphOptions options) { - m_options = options; +class DefaultGraphWriterFactory : AbstractWriterFactory, GraphWriterFactory { + this(DocGenerator generator) { + super(generator); } GraphWriterDg createGraphWriter(OutputStream[] outputs) { - switch (m_options.graphFormat) { + switch (options.graph.graphFormat) { case GraphFormat.Dot: return &((new DotWriter(this, outputs)).generateGraph); case GraphFormat.ModuleNames:
--- a/trunk/src/docgen/misc/misc.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/misc/misc.d Wed Oct 17 18:41:46 2007 +0300 @@ -16,4 +16,71 @@ enum CommentFormat { Ddoc, Doxygen +} + +enum ImageFormat { + PNG, + SVG, + GIF +} + +const imageFormatExts = [ "png", "svg", "gif" ]; + +enum GraphFormat { + Dot, + ModuleNames, + ModulePaths +} + +struct GraphOptions { + GraphFormat graphFormat; + ImageFormat imageFormat; + uint depth; + bool IncludeUnlocatableModules; + bool HighlightCyclicEdges; + bool HighlightCyclicVertices; + bool GroupByPackageNames; + bool GroupByFullPackageName; +} + +struct ListingOptions { + bool literateStyle = true; + bool enableListings; +} + +struct TemplateOptions { + char[] title = "Test project"; + char[] versionString = "1.0"; + char[] copyright; + char[] paperSize = "a4paper"; +} + +struct DocGeneratorOptions { + + GraphOptions graph; + ListingOptions listings; + TemplateOptions templates; + DocFormat docFormat; + CommentFormat commentFormat; +} + +interface DocGenerator { + DocGeneratorOptions *options(); + void generate(); +} + +interface WriterFactory { + DocGeneratorOptions *options(); +} + +abstract class AbstractWriterFactory : WriterFactory { + protected DocGenerator generator; + + public DocGeneratorOptions *options() { + return generator.options; + } + + this(DocGenerator generator) { + this.generator = generator; + } } \ No newline at end of file
--- a/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 18:41:46 2007 +0300 @@ -8,11 +8,6 @@ import dil.Parser; import tango.io.model.IConduit : OutputStream, InputStream; -struct ListingOptions { - DocFormat docFormat; - bool enableListings; -} - interface ListingWriter { void generateListing(Parser parser); void generateListing(InputStream input); @@ -28,15 +23,6 @@ } } -interface ListingWriterFactory { - ListingOptions *options(); +interface ListingWriterFactory : WriterFactory { ListingWriter createListingWriter(OutputStream[] outputs); -} - -abstract class AbstractListingWriterFactory : ListingWriterFactory { - protected ListingOptions m_options; - - public ListingOptions *options() { - return &m_options; - } } \ No newline at end of file
--- a/trunk/src/docgen/sourcelisting/writers.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writers.d Wed Oct 17 18:41:46 2007 +0300 @@ -10,9 +10,9 @@ import docgen.sourcelisting.xmlwriter; import docgen.sourcelisting.plaintextwriter; -class DefaultListingWriterFactory : AbstractListingWriterFactory { - this(ListingOptions options) { - m_options = options; +class DefaultListingWriterFactory : AbstractWriterFactory, ListingWriterFactory { + this(DocGenerator generator) { + super(generator); } ListingWriter createListingWriter(OutputStream[] outputs) {
--- a/trunk/src/docgen/templates/htmlwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/htmlwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,6 +9,8 @@ import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +// TODO: this is mostly broken now + /** * Writes a HTML document skeleton. */ @@ -25,15 +27,15 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> - <title>` ~ factory.options.title ~ ` Reference Manual</title> - <meta name="AUTHOR" content="` ~ factory.options.copyright ~ `" /> + <title>` ~ factory.options.templates.title ~ ` Reference Manual</title> + <meta name="AUTHOR" content="` ~ factory.options.templates.copyright ~ `" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="style.css" media="all" title="default" /> <link rel="stylesheet" href="print.css" media="print" /> </head> <body> - <h1>` ~ factory.options.title ~ ` Reference Manual</h1> - <h2>` ~ factory.options.versionString ~ `</h2> + <h1>` ~ factory.options.templates.title ~ ` Reference Manual</h1> + <h2>` ~ factory.options.templates.versionString ~ `</h2> <h2>Generated by ` ~ docgen_version ~ `</h2> <h3>` ~ timeNow() ~ `</h3> <hr />
--- a/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -22,7 +22,7 @@ auto output = new Print!(char)(new Layout!(char), outputs[0]); output(` - \documentclass[` ~ factory.options.paperSize ~ `]{book} + \documentclass[` ~ factory.options.templates.paperSize ~ `]{book} \usepackage{a4wide} \usepackage{makeidx} \usepackage{fancyhdr} @@ -37,7 +37,7 @@ { \lstset{language=d} } {} \lstset{` ~ - (factory.options.literateStyle ? ` + (factory.options.listings.literateStyle ? ` literate= {<=}{{$\leq$}}1 {>=}{{$\geq$}}1 @@ -61,8 +61,8 @@ \begin{titlepage} \vspace*{7cm} \begin{center} - {\Large ` ~ factory.options.title ~ ` Reference Manual\\[1ex]\large ` ~ - factory.options.versionString ~ ` }\\ + {\Large ` ~ factory.options.templates.title ~ ` Reference Manual\\[1ex]\large ` ~ + factory.options.templates.versionString ~ ` }\\ \vspace*{1cm} {\large Generated by ` ~ docgen_version ~ `}\\ \vspace*{0.5cm}
--- a/trunk/src/docgen/templates/plaintextwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/plaintextwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,6 +9,7 @@ import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +//TODO: this is mostly broken now /** * Writes a plain text document skeleton. @@ -32,8 +33,8 @@ } output( - h(factory.options.title ~ " Reference Manual") ~ \n ~ - factory.options.versionString ~ \n ~ + h(factory.options.templates.title ~ " Reference Manual") ~ \n ~ + factory.options.templates.versionString ~ \n ~ "Generated by " ~ docgen_version ~ \n ~ timeNow() ~ \n \n \n ~ line2 ~ \n \n \n ~
--- a/trunk/src/docgen/templates/writer.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/writer.d Wed Oct 17 18:41:46 2007 +0300 @@ -10,15 +10,6 @@ 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(); } @@ -43,16 +34,6 @@ } } -interface TemplateWriterFactory { - TemplateOptions *options(); +interface TemplateWriterFactory : WriterFactory { TemplateWriter createTemplateWriter(OutputStream[] outputs); -} - -abstract class AbstractTemplateWriterFactory : TemplateWriterFactory { - protected TemplateOptions m_options; - - public TemplateOptions *options() { - return &m_options; - } -} - +} \ No newline at end of file
--- a/trunk/src/docgen/templates/writers.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/writers.d Wed Oct 17 18:41:46 2007 +0300 @@ -10,13 +10,13 @@ import docgen.templates.plaintextwriter; import docgen.templates.latexwriter; -class DefaultTemplateWriterFactory : AbstractTemplateWriterFactory { - this(TemplateOptions options) { - m_options = options; +class DefaultTemplateWriterFactory : AbstractWriterFactory, TemplateWriterFactory { + this(DocGenerator generator) { + super(generator); } TemplateWriter createTemplateWriter(OutputStream[] outputs) { - switch (m_options.docFormat) { + switch (options.docFormat) { case DocFormat.LaTeX: return new LaTeXWriter(this, outputs); case DocFormat.XML:
--- a/trunk/src/docgen/templates/xmlwriter.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/templates/xmlwriter.d Wed Oct 17 18:41:46 2007 +0300 @@ -9,6 +9,8 @@ import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +//TODO: this is mostly broken now + /** * TODO */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/tests/common.d Wed Oct 17 18:41:46 2007 +0300 @@ -0,0 +1,19 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.tests.common; + +import docgen.misc.misc; + +class TestDocGenerator : DocGenerator { + DocGeneratorOptions m_options; + + public void generate() { + + } + + public DocGeneratorOptions *options() { + return &m_options; + } +} \ No newline at end of file
--- a/trunk/src/docgen/tests/doctemplate.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/tests/doctemplate.d Wed Oct 17 18:41:46 2007 +0300 @@ -4,20 +4,20 @@ */ module docgen.tests.doctemplate; +import docgen.tests.common; 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 gen = new TestDocGenerator; + gen.options.docFormat = DocFormat.LaTeX; auto fname = "doctemplate.tex"; - auto gwf = new DefaultTemplateWriterFactory(test); + auto gwf = new DefaultTemplateWriterFactory(gen); auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); auto writer = gwf.createTemplateWriter( [ file ] );
--- a/trunk/src/docgen/tests/graphs.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/tests/graphs.d Wed Oct 17 18:41:46 2007 +0300 @@ -4,19 +4,20 @@ */ module docgen.tests.graphs; +import docgen.tests.common; import docgen.graphutils.writers; import tango.io.Stdout; import tango.io.FileConduit; void saveDefaultGraph(Vertex[] vertices, Edge[] edges, char[] fname) { - GraphOptions test; - test.graphFormat = GraphFormat.Dot; - test.HighlightCyclicVertices = true; - //test.format = GraphOutputFormat.ModuleNames; - //test.format = GraphOutputFormat.ModulePaths; - test.depth = 5; + auto gen = new TestDocGenerator; + gen.options.graph.HighlightCyclicVertices = true; + gen.options.graph.graphFormat = GraphFormat.Dot; + //gen.options.graph.graphFormat = GraphFormat.ModuleNames; + //gen.options.graph.graphFormat = GraphFormat.ModulePaths; + gen.options.graph.depth = 5; - auto gwf = new DefaultGraphWriterFactory(test); + auto gwf = new DefaultGraphWriterFactory(gen); auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); auto file2 = new FileConduit("docgen/teststuff/" ~ fname ~ "-2", FileConduit.WriteCreate); auto writer = gwf.createGraphWriter( [ file2, file] );
--- a/trunk/src/docgen/tests/parse.d Wed Oct 17 03:12:46 2007 +0300 +++ b/trunk/src/docgen/tests/parse.d Wed Oct 17 18:41:46 2007 +0300 @@ -28,7 +28,7 @@ Module[] modules; Parser.loadModules( - [ "c" ], ["docgen/teststuff/"[].dup], + [ "c" ], [ "docgen/teststuff/" ], null, true, -1, (char[] fqn, char[] path, Module m) { file.format("{0} = {1}\n", fqn, path); @@ -52,8 +52,7 @@ Module[] modules; Parser.loadModules( - [ "docgen-tests" ], [".", "/home/jm/d/tango/"], -// [ "c" ], ["docgen/teststuff/"[].dup], + [ "docgen/testsuite" ], [".", "/home/jm/d/tango/"], null, true, -1, (char[] fqn, char[] path, Module m) { file.format("{0} = {1}\n", fqn, path);