# HG changeset patch # User Jari-Matti M?kel? # Date 1193254298 -10800 # Node ID f658ec4a15ddf0e7e73fe01fbbcf53ec05e27b70 # Parent 3f44c38bf87008aa8e6164d301bd01cdf6c37d4c Simple docgen ui util, some fixes. diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/docgen.d --- a/trunk/src/docgen/docgen.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/docgen.d Wed Oct 24 22:31:38 2007 +0300 @@ -5,23 +5,195 @@ module docgen.docgen; import docgen.modulegraph.writer; -import docgen.sourcelisting.writer; -import docgen.templates.writer; -import docgen.graphutils.writer; +import docgen.sourcelisting.writers; +import docgen.document.writers; +import docgen.graphutils.writers; import docgen.misc.misc; +import docgen.misc.parser; +import dil.Module; +import tango.core.Array; +import tango.io.stream.FileStream; +import tango.text.Ascii; +import tango.text.Util : replace; + +abstract class DefaultDocGenerator : DocGenerator { + DocGeneratorOptions m_options; + DocumentWriter docWriter; + GraphWriterFactory graphFactory; + + Module[] modules; + Edge[] edges; + Vertex[char[]] vertices; + + this(DocGeneratorOptions options) { + m_options = options; + parseSources(); + graphFactory = new DefaultGraphWriterFactory(this); + } + + // TODO: constructor for situations where parsing has happened elsewhere + + char[] outPath(char[] file) { + return options.outputDir ~ "/" ~ file; + } + + void parseSources() { + int id = 1; + + Parser.loadModules( + options.parser.rootPaths, options.parser.importPaths, + null, true, -1, + (char[] fqn, char[] path, Module m) { + vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); + }, + (Module imported, Module importer) { + edges ~= vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); + }, + modules + ); + } + + void createDepGraph(char[] depGraphFile) { + auto imgFile = new FileOutput(outPath(depGraphFile)); + + auto writer = graphFactory.createGraphWriter( docWriter ); + + writer.generateGraph(vertices.values, edges, imgFile); + + imgFile.close(); + } + + public DocGeneratorOptions *options() { + return &m_options; + } +} /** - * Main routine for doc generation. + * Main routine for LaTeX doc generation. */ -class DefaultDocGenerator : DocGenerator { - DocGeneratorOptions m_options; - +class LaTeXDocGenerator : DefaultDocGenerator { + this(DocGeneratorOptions options) { + super(options); + } + + /** + * Generates document skeleton + */ + void generateDoc(char[] docFileName) { + auto ddf = new DefaultDocumentWriterFactory(this); + + auto docFile = new FileOutput(outPath(docFileName)); + docWriter = ddf.createDocumentWriter( [ docFile ] ); + + docWriter.generateFirstPage(); + docWriter.generateTOC(modules); + docWriter.generateModuleSection(); + docWriter.generateListingSection(); + docWriter.generateDepGraphSection(); + docWriter.generateIndexSection(); + docWriter.generateLastPage(); + + docFile.close(); + } + + /** + * Generates documentation for modules + */ + void generateModules() { + } + + /** + * Generates source file listings.listings + */ + void generateListings(char[] listingsFile) { + auto dlwf = new DefaultListingWriterFactory(this); + auto docFile = new FileOutput(outPath(listingsFile)); + docWriter.setOutput([docFile]); + auto writer = dlwf.createListingWriter(docWriter); + + modules.sort( + (Module a, Module b){ return icompare(a.moduleFQN, b.moduleFQN); } + ); + + foreach(mod; modules) { + auto dstFname = replace(mod.moduleFQN.dup, '.', '_') ~ ".d"; + + auto srcFile = new FileInput(mod.filePath); + auto dstFile = new FileOutput(outPath(dstFname)); + + writer.generateListing(srcFile, dstFile, mod.moduleFQN); + + srcFile.close(); + dstFile.close(); + } + + docFile.close(); + } + + /** + * Generates dependency graphs. + */ + void generateDependencies(char[] depGraphTexFile, char[] depGraphFile) { + auto docFile = new FileOutput(outPath(depGraphTexFile)); + docWriter.setOutput([docFile]); + + createDepGraph(depGraphFile); + + docFile.close(); + } + public void generate() { + auto docFileName = "document.tex"; + auto depGraphTexFile = "dependencies.tex"; + auto depGraphFile = "depgraph.dot"; + auto listingsFile = "files.tex"; + + generateDoc(docFileName); + + if (options.listings.enableListings) + generateListings(listingsFile); + + generateDependencies(depGraphTexFile, depGraphFile); } +} + +void main(char[][] args) { + DocGeneratorOptions options; + + options.graph.graphFormat = GraphFormat.Dot; + options.graph.imageFormat = ImageFormat.PS; + options.graph.depth = 0; + options.graph.nodeColor = "tomato"; + options.graph.cyclicNodeColor = "red"; + options.graph.clusterColor = "blue"; + options.graph.includeUnlocatableModules = true; + options.graph.highlightCyclicEdges = true; + options.graph.highlightCyclicVertices = true; + options.graph.groupByPackageNames = true; + options.graph.groupByFullPackageName = true; - public DocGeneratorOptions *options() { - return &m_options; - } -} \ No newline at end of file + options.listings.literateStyle = true; + options.listings.enableListings = true; + + options.templates.title = "Test project"; + options.templates.versionString = "1.0"; + options.templates.copyright = "(C) Me!"; + options.templates.paperSize = "a4paper"; + options.templates.shortFileNames = false; + options.templates.templateStyle = "default"; + + options.parser.importPaths = [ args[2] ]; + options.parser.rootPaths = [ args[1] ]; + options.parser.strRegexps = null; + + options.docFormat = DocFormat.LaTeX; + options.commentFormat = CommentFormat.Doxygen; + options.outputDir = args[3]; + + + auto generator = new LaTeXDocGenerator(options); + + generator.generate(); +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/document/htmlwriter.d --- a/trunk/src/docgen/document/htmlwriter.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/document/htmlwriter.d Wed Oct 24 22:31:38 2007 +0300 @@ -19,7 +19,39 @@ super(factory, outputs); } - void generateDocument() { + void generateTOC(Module[] modules) { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["toc"]); + } + + void generateModuleSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["modules"]); + } + + void generateListingSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["listings"]); + } + + void generateDepGraphSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["dependencies"]); + } + + void generateIndexSection() { } + + void generateLastPage() { } + + void generateFirstPage() { auto output = new Print!(char)(new Layout!(char), outputs[0]); output.format( @@ -30,4 +62,4 @@ docgen_version ); } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/document/latexwriter.d --- a/trunk/src/docgen/document/latexwriter.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/document/latexwriter.d Wed Oct 24 22:31:38 2007 +0300 @@ -17,7 +17,7 @@ super(factory, outputs); } - void generateDocument() { + void generateFirstPage() { auto print = new Print!(char)(new Layout!(char), outputs[0]); print.format( @@ -30,4 +30,4 @@ factory.options.listings.literateStyle ? "" : "%" ); } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/document/plaintextwriter.d --- a/trunk/src/docgen/document/plaintextwriter.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/document/plaintextwriter.d Wed Oct 24 22:31:38 2007 +0300 @@ -20,7 +20,39 @@ super(factory, outputs); } - void generateDocument() { + void generateTOC(Module[] modules) { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["toc"]); + } + + void generateModuleSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["modules"]); + } + + void generateListingSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["listings"]); + } + + void generateDepGraphSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["dependencies"]); + } + + void generateIndexSection() { } + + void generateLastPage() { } + + void generateFirstPage() { auto output = new Print!(char)(new Layout!(char), outputs[0]); output( @@ -35,4 +67,4 @@ plainTextHeading("Dependency diagram") ~ \n ); } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/document/writer.d --- a/trunk/src/docgen/document/writer.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/document/writer.d Wed Oct 24 22:31:38 2007 +0300 @@ -13,6 +13,7 @@ import tango.io.Stdout; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +public import dil.Module; char[] timeNow() { auto date = Clock.toDate; @@ -43,11 +44,29 @@ return content; } -const templateNames = [ "firstpage"[], "graphics"[], "listing"[] ]; -//const templateNames = [ "firstpage", "toc", "module", "depGraph", "graphics" ]; +const templateNames = [ + "firstpage"[], "toc"[], "modules"[], + "listings"[], "dependencies"[], "index"[], + "lastpage"[], + "graphics"[], "listing"[] +]; interface DocumentWriter { - void generateDocument(); + void setOutput(OutputStream[] outputs); + + void generateFirstPage(); + + void generateTOC(Module[] modules); + + void generateModuleSection(); + + void generateListingSection(); + + void generateDepGraphSection(); + + void generateIndexSection(); + + void generateLastPage(); /** * Writes a tag for the given image to the output stream @@ -75,7 +94,49 @@ templates[tpl] = loadTemplate(factory.options.templates.templateStyle, format, tpl); } } - + + void setOutput(OutputStream[] outputs) { + this.outputs = outputs; + } + + void generateTOC(Module[] modules) { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["toc"]); + } + + void generateModuleSection() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["modules"]); + } + + void generateListingSection() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["listings"]); + } + + void generateDepGraphSection() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["dependencies"]); + } + + void generateIndexSection() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["index"]); + } + + void generateLastPage() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["lastpage"]); + } + + // --- page components + void addGraphics(char[] imageFile) { auto print = new Print!(char)(new Layout!(char), outputs[0]); @@ -88,4 +149,4 @@ print.format(templates["listing"], moduleName, contents); } } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/document/xmlwriter.d --- a/trunk/src/docgen/document/xmlwriter.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/document/xmlwriter.d Wed Oct 24 22:31:38 2007 +0300 @@ -19,5 +19,37 @@ super(factory, outputs); } - void generateDocument() { /* TODO */ } -} \ No newline at end of file + void generateTOC(Module[] modules) { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["toc"]); + } + + void generateModuleSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["modules"]); + } + + void generateListingSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["listings"]); + } + + void generateDepGraphSection() { + // TODO + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print.format(templates["dependencies"]); + } + + void generateIndexSection() { } + + void generateLastPage() { } + + void generateFirstPage() { } +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/graphutils/dotwriter.d --- a/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 24 22:31:38 2007 +0300 @@ -22,12 +22,12 @@ auto image = new Print!(char)(new Layout!(char), imageFile); Vertex[][char[]] verticesByPckgName; - if (factory.options.graph.GroupByFullPackageName) + if (factory.options.graph.groupByFullPackageName) foreach (module_; vertices) verticesByPckgName[module_.name] ~= module_; // FIXME: is it name or loc? - if (factory.options.graph.HighlightCyclicVertices || - factory.options.graph.HighlightCyclicEdges) + if (factory.options.graph.highlightCyclicVertices || + factory.options.graph.highlightCyclicEdges) findCycles(vertices, edges); if (cast(FileConduit)imageFile.conduit) { @@ -42,7 +42,7 @@ image("Digraph ModuleDependencies {\n"); - if (factory.options.graph.HighlightCyclicVertices) + if (factory.options.graph.highlightCyclicVertices) foreach (module_; vertices) image.format( ` n{0} [label="{1}"{2}];`\n, @@ -62,7 +62,7 @@ (edge.isCyclic ? "[color=" ~ factory.options.graph.cyclicNodeColor ~ "]" : "") ); - if (factory.options.graph.GroupByFullPackageName) + if (factory.options.graph.groupByFullPackageName) foreach (packageName, vertices; verticesByPckgName) { image.format( ` subgraph "cluster_{0}" {{`\n` label="{0}";color=` @@ -78,4 +78,4 @@ image("}"); } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/misc/misc.d --- a/trunk/src/docgen/misc/misc.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/misc/misc.d Wed Oct 24 22:31:38 2007 +0300 @@ -50,12 +50,12 @@ uint depth; char[] nodeColor = "tomato"; char[] cyclicNodeColor = "red"; - char[] clusterColor = ""; - bool IncludeUnlocatableModules; - bool HighlightCyclicEdges; - bool HighlightCyclicVertices; - bool GroupByPackageNames; - bool GroupByFullPackageName; + char[] clusterColor = "blue"; + bool includeUnlocatableModules; + bool highlightCyclicEdges; + bool highlightCyclicVertices; + bool groupByPackageNames; + bool groupByFullPackageName; } struct ListingOptions { @@ -81,21 +81,25 @@ } struct ParserOptions { - /// location for the generated output - char[] outputDir; /// paths to search for imports char[][] importPaths; + /// paths to "root files" + char[][] rootPaths; /// regexps for excluding modules char[][] strRegexps; } struct DocGeneratorOptions { + /// location for the generated output + char[] outputDir; + + DocFormat docFormat; + CommentFormat commentFormat; + GraphOptions graph; ListingOptions listings; TemplateOptions templates; ParserOptions parser; - DocFormat docFormat; - CommentFormat commentFormat; } // --- @@ -139,4 +143,4 @@ } } } -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/modulegraph/writer.d --- a/trunk/src/docgen/modulegraph/writer.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/modulegraph/writer.d Wed Oct 24 22:31:38 2007 +0300 @@ -16,7 +16,7 @@ import common; alias FileConst.PathSeparatorChar dirSep; - +/+ class ModuleGraphGenerator { /** @@ -38,3 +38,4 @@ */ } } ++/ diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/html/firstpage.tpl --- a/trunk/src/docgen/templates/default/html/firstpage.tpl Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/templates/default/html/firstpage.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -12,11 +12,5 @@

{2}

Generated by {3}

{4}

-
-

Table of Contents

-
-

Module documentation

-
-

File listings

-
-

Dependency diagram

\ No newline at end of file + + diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/html/toc.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/html/toc.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,15 @@ + + + + {0} Reference Manual + + + + + + +

Table of Contents

+
+{0} + + diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/dependencies.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/dependencies.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,2 @@ +\chapter{{Dependency diagram} +\input{{dependencies} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/firstpage.tpl --- a/trunk/src/docgen/templates/default/latex/firstpage.tpl Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/templates/default/latex/firstpage.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -46,22 +46,3 @@ \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 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/index.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/index.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,1 @@ +\printindex diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/lastpage.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/lastpage.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,1 @@ +\end{{document} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/listings.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/listings.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,2 @@ +\chapter{{File listings} +\input{{files} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/modules.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/modules.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,2 @@ +\chapter{{Module documentation} +\input{{modules} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/templates/default/latex/toc.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/toc.tpl Wed Oct 24 22:31:38 2007 +0300 @@ -0,0 +1,6 @@ +\tableofcontents +\thispagestyle{{empty} + +\clearemptydoublepage + +\setcounter{{page}{{1} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/tests/doctemplate.d --- a/trunk/src/docgen/tests/doctemplate.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/tests/doctemplate.d Wed Oct 24 22:31:38 2007 +0300 @@ -21,7 +21,13 @@ auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); auto writer = gwf.createDocumentWriter( [ file ] ); - writer.generateDocument(); + writer.generateFirstPage(); + writer.generateTOC(null); + writer.generateModuleSection(); + writer.generateListingSection(); + writer.generateDepGraphSection(); + writer.generateIndexSection(); + writer.generateLastPage(); file.close(); -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/tests/graphs.d --- a/trunk/src/docgen/tests/graphs.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/tests/graphs.d Wed Oct 24 22:31:38 2007 +0300 @@ -14,7 +14,7 @@ void saveDefaultGraph(Vertex[] vertices, Edge[] edges, char[] fname) { auto gen = new TestDocGenerator; - gen.options.graph.HighlightCyclicVertices = true; + gen.options.graph.highlightCyclicVertices = true; gen.options.graph.imageFormat = ImageFormat.SVG; gen.options.graph.graphFormat = GraphFormat.Dot; //gen.options.graph.graphFormat = GraphFormat.ModuleNames; @@ -107,7 +107,7 @@ //@unittest void graph5() { auto gen = new TestDocGenerator; - gen.options.graph.HighlightCyclicVertices = true; + gen.options.graph.highlightCyclicVertices = true; gen.options.graph.graphFormat = GraphFormat.Dot; gen.options.graph.imageFormat = ImageFormat.SVG; gen.options.docFormat = DocFormat.LaTeX; @@ -142,4 +142,4 @@ file.close(); imgFile.close(); -} \ No newline at end of file +} diff -r 3f44c38bf870 -r f658ec4a15dd trunk/src/docgen/tests/listing.d --- a/trunk/src/docgen/tests/listing.d Wed Oct 24 17:25:52 2007 +0300 +++ b/trunk/src/docgen/tests/listing.d Wed Oct 24 22:31:38 2007 +0300 @@ -22,7 +22,7 @@ auto fname = "files.tex"; auto ddf = new DefaultDocumentWriterFactory(gen); - auto gwf = new DefaultListingWriterFactory(gen); + auto dlwf = new DefaultListingWriterFactory(gen); auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); @@ -41,7 +41,7 @@ auto srcFile = new FileConduit(mod.filePath); auto dstFile = new FileConduit("docgen/teststuff/_" ~ dstFname ~ ".d", FileConduit.WriteCreate); - auto writer = gwf.createListingWriter( ddf.createDocumentWriter( [ file ] ) ); + auto writer = dlwf.createListingWriter( ddf.createDocumentWriter( [ file ] ) ); writer.generateListing(srcFile, dstFile, mod.moduleFQN); @@ -50,4 +50,4 @@ } file.close(); -} \ No newline at end of file +}