1 //
2 // Copyright (c) 2007, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 5 May 07 Brian Frank Creation
7 //
8
9 using compiler
10 using fandoc
11
12 **
13 ** PodIndexGenerator generates the index file for a pod.
14 **
15 class PodIndexGenerator : HtmlGenerator
16 {
17
18 //////////////////////////////////////////////////////////////////////////
19 // Constructor
20 //////////////////////////////////////////////////////////////////////////
21
22 new make(DocCompiler compiler, Location loc, OutStream out)
23 : super(compiler, loc, out)
24 {
25 this.pod = compiler.pod
26 }
27
28 //////////////////////////////////////////////////////////////////////////
29 // Generator
30 //////////////////////////////////////////////////////////////////////////
31
32 override Str title()
33 {
34 return pod.name
35 }
36
override Void header()
38 {
39 out.print("<ul>\n")
40 out.print(" <li><a href='../index.html'>$docHome</a></li>\n")
41 out.print(" <li>$pod.name</li>\n")
42 out.print("</ul>\n")
43 }
44
45 override Void content()
46 {
47 out.print("<h1>$pod.name</h1>\n")
48 out.print("<table>\n")
49 sorter := |Type a, Type b -> Int| { return a.name <=> b.name }
50 filter := |Type t -> Bool| { return showType(t) }
51 types := pod.types.rw.sort(sorter).findAll(filter)
52 types.each |Type t, Int i|
53 {
54 // clip doc to first sentence
55 cls := i % 2 == 0 ? "even" : "odd"
56 doc := t.doc
57 if (doc != null) doc = firstSentance(doc)
58
59 out.print("<tr class='$cls'>\n")
60 out.print(" <td class='first'><a href='${compiler.uriMapper.map(t.qname, loc)}'>$t.name</a></td>\n")
61 out.print(" <td>$doc</td>\n")
62 out.print("</tr>\n")
63 }
64 out.print("</table>\n")
65 }
66
67 //////////////////////////////////////////////////////////////////////////
68 // Methods
69 //////////////////////////////////////////////////////////////////////////
70
71 static Str firstSentance(Str s)
72 {
73 buf := StrBuf.make
74 for (i:=0; i<s.size; i++)
75 {
76 ch := s[i]
77 peek := i<s.size-1 ? s[i+1] : -1
78
79 if (ch == '.' && (peek == ' ' || peek == '\n'))
80 {
81 buf.addChar(ch)
82 break;
83 }
84 else if (ch == '\n')
85 {
86 if (peek == -1 || peek == ' ' || peek == '\n')
87 break;
88 else
89 buf.addChar(' ')
90 }
91 else
92 {
93 switch (ch)
94 {
95 case '<': buf.add("<")
96 case '>': buf.add(">")
97 case '&': buf.add("&")
98 default: buf.addChar(ch)
99 }
100 }
101 }
102 return buf.toStr
103 }
104
105 //////////////////////////////////////////////////////////////////////////
106 // Fields
107 //////////////////////////////////////////////////////////////////////////
108
109 Pod pod
110
111 }