Mercurial > projects > dil
annotate trunk/src/docgen/page/htmlwriter.d @ 717:cb8edb09108a
Updated docgen (mostly) to new tango.
Reflective options.
Updated translations.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Fri, 01 Feb 2008 15:05:56 +0200 |
parents | e48a011e687a |
children |
rev | line source |
---|---|
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
1 /** |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
2 * Author: Jari-Matti Mäkelä |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
3 * License: GPL3 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
4 */ |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
5 module docgen.page.htmlwriter; |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
6 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
7 import docgen.page.writer; |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
8 import docgen.misc.textutils; |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
9 import tango.io.FileConduit : FileConduit; |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
10 import tango.text.convert.Sprint; |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
11 import tango.io.FilePath; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
12 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
13 /** |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
14 * Writes a HTML document skeleton. |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
15 */ |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
16 class HTMLWriter : AbstractPageWriter!("html") { |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
17 private: |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
18 |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
19 char[] styleSheetFile; |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
20 |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
21 public: |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
22 |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
23 this(PageWriterFactory factory, OutputStream[] outputs) { |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
24 super(factory); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
25 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
26 |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
27 override void generateClassSection() { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
28 print.format(getTemplate("classes"), factory.options.templates.title); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
29 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
30 |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
31 override void generateModuleSection(Module[] modules) { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
32 print.format(getTemplate("modules"), factory.options.templates.title); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
33 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
34 |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
35 override void generateListingSection(Module[] modules) { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
36 print.format(getTemplate("listings"), factory.options.templates.title); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
37 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
38 |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
39 override void generateDepGraphSection() { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
40 print.format(getTemplate("dependencies"), factory.options.templates.title); |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
41 } |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
42 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
43 void generateFirstPage() { |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
44 print.format( |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
45 getTemplate("firstpage"), |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
46 factory.options.templates.title, |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
47 factory.options.templates.versionString, |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
48 factory.options.templates.copyright |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
49 ); |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
50 |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
51 footer(); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
52 } |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
53 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
54 /** |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
55 * A hack for figuring out the stylesheet file name. |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
56 */ |
470
e48a011e687a
Initial plain text output support.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
469
diff
changeset
|
57 override void generateCustomPage(char[] name, char[][] args ...) { |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
58 super.generateCustomPage(name, args); |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
59 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
60 if (name == "stylesheet") { |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
61 styleSheetFile = (new FilePath( |
717
cb8edb09108a
Updated docgen (mostly) to new tango.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
470
diff
changeset
|
62 (cast(Object)outputs[0].conduit).toString())).file(); |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
63 } |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
64 } |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
65 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
66 /** |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
67 * Overrides the default template fetcher in order to |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
68 * provide a consistent layout for all pages. |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
69 */ |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
70 override char[] getTemplate(char[] name) { |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
71 auto content = super.getTemplate(name); |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
72 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
73 foreach(pageName; [ |
469
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
74 "firstpage"[], "toc"[], "classes"[], "modules"[], "listing"[], |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
75 "listings"[], "dependencies"[], "lastpage"[] ]) { |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
76 if (name == pageName) { |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
77 auto sprint = new Sprint!(char)(5120); |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
78 char[] title = factory.options.templates.title ~ " "; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
79 switch(name) { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
80 case "firstpage": title ~= "Documentation"; break; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
81 case "toc": title ~= "TOC"; break; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
82 case "classes": title ~= "Class index"; break; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
83 case "modules": title ~= "Module index"; break; |
469
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
84 case "listing": title ~= "File contents"; break; |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
85 case "listings": title ~= "File index"; break; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
86 case "dependencies": title ~="Dependencies"; break; |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
87 } |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
88 return |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
89 sprint.format(super.getTemplate("pagetemplate"), styleSheetFile, title) ~ |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
90 content; |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
91 } |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
92 } |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
93 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
94 return content; |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
95 } |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
96 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
97 void addList(char[][] contents, bool ordered) { |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
98 foreach(item; contents) { |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
99 switch(item) { |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
100 case "(": print(ordered ? "<ol>" : "<ul>"); continue; |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
101 case ")": print(ordered ? "</ol>" : "</ul>"); continue; |
469
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
102 default: print("<li>")(item)("</li>"); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
103 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
104 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
105 } |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
106 |
469
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
107 override void addListing(char[] moduleName, char[] contents, bool inline) { |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
108 print.format(getTemplate("listing"), moduleName, contents); |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
109 |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
110 footer(); |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
111 } |
e562d455cbbe
Fixed latex regressions, added html file lists.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
468
diff
changeset
|
112 |
468
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
113 protected: |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
114 |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
115 /** |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
116 * Writes the page footer. |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
117 */ |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
118 void footer() { |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
119 print.format(getTemplate("pagetemplate2"), docgen_version); |
7f7b2232a9eb
Fixes for the html generation.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
120 } |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
121 } |