Merge branch 'master' of git@github.com:macournoyer/thin
[thin.git] / site / rdoc.rb
blobef853dbacb8261becdc00b6e15d0364761520d3f
1 # Based on Camping flipbook_rdoc by _why.
2 # http://code.whytheluckystiff.net/svn/camping/trunk/extras/flipbook_rdoc.rb
4 SITE_DIR = File.expand_path(File.dirname(__FILE__))
6 module Generators
7   class HTMLGenerator
8     def generate_html
9       @files_and_classes = {
10         'allfiles'     => gen_into_index(@files),
11         'allclasses'   => gen_into_index(@classes),
12         "initial_page" => main_url,
13         'realtitle'    => CGI.escapeHTML(@options.title),
14         'charset'      => @options.charset
15       }
17       # the individual descriptions for files and classes
18       gen_into(@files)
19       gen_into(@classes)
20       gen_main_index
21       
22       # this method is defined in the template file
23       write_extra_pages if defined? write_extra_pages
24     end
26     def gen_into(list)
27       hsh = @files_and_classes.dup
28       list.each do |item|
29         if item.document_self
30           op_file = item.path
31           hsh['root'] = item.path.split("/").map { ".." }[1..-1].join("/")
32           item.instance_variable_set("@values", hsh)
33           File.makedirs(File.dirname(op_file))
34           File.open(op_file, "w") { |file| item.write_on(file) }
35         end
36       end
37     end
39     def gen_into_index(list)
40       res = []
41       list.each do |item|
42         hsh = item.value_hash
43         hsh['href'] = item.path
44         hsh['name'] = item.index_name
45         res << hsh
46       end
47       res
48     end
50     def gen_main_index
51       template = TemplatePage.new(RDoc::Page::INDEX)
52       File.open("index.html", "w") do |f|
53         values = @files_and_classes.dup
54         if @options.inline_source
55           values['inline_source'] = true
56         end
57         template.write_html_on(f, values)
58       end
59       ['logo.gif'].each do |img|
60           ipath = File.join(SITE_DIR, 'images', img)
61           File.copy(ipath, img)
62       end
63     end
64   end
65 end
68 module RDoc
69 module Page
70 ######################################################################
72 # The following is used for the -1 option
75 FONTS = "verdana,arial,'Bitstream Vera Sans',helvetica,sans-serif"
77 STYLE = File.read(SITE_DIR + '/style.css')
79 CONTENTS_XML = %{
80 IF:description
81 %description%
82 ENDIF:description
84 IF:requires
85 <strong>Requires:</strong>
86 START:requires
87 IF:aref
88 <a href="%aref%">%name%</a> 
89 ENDIF:aref
90 IFNOT:aref
91 %name%
92 ENDIF:aref 
93 END:requires
94 </ul>
95 ENDIF:requires
97 IF:attributes
98 <h4>Attributes</h4>
99 <table>
100 START:attributes
101 <tr><td>%name%</td><td>%rw%</td><td>%a_desc%</td></tr>
102 END:attributes
103 </table>
104 ENDIF:attributes
106 IF:includes
107 <h4>Includes</h4>
108 <ul>
109 START:includes
110 IF:aref
111 <li><a href="%aref%">%name%</a></li>
112 ENDIF:aref
113 IFNOT:aref
114 <li>%name%</li>
115 ENDIF:aref 
116 END:includes
117 </ul>
118 ENDIF:includes
120 START:sections
121 IF:method_list
122 <h2 class="ruled">Methods</h2>
123 START:method_list
124 IF:methods
125 START:methods
126 <h4 class="ruled">
127 <span class="method-type" title="%type% %category% method">%type% %category%</span>
128 IF:callseq
129 <strong><a name="%aref%" href="#%aref%" title="Permalink to %callseq%">%callseq%</a></strong>
130 ENDIF:callseq
131 IFNOT:callseq
132 <strong><a name="%aref%" href="#%aref%" title="Permalink to %type% %category% method: %name%">%name%%params%</a></strong>
133 ENDIF:callseq
134 </h4>
136 IF:m_desc
137 %m_desc%
138 ENDIF:m_desc
140 IF:sourcecode
141 <div class="sourcecode">
142   <p class="source-link">[ <a href="javascript:toggleSource('%aref%_source')" id="l_%aref%_source">show source</a> ]</p>
143   <div id="%aref%_source" class="dyn-source">
144 <pre>
145 %sourcecode%
146 </pre>
147   </div>
148 </div>
149 ENDIF:sourcecode
150 END:methods
151 ENDIF:methods
152 END:method_list
153 ENDIF:method_list
154 END:sections
157 ############################################################################
160 BODY = %{
161 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
162 <html>
163 <head>
164   <title>
165 IF:title
166   %realtitle% &raquo; %title%
167 ENDIF:title
168 IFNOT:title
169   %realtitle%
170 ENDIF:title
171   </title>
172   <meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
173   <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" />
174   <script language="JavaScript" type="text/javascript">
175     // <![CDATA[
177     function toggleSource( id )
178     {
179     var elem
180     var link
182     if( document.getElementById )
183     {
184     elem = document.getElementById( id )
185     link = document.getElementById( "l_" + id )
186     }
187     else if ( document.all )
188     {
189     elem = eval( "document.all." + id )
190     link = eval( "document.all.l_" + id )
191     }
192     else
193     return false;
195     if( elem.style.display == "block" )
196     {
197     elem.style.display = "none"
198     link.innerHTML = "show source"
199     }
200     else
201     {
202     elem.style.display = "block"
203     link.innerHTML = "hide source"
204     }
205     }
207     function openCode( url )
208     {
209     window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
210     }
211     // ]]>
212   </script>
213 </head>
214   <body>
215     <ul id="menu">
216       <li><a href="/thin/">about</a></li>
217       <li><a href="/thin/download/">download</a></li>
218       <li><a href="/thin/usage/">usage</a></li>
219       <li><a href="/thin/doc/">doc</a></li>
220       <li><a href="http://groups.google.com/group/thin-ruby/">community</a></li>
221     </ul>
222     <div id="sidebar">
223       <h2>Files</h2>
224       <ul class="list">
225 START:allfiles
226         <li><a href="%root%/%href%" value="%title%">%name%</a></li>
227 END:allfiles
228       </ul>
229 IF:allclasses
230       
231       <h2>Classes</h2>
232       <ul class="list">
233 START:allclasses
234         <li><a href="%root%/%href%" title="%title%">%name%</a></li>
235 END:allclasses
236       </ul>
237 ENDIF:allclasses
238     </div>
239     <div id="container">
240       <div id="header">
241         <a href="/thin/" title="Home">
242           <img id="logo" src="%root%/logo.gif" />
243         </a>
244         <h2 id="tag_line">A fast and very simple Ruby web server</h2>
245       </div>
246     
247       <div id="content">
248         <h2>%title%</h2>
250   !INCLUDE!
252       </div>
253     </div>
254     <div id="footer">
255       <hr />
256       &copy; <a href="http://macournoyer.com">Marc-Andr&eacute; Cournoyer</a>
257     </div>
258   </body>
259 </html>
262 ###############################################################################
264 FILE_PAGE = <<_FILE_PAGE_
265 <div id="%full_path%" class="page_shade">
266 <div class="page">
267 <div class="header">
268   <div class="path">%full_path% / %dtm_modified%</div>
269 </div>
270 #{CONTENTS_XML}
271 </div>
272 </div>
273 _FILE_PAGE_
275 ###################################################################
277 CLASS_PAGE = %{
278 <div id="%full_name%" class="page_shade">
279 <div class="page">
280 IF:parent
281 <h3>%classmod% %full_name% &lt; HREF:par_url:parent:</h3>
282 ENDIF:parent
283 IFNOT:parent
284 <h3>%classmod% %full_name%</h3>
285 ENDIF:parent
287 IF:infiles
288 <span class="path">(in files
289 START:infiles
290 HREF:full_path_url:full_path:
291 END:infiles
292 )</span>
293 ENDIF:infiles
294 } + CONTENTS_XML + %{
295 </div>
296 </div>
299 ###################################################################
301 METHOD_LIST = %{
302 IF:includes
303 <div class="tablesubsubtitle">Included modules</div><br>
304 <div class="name-list">
305 START:includes
306   <span class="method-name">HREF:aref:name:</span>
307 END:includes
308 </div>
309 ENDIF:includes
311 IF:method_list
312 START:method_list
313 IF:methods
314 <table cellpadding=5 width="100%">
315 <tr><td class="tablesubtitle">%type% %category% methods</td></tr>
316 </table>
317 START:methods
318 <table width="100%" cellspacing = 0 cellpadding=5 border=0>
319 <tr><td class="methodtitle">
320 <a name="%aref%">
321 IF:callseq
322 <b>%callseq%</b>
323 ENDIF:callseq
324 IFNOT:callseq
325  <b>%name%</b>%params%
326 ENDIF:callseq
327 IF:codeurl
328 <a href="%codeurl%" target="source" class="srclink">src</a>
329 ENDIF:codeurl
330 </a></td></tr>
331 </table>
332 IF:m_desc
333 <div class="description">
334 %m_desc%
335 </div>
336 ENDIF:m_desc
337 IF:aka
338 <div class="aka">
339 This method is also aliased as
340 START:aka
341 <a href="%aref%">%name%</a>
342 END:aka
343 </div>
344 ENDIF:aka
345 IF:sourcecode
346 <div class="sourcecode">
347   <p class="source-link">[ <a href="javascript:toggleSource('%aref%_source')" id="l_%aref%_source">show source</a> ]</p>
348   <div id="%aref%_source" class="dyn-source">
349 <pre>
350 %sourcecode%
351 </pre>
352   </div>
353 </div>
354 ENDIF:sourcecode
355 END:methods
356 ENDIF:methods
357 END:method_list
358 ENDIF:method_list
362 ########################## Index ################################
364 FR_INDEX_BODY = %{
365 !INCLUDE!
368 FILE_INDEX = %{
369 <html>
370 <head>
371 <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
372 <style>
373 <!--
374   body {
375 background-color: #ddddff;
376      font-family: #{FONTS}; 
377        font-size: 11px; 
378       font-style: normal;
379      line-height: 14px; 
380            color: #000040;
381   }
382 div.banner {
383   background: #0000aa;
384   color:      white;
385   padding: 1;
386   margin: 0;
387   font-size: 90%;
388   font-weight: bold;
389   line-height: 1.1;
390   text-align: center;
391   width: 100%;
393   
395 </style>
396 <base target="docwin">
397 </head>
398 <body>
399 <div class="banner">%list_title%</div>
400 START:entries
401 <a href="%href%">%name%</a><br>
402 END:entries
403 </body></html>
406 CLASS_INDEX = FILE_INDEX
407 METHOD_INDEX = FILE_INDEX
409 INDEX = %{
410 <HTML>
411 <HEAD>
412 <META HTTP-EQUIV="refresh" content="0;URL=%initial_page%">
413 <TITLE>%realtitle%</TITLE>
414 </HEAD>
415 <BODY>
416 Click <a href="%initial_page%">here</a> to open the Thin docs.
417 </BODY>
418 </HTML>