#DOCUMENTATION by cg
class: HTMLDocGenerator
added:
#camelCaseSeparatedWordsOf:do:
#generateKWICForClassAndMethodNames
#generateMethodDocReferenceFor:inClass:text:autoloading:
comment/format in: #generateKWIC
changed:
#htmlKWOCList (send #generateKWICForClassAndMethodNames instead of #generateKWIC)
#htmlKWOCListFor:
--- a/HTMLDocGenerator.st Fri Nov 04 13:47:38 2016 +0100
+++ b/HTMLDocGenerator.st Fri Nov 04 14:33:21 2016 +0100
@@ -212,7 +212,8 @@
CachedKWIC := nil
"
CachedKWIC isNil ifTrue:[
- CachedKWIC := self generateKWIC.
+ "/ CachedKWIC := self generateKWIC.
+ CachedKWIC := self generateKWICForClassAndMethodNames.
"/ to flush the cached kwic, whenever a class-documentation method is changed
Smalltalk addDependent:self class.
].
@@ -369,6 +370,54 @@
!HTMLDocGenerator class methodsFor:'document generation-helpers'!
+camelCaseSeparatedWordsOf:wordIn do:aBlock
+ "
+ self camelCaseSeparatedWordsOf:'HelloWorld' do:[:w | Transcript showCR:w]
+ self camelCaseSeparatedWordsOf:'abcDef' do:[:w | Transcript showCR:w]
+ self camelCaseSeparatedWordsOf:'UTFEncoder' do:[:w | Transcript showCR:w]
+ self camelCaseSeparatedWordsOf:'JisEncoder' do:[:w | Transcript showCR:w]
+ self camelCaseSeparatedWordsOf:'JISEncode' do:[:w | Transcript showCR:w]
+ "
+ |state newState in out ch part|
+
+ in := wordIn readStream.
+ out := '' writeStream.
+ [in atEnd] whileFalse:[
+ ch := in next.
+ (ch isDigit or:[ch == $_]) ifFalse:[
+ newState := ch isUppercase.
+ ].
+ (newState ~~ state) ifTrue:[
+ newState == true ifTrue:[
+ "/ going from lower- to uppercase
+ part := out contents.
+ part notEmpty ifTrue:[ aBlock value:part ].
+ out := '' writeStream.
+ out nextPut:ch.
+ state := newState.
+ ] ifFalse:[
+ "/ going upper- to lowercase
+ out size <= 1 ifTrue:[
+ out nextPut:ch.
+ ] ifFalse:[
+ |prev|
+
+ prev := out contents.
+ aBlock value:(prev copyButLast).
+ out := '' writeStream.
+ out nextPut:prev last.
+ out nextPut:ch.
+ ].
+ state := newState.
+ ].
+ ] ifFalse:[
+ out nextPut:ch.
+ ].
+ ].
+ part := out contents.
+ part notEmpty ifTrue:[ aBlock value:part ].
+!
+
generateKWIC
|fillWords kwic|
@@ -392,7 +441,9 @@
kwic := KeywordInContextIndexBuilder new.
kwic excluded:fillWords.
- kwic separatorAlgorithm:[:line | line asCollectionOfSubstringsSeparatedByAny:' ^~=@.:,;-+*/()[]|{}#"''<>',Character cr].
+ kwic separatorAlgorithm:[:line |
+ line asCollectionOfSubstringsSeparatedByAny:' ^~=@.:,;-+*/()[]|{}#"''<>',Character cr
+ ].
kwic exclusionFilter:[:word |
word size == 1
or:[ word conform:#isDigit ]].
@@ -434,6 +485,60 @@
"
!
+generateKWICForClassAndMethodNames
+ |fillWords kwic|
+
+ fillWords :=
+ #(
+"/ 'the' 'a'
+"/ 'can' 'you'
+"/ 'to' 'in' 'out' 'at' 'of'
+"/ 'also' 'with' 'without' 'all' 'any' 'how'
+"/ 'however' 'although' 'always' 'either' 'neither'
+"/ 'anywhere' 'anyway' 'anything' 'anyone'
+"/ 'not' 'but' 'else' 'elsewhere'
+"/ 'am' 'are' 'is' 'be' 'will' 'wont' 'won''t' 'do' 'don''t'
+"/ 'no' 'non' 'now' 'old' 'on' 'only'
+"/ 'my' 'their' 'your' 'its'
+"/ 'one' 'two' 'three'
+"/ 'etc' 'for' 'lot' 'lots' 'made' 'may' 'most' 'mostly' 'much'
+"/ 'use' 'this' 'that' 'which' 'what' 'why'
+"/ 'or' 'other' 'please'
+ ).
+
+ kwic := KeywordInContextIndexBuilder new.
+ kwic excluded:fillWords.
+ kwic separatorAlgorithm:[:name |
+ |words|
+ words := Set new.
+ (name asCollectionOfSubstringsSeparatedBy:$:) do:[:eachPart |
+ eachPart notEmpty ifTrue:[
+ self camelCaseSeparatedWordsOf:eachPart do:[:w | words add:w].
+ ].
+ ].
+ words := words reject:[:w | w isEmpty].
+ words
+ ].
+
+ Smalltalk allClassesDo:[:eachClass |
+ kwic addLine:eachClass name reference:eachClass ignoreCase:true.
+"/ eachClass isLoaded ifTrue:[
+"/ eachClass theNonMetaclass selectorsAndMethodsDo:[:sel :mthd |
+"/ kwic addLine:sel reference:mthd ignoreCase:true.
+"/ ].
+"/ eachClass theMetaclass selectorsAndMethodsDo:[:sel :mthd|
+"/ kwic addLine:sel reference:mthd ignoreCase:true.
+"/ ].
+"/ ].
+ ].
+ ^ kwic
+
+ "
+ CachedKWIC := nil.
+ self generateKWICForClassAndMethodNames
+ "
+!
+
htmlForMethod:aMethod
|who sel partStream args argStream methodSpecLine|
@@ -2341,9 +2446,9 @@
].
].
- aKWIC matchSorter:[:a :b | a value name < b value name].
+ aKWIC matchSorter:[:a :b | a key < b key].
- aKWIC entriesDo:[:word :left :right :class|
+ aKWIC entriesDo:[:word :left :right :classOrMethod|
|ref lcWord ctx|
ctx := (HTMLUtilities escapeCharacterEntities:(left contractAtBeginningTo:25))
@@ -2358,14 +2463,22 @@
"/ outStream nextPutLine:'<dt>',(HTMLUtilities escapeCharacterEntities:(caseMapping at:lcWord ifAbsent:[word])),'</dt>'.
outStream nextPutLine:'<dt>',(HTMLUtilities escapeCharacterEntities:word),'</dt>'.
outStream nextPutLine:'<dd><ul><li>'.
- self generateClassDocReferenceFor:class name.
+ classOrMethod isBehavior ifTrue:[
+ self generateClassDocReferenceFor:classOrMethod name.
+ ] ifFalse:[
+ self generateMethodDocReferenceFor:classOrMethod selector inClass:classOrMethod mclass name text:classOrMethod selector autoloading:nil.
+ ].
outStream nextPutAll:'<tab indent=300>'.
outStream nextPutLine:ctx.
outStream nextPutLine:'</li>'.
prevWord := lcWord.
] ifFalse:[
outStream nextPutLine:'</li><li>'.
- self generateClassDocReferenceFor:class name.
+ classOrMethod isBehavior ifTrue:[
+ self generateClassDocReferenceFor:classOrMethod name.
+ ] ifFalse:[
+ self generateMethodDocReferenceFor:classOrMethod selector inClass:classOrMethod mclass name text:classOrMethod selector autoloading:nil.
+ ].
outStream nextPutAll:'<tab indent=300>'.
outStream nextPutLine:ctx.
outStream nextPutLine:'</li>'.
@@ -2948,6 +3061,38 @@
outStream nextPutLine:'<hr>'.
!
+generateMethodDocReferenceFor:selector inClass:className text:text autoloading:autoloadedClass
+ "generates a link to a classes documentation"
+
+ |href serviceLinkName action|
+
+ self generatingForSTXBrowser ifTrue:[
+ action := self class name , ' htmlDocOf:' , className.
+ autoloadedClass notNil ifTrue:[
+ action := autoloadedClass , ' autoload,', action.
+ ].
+
+ href := self
+ anchorForHTMLAction:action
+ info:('Show documentation of ' , className )
+ text:text.
+ ] ifFalse:[
+ "/ page is generated for a real http service;
+ "/ generate a link to the services classDocOf page,
+ "/ Assumes that the server has a classDoc service running.
+ httpRequestOrNil notNil ifTrue:[
+ serviceLinkName := httpRequestOrNil serviceLinkName.
+ ].
+ href := self
+ anchorFor:(serviceLinkName, '/classDocOf,', (HTMLUtilities escape:className) )
+ info:('Show documentation of ' , className )
+ text:text
+ name:nil
+ ].
+
+ outStream nextPutAll:href.
+!
+
generatePackageDocReferenceFor:packageID text:text
"generates a link to a package documentation"