comparison src/docgen/document/generator.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/docgen/document/generator.d@ec8dd7b8bf0c
children
comparison
equal deleted inserted replaced
805:a3fab8b74a7d 806:bcb74c9b895c
1 /**
2 * Author: Jari-Matti Mäkelä
3 * License: GPL3
4 */
5 module docgen.document.generator;
6
7 import docgen.misc.misc;
8 import docgen.misc.parser;
9 public import docgen.misc.options;
10 import docgen.page.writers;
11 import docgen.moduledoc.writers;
12 import docgen.graphutils.writers;
13 import docgen.sourcelisting.writers;
14 import docgen.config.configurator;
15 import tango.io.stream.FileStream;
16 import tango.io.FilePath;
17 import tango.io.FileScan;
18 debug import tango.io.Stdout;
19
20
21 alias void delegate(ref Module[], ref DepGraph) ParserDg;
22
23 abstract class DefaultDocGenerator : DocGenerator {
24 protected:
25
26 DocFormat docFormat;
27 auto makeFile = "make.sh";
28 char[] genDir;
29
30 DocGeneratorOptions m_options;
31 ParserDg m_parser;
32 PageWriter docWriter;
33
34 GraphWriterFactory graphFactory;
35 PageWriterFactory pageFactory;
36 ListingWriterFactory listingFactory;
37 ModuleDocWriterFactory moduleDocFactory;
38
39 Module[] modules;
40 DepGraph depGraph;
41
42 public:
43
44 this(DocGeneratorOptions options, ParserDg parser) {
45 m_options = options;
46 m_parser = parser;
47
48 createGraphWriterFactory();
49 createPageWriterFactory();
50 createListingWriterFactory();
51 createModuleDocWriterFactory();
52
53 // create output dir
54 (new FilePath(options.outputDir ~ "/" ~ genDir)).create();
55
56 // copy static files
57 copyStaticContent();
58 }
59
60 DocGeneratorOptions *options() {
61 return &m_options;
62 }
63
64 protected:
65
66 void createGraphWriterFactory() {
67 graphFactory = new DefaultGraphWriterFactory(this);
68 }
69
70 void createPageWriterFactory() {
71 pageFactory = new DefaultPageWriterFactory(this);
72 }
73
74 void createListingWriterFactory() {
75 listingFactory = new DefaultListingWriterFactory(this);
76 }
77
78 void createModuleDocWriterFactory() {
79 moduleDocFactory = new DefaultModuleDocWriterFactory(this);
80 }
81
82 char[] outPath(char[] file) {
83 return options.outputDir ~ "/" ~ genDir ~ "/" ~ file;
84 }
85
86 void copyStaticContent() {
87 auto scan = new FileScan();
88 scan(templateDir~options.templates.templateStyle~"/"~formatDirs[docFormat]~"/static/");
89
90 foreach(filePath; scan.files) {
91 (new FilePath(outPath(filePath.file))).copy(filePath.toString());
92 }
93
94 debug Stdout(scan.files.length)(" static files copied.\n");
95 }
96
97 FileOutput outputFile(char[] fname) {
98 return new FileOutput(outPath(fname));
99 }
100
101 void parseSources() {
102 depGraph = new DepGraph();
103 m_parser(modules, depGraph);
104 }
105
106 //---
107
108 void writeSimpleFile(char[] fname, void delegate() dg) {
109 auto docFile = outputFile(fname);
110
111 docWriter.setOutput([docFile]);
112 dg();
113
114 docFile.close();
115 }
116
117 /**
118 * Generates "makefile" for processing e.g. .dot files.
119 */
120 void generateMakeFile(char[][] args ...) {
121 writeSimpleFile(makeFile, { docWriter.generateCustomPage("makefile", args); } );
122 }
123
124 }
125
126 abstract class DefaultCachingDocGenerator : DefaultDocGenerator, CachingDocGenerator {
127 private:
128
129 GraphCache m_graphCache;
130
131 public:
132
133 this(DocGeneratorOptions options, ParserDg parser, GraphCache graphCache) {
134 super(options, parser);
135 m_graphCache = graphCache;
136 }
137
138 GraphCache graphCache() {
139 return m_graphCache;
140 }
141
142 protected:
143
144 void createGraphWriterFactory() {
145 graphFactory = new DefaultCachingGraphWriterFactory(this);
146 }
147 }