Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
- Did a pass on the complete code
Browse files Browse the repository at this point in the history
- Remove unused code
- Check comments.
- Recategorised some methods.
See #12 for next actions.
  • Loading branch information
Ducasse committed Oct 6, 2021
1 parent 11415da commit 2127d33
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Class {

{ #category : #tests }
StGithubDocSpecificationTest >> testUrlForDocFolder [

| spec |
spec := StGithubDocSpecification new branch: 'Pharo10'.
self
Expand All @@ -18,6 +19,7 @@ StGithubDocSpecificationTest >> testUrlForDocFolder [

{ #category : #tests }
StGithubDocSpecificationTest >> testUrlForFile [

| spec |
spec := StGithubDocSpecification new branch: 'Pharo10'.
self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ StHelpBrowserPresenterTest >> tearDown [
{ #category : #'tests - interaction' }
StHelpBrowserPresenterTest >> testOpenIsWorkingSmokeTest [
"When this fails we have found a default way to open the help browser, then this test should be changed"

| browser |
self
should: [
browser := self presenterClass new.
window := browser openWithSpec]
window := browser openWithSpec ]
raise: Exception
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ StTopicBuilderVisitorTest >> testTopicBuilderVisitorVisitHeaderAtLevel2 [
StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithLevelsSections [

| topic |

topic := self topicIn: self class spFileContentsLevelsSections.
self assert: topic subtopics first title equals: 'Section 1'.
self assert: topic subtopics first subtopics first title equals: 'Section 2'.
]

{ #category : #tests }
StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSections [

| topic |
topic := self topicIn: self class spFileContentsMoreSections.
self assert: topic subtopics second title equals: 'Section 2'.
Expand All @@ -110,8 +110,8 @@ StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSections [

{ #category : #tests }
StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSubSection [
| topic |


| topic |
topic := self topicIn: self class spFileContentsWithMoreSubSection.
self
assert: (topic subtopics first subtopics second) title
Expand Down Expand Up @@ -143,6 +143,7 @@ StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithOneSubSection [

{ #category : #helper }
StTopicBuilderVisitorTest >> topicIn: aString [

| visitor |
visitor := StTopicBuilderVisitor new.
visitor visit: (MicroDownParser new parse: aString).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
#category : #'NewTools-DocumentationReader-Tests'
}

{ #category : #'as yet unclassified' }
{ #category : #'manual inspection' }
StTopicFromFileFolderBuilderTest class >> eyeballTest [
"This should be able to open the HelpBrowser on the test data"
<script>
Expand Down Expand Up @@ -59,7 +59,9 @@ StTopicFromFileFolderBuilderTest >> createFilesIn: root from: anArray [

{ #category : #initialization }
StTopicFromFileFolderBuilderTest >> fileContents: fileName [
^ self perform: (fileName copyReplaceAll: '.' with: '_' )asSymbol
"We replace . by _ because the methods are named sunit_md."

^ self perform: (fileName copyReplaceAll: '.' with: '_' ) asSymbol

]

Expand All @@ -75,7 +77,7 @@ StTopicFromFileFolderBuilderTest >> initializeTestFileStore [
sunitFramework.md
The subject files are made in the methods topic1Subject11 etc
"
docDir ifNotNil: [ ^docDir ].
docDir ifNotNil: [ ^ docDir ].
docDir := self
createFilesIn: FileSystem memory workingDirectory
from: #( doc #(welcome 'welcome.md' 'contribute.md') #(sunit 'sunitFramework.md')).
Expand All @@ -84,6 +86,7 @@ StTopicFromFileFolderBuilderTest >> initializeTestFileStore [

{ #category : #running }
StTopicFromFileFolderBuilderTest >> setUp [

super setUp.
self initializeTestFileStore.
rootTopic := StTopicFromFileFolderBuilder new createRootTopicFromFolder: docDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ StTopicFromGithubBuilderTest class >> eyeballTest [
{ #category : #initialization }
StTopicFromGithubBuilderTest >> initialize [
"Reset cache first time"

StTopicFromGithubBuilder reset.
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ StHelpBrowserPresenter >> initializePresenters [
strings, not instances of Text (the fact that it works now is just casual, and will
be removed in the future)"
textOutput := self newMorph
morph: (RubScrolledTextMorph new
morph: (RubScrolledTextMorph new
beWrapped;
hResizing: #spaceFill;
vResizing: #spaceFill;
in: [ :this | this textArea readOnly: true ];
Expand Down
3 changes: 2 additions & 1 deletion src/NewTools-DocumentationReader/StIconClassBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Class {

{ #category : #build }
StIconClassBuilder >> buildIcon: aTopic [
aTopic title = 'Subclasses' ifTrue: [ ^ aTopic icon: (Smalltalk ui icons iconNamed: #hierarchy) ].
aTopic title = 'Subclasses'
ifTrue: [ ^ aTopic icon: (self iconNamed: #hierarchy) ].
^ aTopic icon: (self class environment at: aTopic title asSymbol) systemIcon
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"
I create a documentation for a class and such documentation that be displayed in a documentation reader.
"
Class {
#name : #StMicrodownClassAPIHelpBuilder,
#superclass : #HelpBuilder,
Expand Down Expand Up @@ -80,7 +83,7 @@ StMicrodownClassAPIHelpBuilder >> build [
{ #category : #'private building' }
StMicrodownClassAPIHelpBuilder >> buildMethodTopicsOn: topic for: aClass [

|stream methodComment|
| stream methodComment |
stream := String new writeStream.
aClass selectors asSortedCollection do: [:selector |
methodComment := (aClass>>selector) comment.
Expand All @@ -92,9 +95,10 @@ StMicrodownClassAPIHelpBuilder >> buildMethodTopicsOn: topic for: aClass [
nextPutAll: selector asString;
nextPutAll: '`';
cr.

methodComment ifNil: [ methodComment := 'Method has no comment.' ].
stream nextPutAll: '_"'; nextPutAll: methodComment; nextPutAll: '"_';cr;cr ] ].
stream
nextPutAll: '_"';
nextPutAll: methodComment; nextPutAll: '"_';cr;cr ] ].

topic addNode: (MicroDownParser new parse: stream contents).

Expand Down Expand Up @@ -146,7 +150,8 @@ StMicrodownClassAPIHelpBuilder >> buildSubnodesForSubclasses [
]

{ #category : #accessing }
StMicrodownClassAPIHelpBuilder >> iconBuilder [
StMicrodownClassAPIHelpBuilder >> iconBuilder [

^ iconBuilder
]

Expand All @@ -159,8 +164,6 @@ StMicrodownClassAPIHelpBuilder >> iconBuilder: aIconBuilder [
{ #category : #initialization }
StMicrodownClassAPIHelpBuilder >> initialize [

"Initializes the receiver"

super initialize.
addSubclasses := false.
addMethods := true.
Expand All @@ -171,11 +174,13 @@ StMicrodownClassAPIHelpBuilder >> initialize [

{ #category : #accessing }
StMicrodownClassAPIHelpBuilder >> subclassesAsSeparateTopic [

^ subclassesAsSeparateTopic
]

{ #category : #accessing }
StMicrodownClassAPIHelpBuilder >> subclassesAsSeparateTopic: anObject [

subclassesAsSeparateTopic := anObject
]

Expand Down
4 changes: 2 additions & 2 deletions src/NewTools-DocumentationReader/StNodeHelpTopic.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ StNodeHelpTopic >> initialize [

super initialize.
self iconName: #pageIcon.
contents := MicRootBlock new.
contents := MicRootBlock new
]

{ #category : #inspecting }
Expand Down Expand Up @@ -68,6 +68,6 @@ StNodeHelpTopic >> node [
{ #category : #accessing }
StNodeHelpTopic >> subtopics: aCollection [

aCollection ifNotEmpty: [self iconName: #bookIcon].
aCollection ifNotEmpty: [ self iconName: #bookIcon ].
super subtopics: aCollection
]
12 changes: 3 additions & 9 deletions src/NewTools-DocumentationReader/StTopicBuilderVisitor.class.st
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"
When I visit a header I create a `StNodeHelpTopic`.
When I visit anything node I add the node at the last `StNodeHelpTopic` create.
When I visit anything else I add the node at the last `StNodeHelpTopic` create.
"
Class {
#name : #StTopicBuilderVisitor,
#superclass : #MicrodownVisitor,
#instVars : [
'actualTopic',
'helpTopicVisitor',
'helpTopic'
],
#category : #'NewTools-DocumentationReader'
}

{ #category : #internals }
StTopicBuilderVisitor >> extractNode: aNode into: aTopic [

aTopic owner ifNotNil: [
aTopic owner addNode: aNode.
self extractNode: aNode into: aTopic owner ]
Expand All @@ -26,6 +26,7 @@ StTopicBuilderVisitor >> extractNode: aNode into: aTopic [

{ #category : #accessing }
StTopicBuilderVisitor >> helpTopic [

^ helpTopic
]

Expand All @@ -35,13 +36,6 @@ StTopicBuilderVisitor >> helpTopicClass [
^ StNodeHelpTopic
]

{ #category : #accessing }
StTopicBuilderVisitor >> helpTopicVisitor [

helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ].
^ helpTopicVisitor
]

{ #category : #initialization }
StTopicBuilderVisitor >> initialize [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ I am able to build a topic tree from a root folder.
The topic tree will have one root - based on the root folder.
It will have subtropics based on subfoldes and the heading hiearchy of the markdown files in the folders.
I'm usually invoked from `StHelpBrowserPresenter class>> #openOnHelpFolder:`
"
Class {
#name : #StTopicFromFileFolderBuilder,
Expand All @@ -23,9 +27,10 @@ StTopicFromFileFolderBuilder class >> cache [
^ cache
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
StTopicFromFileFolderBuilder class >> onDirectory: fileReference [
"return a topic from fileRefence (assumed to be a folder)"
"Return a topic from fileRefence (assumed to be a folder)"

^ self cache at: fileReference ifAbsentPut: [ self new createRootTopicFromFolder: fileReference]
]

Expand Down Expand Up @@ -78,11 +83,13 @@ StTopicFromFileFolderBuilder >> isMicFile: aFile [

{ #category : #accessing }
StTopicFromFileFolderBuilder >> rootTopic [

^ rootTopic ifNil: [ self rootTopic: (self helpTopicClass named: 'Help'). rootTopic ]
]

{ #category : #accessing }
StTopicFromFileFolderBuilder >> rootTopic: aHelpTopic [
StTopicFromFileFolderBuilder >> rootTopic: aHelpTopic [

rootTopic := aHelpTopic asHelpTopic
]

Expand Down
24 changes: 16 additions & 8 deletions src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"
I am read the microdown files in the pharo-project/pharo/doc folder.
From these files I create a topic hiearachy.
From these files I create a topic hierarchy.
My implementation is suffering from the structure of the github api, which do not return a folder tree, but a list of folders.
In the key method `buildSubtopics: pathCollection level: level` the pathCollection and level is a approximation of a folder. Level 3 and path collection:
Expand Down Expand Up @@ -30,16 +30,18 @@ Class {

{ #category : #accessing }
StTopicFromGithubBuilder class >> githubTopics [
"return the root topic for the pharo documentation"
"Return the root topic for the pharo documentation"

^ self githubTopicsFrom: (StGithubDocSpecification new branch: 'Pharo10')
]

{ #category : #accessing }
StTopicFromGithubBuilder class >> githubTopicsFrom: aDocSpec [
"aDocSpec is an instance of StGithubDocSpecifcation"
^cache

^ cache
at: aDocSpec printString
ifAbsentPut: [ (self new docSpec: aDocSpec) buildTopics].
ifAbsentPut: [ (self new docSpec: aDocSpec) buildTopics].
]

{ #category : #accessing }
Expand All @@ -57,6 +59,7 @@ StTopicFromGithubBuilder class >> reset [
{ #category : #private }
StTopicFromGithubBuilder >> buildSubtopics: pathCollection level: level [
"I assume pachCollection shares path below level"

| subDirectories subTopics |
subDirectories := pathCollection select: [ :p | p size >= level ].
subDirectories := subDirectories groupedBy: [ :p | p at: (level)].
Expand All @@ -67,8 +70,8 @@ StTopicFromGithubBuilder >> buildSubtopics: pathCollection level: level [
{ #category : #private }
StTopicFromGithubBuilder >> buildTopic: pathCollection level: level [
"I assume collectionOfPaths to share a root"
| docTopics subTopics topic |

| docTopics subTopics topic |
docTopics := self getFiles: (pathCollection select: [ :p | p size = level ]).
subTopics := docTopics , (self buildSubtopics: pathCollection level: level + 1).
subTopics size = 1
Expand All @@ -82,7 +85,8 @@ StTopicFromGithubBuilder >> buildTopic: pathCollection level: level [
{ #category : #'public-api' }
StTopicFromGithubBuilder >> buildTopics [
"I return a topic (with subtopics) read from the pharo-project repository on github"
| root subTopics|

| root subTopics |
[ :job |
readingJob := job.
jobCounter := 1.
Expand Down Expand Up @@ -112,6 +116,7 @@ StTopicFromGithubBuilder >> docSpec: anObject [
StTopicFromGithubBuilder >> documentForPath: aPath [
"https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/Epicea/1-Epicea.md"
"aPath is the stuff after the doc/"

|url response doc |
readingJob title: aPath segments last.
url := docSpec urlForFile: aPath pathString.
Expand All @@ -125,24 +130,27 @@ StTopicFromGithubBuilder >> documentForPath: aPath [
{ #category : #private }
StTopicFromGithubBuilder >> getFiles: pathCollection [
"Return an OrderedCollection of documents in the pathCollection"

^ (pathCollection collect: [ :path | self documentForPath: path ]) flattened.
]

{ #category : #accessing }
{ #category : #initialization }
StTopicFromGithubBuilder >> initialize [
super initialize.
docSpec := StGithubDocSpecification new branch: 'Pharo10'.
]

{ #category : #private }
StTopicFromGithubBuilder >> locationFrom: pathCollection level: level [

^ (pathCollection first segments copyFrom: 1 to: level) joinUsing: '/'
]

{ #category : #private }
StTopicFromGithubBuilder >> pharoDocPaths [
"I return an ordered collection of paths for documents in the doc tree"
|folderUrl docURL json|

| folderUrl docURL json |
"get the files in the pharo-project repository"
folderUrl := docSpec urlForDocFolder.
json := STONJSON fromString: (githubClientConnection get: folderUrl).
Expand Down
Loading

0 comments on commit 2127d33

Please sign in to comment.