HTMLDocGenerator.st
changeset 1328 7bee978ad3bb
parent 1326 f439abbfb309
child 1331 204a6ea81433
equal deleted inserted replaced
1327:88045876c6ae 1328:7bee978ad3bb
    15 "{ Package: 'stx:libhtml' }"
    15 "{ Package: 'stx:libhtml' }"
    16 
    16 
    17 Object subclass:#HTMLDocGenerator
    17 Object subclass:#HTMLDocGenerator
    18 	instanceVariableNames:'outStream pathToTopOfDocumentation
    18 	instanceVariableNames:'outStream pathToTopOfDocumentation
    19 		pathToLanguageTopOfDocumentation httpRequestOrNil
    19 		pathToLanguageTopOfDocumentation httpRequestOrNil
    20 		generateBodyOnly'
    20 		generateBodyOnly backRef backCmd imagePath'
    21 	classVariableNames:''
    21 	classVariableNames:''
    22 	poolDictionaries:''
    22 	poolDictionaries:''
    23 	category:'System-Documentation'
    23 	category:'System-Documentation'
    24 !
    24 !
    25 
    25 
   762         back:backCmd 
   762         back:backCmd 
   763         backRef:backRef 
   763         backRef:backRef 
   764         imagePath:(self pathToTopOfDocumentation , '/icons')
   764         imagePath:(self pathToTopOfDocumentation , '/icons')
   765 !
   765 !
   766 
   766 
   767 htmlDocOf:aClass back:backCmd backRef:backRef imagePath:imagePath
   767 htmlDocOf:aClass back:backCmdArg backRef:backRefArg imagePath:imagePathArg
   768     "generate a nice HTML page from a class, with a back-reference
   768     "generate a nice HTML page from a class, with a back-reference
   769      to a command or document.
   769      to a command or document.
   770 
   770 
   771      Extract sections from the classes documentation method,
   771      Extract sections from the classes documentation method,
   772      where the following lines start a special subsection:
   772      where the following lines start a special subsection:
   787      these parts are displayed in courier and will be made executable.
   787      these parts are displayed in courier and will be made executable.
   788      everything else is plain documentation text.
   788      everything else is plain documentation text.
   789     "
   789     "
   790         
   790         
   791     |supers s indent m docu examples firstIndent firstNonEmpty
   791     |supers s indent m docu examples firstIndent firstNonEmpty
   792      collectionOfCategories collectionOfClassCategories subs refLines demoLines warnLines hintLines
   792      collectionOfCategories collectionOfClassCategories subs refLines demoLines warnLines hintLines authorLines first wasLoaded didLoadBin
   793      backHRef backLabel authorLines first wasLoaded didLoadBin
       
   794      privateClasses owner className metaClass shortName shortMetaName|
   793      privateClasses owner className metaClass shortName shortMetaName|
       
   794 
       
   795     backRef := backRefArg.
       
   796     backCmd := backCmdArg.
       
   797     imagePath := imagePathArg.
   795 
   798 
   796     aClass isNil ifTrue:[
   799     aClass isNil ifTrue:[
   797         ^ ''  "/ just in case ...
   800         ^ ''  "/ just in case ...
       
   801     ].
       
   802 
       
   803     outStream := s := '' writeStream.
       
   804     className := aClass name.
       
   805     shortName := aClass nameWithoutPrefix.
       
   806     metaClass := aClass class.
       
   807     shortMetaName := metaClass nameWithoutPrefix.
       
   808 
       
   809     self generateHTMLHeadWithTitle:('Class: ' , className).
       
   810     self generateBODYStart.
       
   811     self generateBackButton.
       
   812 
       
   813     aClass isNameSpace ifTrue:[
       
   814         s nextPutLine:'<h1>'.
       
   815         s nextPutAll:'NameSpace: ';
       
   816           nextPutLine:(shortName).
       
   817         s nextPutLine:'</h1>'.
       
   818         self generateBODYandHTMLEnd.
       
   819         ^ s contents.
   798     ].
   820     ].
   799 
   821 
   800     (wasLoaded := aClass isLoaded) ifFalse:[
   822     (wasLoaded := aClass isLoaded) ifFalse:[
   801         "/ load it - but not a binary
   823         "/ load it - but not a binary
   802         didLoadBin := Smalltalk loadBinaries.
   824         didLoadBin := Smalltalk loadBinaries.
   812         ].
   834         ].
   813     ].
   835     ].
   814 
   836 
   815     owner := aClass owningClass.
   837     owner := aClass owningClass.
   816     privateClasses := aClass privateClassesSorted.
   838     privateClasses := aClass privateClassesSorted.
   817     className := aClass name.
       
   818     shortName := aClass nameWithoutPrefix.
       
   819     metaClass := aClass class.
       
   820     shortMetaName := metaClass nameWithoutPrefix.
       
   821 
   839 
   822     "/
   840     "/
   823     "/ extract documentation or comment, if there is any
   841     "/ extract documentation or comment, if there is any
   824     "/
   842     "/
   825     m := metaClass compiledMethodAt:#documentation.
   843     m := metaClass compiledMethodAt:#documentation.
   971     (aClass == Autoload or:[aClass == Object]) ifTrue:[
   989     (aClass == Autoload or:[aClass == Object]) ifTrue:[
   972         subs := #()
   990         subs := #()
   973     ] ifFalse:[
   991     ] ifFalse:[
   974         subs := aClass subclasses 
   992         subs := aClass subclasses 
   975                     asOrderedCollection sort:[:a :b | a name < b name].
   993                     asOrderedCollection sort:[:a :b | a name < b name].
   976     ].
       
   977 
       
   978     outStream := s := '' writeStream.
       
   979 
       
   980     self generateHTMLHeadWithTitle:('Class: ' , className).
       
   981     self generateBODYStart.
       
   982 
       
   983     backRef isNil ifTrue:[
       
   984         backHRef := self pathToLanguageTopOfDocumentation , '/TOP.html'.
       
   985         backLabel := 'top'.
       
   986     ] ifFalse:[
       
   987         backHRef := backRef.
       
   988         backLabel := 'back'.
       
   989     ].
       
   990     backCmd notNil ifTrue:[
       
   991         self
       
   992             generateUpArrowButtonWithReference:backHRef 
       
   993             command:backCmd 
       
   994             imagePath:imagePath 
       
   995             altLabel:backLabel.
       
   996         self generateHorizontalLine.
       
   997     ] ifFalse:[
       
   998         backHRef ~~ #none ifTrue:[
       
   999             self
       
  1000                 generateUpArrowButtonWithReference:backHRef 
       
  1001                 command:nil 
       
  1002                 imagePath:imagePath 
       
  1003                 altLabel:backLabel.
       
  1004             self generateHorizontalLine.
       
  1005         ]
       
  1006     ].
   994     ].
  1007 
   995 
  1008     s nextPutLine:'<h1>'.
   996     s nextPutLine:'<h1>'.
  1009     s nextPutAll:'Class: ';
   997     s nextPutAll:'Class: ';
  1010       nextPutAll:'<a INFO="Open a Browser on ' , shortName , '" type="example" action="Smalltalk browseInClass:' , className , '">';
   998       nextPutAll:'<a INFO="Open a Browser on ' , shortName , '" type="example" action="Smalltalk browseInClass:' , className , '">';
  2130 generateBODYandHTMLEnd
  2118 generateBODYandHTMLEnd
  2131     self generateBODYEnd.
  2119     self generateBODYEnd.
  2132     self generateHTMLEnd.
  2120     self generateHTMLEnd.
  2133 !
  2121 !
  2134 
  2122 
       
  2123 generateBackButton
       
  2124     |backHRef backLabel|
       
  2125 
       
  2126     backRef isNil ifTrue:[
       
  2127         backHRef := self pathToLanguageTopOfDocumentation , '/TOP.html'.
       
  2128         backLabel := 'top'.
       
  2129     ] ifFalse:[
       
  2130         backHRef := backRef.
       
  2131         backLabel := 'back'.
       
  2132     ].
       
  2133     backCmd notNil ifTrue:[
       
  2134         self
       
  2135             generateUpArrowButtonWithReference:backHRef 
       
  2136             command:backCmd 
       
  2137             imagePath:imagePath 
       
  2138             altLabel:backLabel.
       
  2139         self generateHorizontalLine.
       
  2140     ] ifFalse:[
       
  2141         backHRef ~~ #none ifTrue:[
       
  2142             self
       
  2143                 generateUpArrowButtonWithReference:backHRef 
       
  2144                 command:nil 
       
  2145                 imagePath:imagePath 
       
  2146                 altLabel:backLabel.
       
  2147             self generateHorizontalLine.
       
  2148         ]
       
  2149     ].
       
  2150 !
       
  2151 
  2135 generateClassDocReferenceFor:className
  2152 generateClassDocReferenceFor:className
  2136     self generateClassDocReferenceFor:className text:className
  2153     self generateClassDocReferenceFor:className text:className
  2137 !
  2154 !
  2138 
  2155 
  2139 generateClassDocReferenceFor:className text:text
  2156 generateClassDocReferenceFor:className text:text
  2370 ! !
  2387 ! !
  2371 
  2388 
  2372 !HTMLDocGenerator class methodsFor:'documentation'!
  2389 !HTMLDocGenerator class methodsFor:'documentation'!
  2373 
  2390 
  2374 version
  2391 version
  2375     ^ '$Header: /cvs/stx/stx/libbasic3/HTMLDocGenerator.st,v 1.60 2003-09-22 18:12:48 cg Exp $'
  2392     ^ '$Header: /cvs/stx/stx/libbasic3/HTMLDocGenerator.st,v 1.61 2003-09-30 08:26:44 penk Exp $'
  2376 ! !
  2393 ! !