home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2000 January / PCW0001.ISO / software / sw / outils / rebol031.exe / rebdoc.r < prev    next >
Encoding:
Rebol source code  |  1999-07-14  |  4.3 KB  |  147 lines

  1. REBOL [
  2.     Title:  "REBOL Document Generator"
  3.     Author: "Carl Sassenrath"
  4.     Date:   cvs-date "$Date: 1999/07/14 18:38:41 $"
  5.     File:   %rebdoc.r
  6.     Email:  carl@rebol.com  ;for problems or changes
  7.     Purpose: {
  8.         A more advanced script that generates an HTML formatted
  9.         document of REBOL defined words (from the information found
  10.         within the REBOL program itself).  The output file is
  11.         rebdoc.html.
  12.     }
  13.     Note: {
  14.         This script was written in this way so I could edit the HTML
  15.         in a visual HTML tool then simply run the script over it.
  16.         To make it easier to send to you, I've merged the HTML
  17.         template with the rest of the code.
  18.         
  19.         With minor modifications you can also use it to create docs
  20.         for your own scripts.
  21.     }
  22. ]
  23.  
  24. show-all: false
  25.  
  26. ;-- HTML Template for the Doc:
  27. html: load {
  28. <HTML>
  29. <HEAD><TITLE>title</title></HEAD>
  30. <BODY BGCOLOR="white">
  31. <FONT SIZE=+2 FACE="Arial, Helvetica"><CENTER><B>title</B></CENTER></FONT><BR>
  32. <FONT FACE="Arial, Helvetica"><CENTER><B>date</B><BR>count " words"</CENTER></FONT>
  33. <P>
  34. <FONT FACE="Arial, Helvetica">
  35. <!--head-->
  36.  
  37. <TABLE WIDTH="100%" BORDER="0" CELLSPACING="3">
  38.     <TR>
  39.         <TD WIDTH="20%" BGCOLOR="#C0C0C0"><P ALIGN="CENTER"><B>name</B></TD>
  40.         <TD WIDTH="80%" BGCOLOR="#E4DECB"><B><I>arg-list</FONT></I></B></TD>
  41.     </TR>
  42.     <TR>
  43.         <TD>nbsp</TD>
  44.         <TD><B>description<B></TD>
  45.     </TR>
  46. <!--word-->
  47.  
  48.     <TR>
  49.         <TD><P ALIGN="CENTER"><B>argument</B></TD>
  50.         <TD>description</TD>
  51.     </TR>
  52. <!--args-->
  53.  
  54.     <TR>
  55.         <TD BGCOLOR="#D0E4F2"><P ALIGN="CENTER"><B>argument</B></TD>
  56.         <TD>description</TD>
  57.     </TR>
  58. <!--refs-->
  59.  
  60. </TABLE>
  61. <!--next-->
  62.  
  63. </FONT>
  64. </BODY>
  65. </HTML>
  66. <!--end-->
  67. }
  68.  
  69. html: bind html 'html ; make it's words useful
  70.  
  71. sections: [ ; comment tags as placed in the html code
  72.     head-html   <!--head-->
  73.     word-html   <!--word-->
  74.     args-html   <!--args-->
  75.     refs-html   <!--refs-->
  76.     next-html   <!--next-->
  77.     end-html    <!--end-->
  78. ]
  79.  
  80. ;-- Split off each html section:
  81. foreach [word marker] sections [
  82.     mark: find html marker
  83.     set word copy/part html mark
  84.     html: next mark
  85. ]
  86.  
  87. ;-- Generate the word list:
  88. word-list: make block! 200
  89. words: first system/words
  90. vals:  second system/words
  91. while [not tail? words] [
  92.     if any-function? first vals [
  93.         append word-list first words
  94.     ]
  95.     words: next words
  96.     vals: next vals
  97. ]
  98. if not show-all [clear next find word-list 'what]
  99. sort word-list
  100. ;if not show-all [remove/part word-list find word-list '?]
  101. bind word-list 'system
  102.  
  103. ;-- Generate the document:
  104. output: make string! 10000
  105. save-html: func [html][append output reduce html]
  106. get-next: func ['series][first back set series next get series]
  107. title: reform ["REBOL Dictionary for" system/version]
  108. count: length? word-list
  109. nbsp: " "  ; keeps the ";" out of the html!
  110. date: mold now
  111. save-html head-html
  112. description: make string! 100
  113. foreach word word-list [
  114.     name: word  ; to get global binding
  115.     args: first get name ; function's arg list
  116.     here: find args refinement! ; first refinement in args
  117.     if not here [here: length? args] ; whole list
  118.     arg-list: form copy/part args here
  119.     spec: third get name ; function's specification
  120.     insert clear description either string? pick spec 1 [get-next spec]
  121.         ["This is an undocumented function"]
  122.     save-html word-html
  123.     while [not empty? spec] [
  124.         arg: get-next spec ; each item in spec...
  125.         if any [arg = 'local number? arg] [break] ; bug: not /local
  126.         argument: mold :arg  ; ":" needed to get-lit
  127.         words: either block? pick spec 1 [get-next spec][none]
  128.         clear description
  129.         if string? pick spec 1 [insert description get-next spec]
  130.         either refinement? arg [save-html refs-html][
  131.             append description rejoin [" <i>(accepts: "
  132.                 any [words "any value"] ")</i>"]
  133.             save-html args-html
  134.         ]
  135.     ]
  136.     save-html next-html
  137.     save-html [<P> newline]
  138. ]
  139.  
  140. save-html end-html
  141. write %rebdoc.html output
  142.  
  143. print {
  144.     Rebdoc has completed compiling the online documentation.  View
  145.     rebdoc.html with your web browser or HTML viewer to read this
  146.     documentation file.
  147. }