From 8527084bad5ddada701da8c2ad14b70cf528e4df Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Tue, 28 Sep 2021 10:33:40 +0200 Subject: [PATCH 01/17] temp save of github-builder --- .../StGithubDocFolderBuilder.class.st | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st new file mode 100644 index 0000000..23dd314 --- /dev/null +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -0,0 +1,86 @@ +" +I am read the microdown files in the pharo-project/pharo/doc folder. +From these files I create a topic hiearachy. +" +Class { + #name : #StGithubDocFolderBuilder, + #superclass : #Object, + #instVars : [ + 'iconBuilder' + ], + #category : #'NewTools-DocumentationReader' +} + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> buildTopicFor: collectionOfPaths [ + "I assume collectionOfPaths to share a root" + | title subElements files subDirs topic | + collectionOfPaths ifEmpty: [ ^nil ]. + title := collectionOfPaths first first. + subElements := (collectionOfPaths + collect: [ :p | p copyWithoutFirst ]). + files := subElements select: [ :p | p size = 1 ]. + subDirs := subElements select: [ :p | p size > 1 ]. + topic := StNodeHelpTopic named: title with: self iconBuilder. + self addFiles: files toTopic: topic. + self addDirs: subDirs toTopic: topic. + ^ topic +] + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> documentForPath: aPath [ + "https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/Epicea/1-Epicea.md" + |url response| + url := 'https://raw.githubusercontent.com/pharo-project/pharo/' + ,self pharoVersion, aPath pathString. + response := ZnClient new beOneShot;get: url. + ^ MicroDownParser parse: response. +] + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> getFiles: pathCollection [ + "Return an OrderedDictionary mapping filename (last element in path) to a markdown root node" + ^ pathCollection + inject: OrderedDictionary new + into: [ :dic :path | + dic at: path segments last put: (self documentForPath: path). + dic ] +] + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> groupPaths: pathCollection level: level [ + |subLevels groups thisLevel files | + thisLevel := pathCollection select: [ :p | p size = level ]. + files := self getFiles: thisLevel. + subLevels := pathCollection select: [ :p | p size > level ]. + groups := subLevels groupedBy: [ :p | p at: level ]. + ^ files addAll: (groups collect: [ :grp | self groupPaths: grp level: level + 1 ]) associations; yourself +] + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> grouped: splitted [ +] + +{ #category : #accessing } +StGithubDocFolderBuilder >> iconBuilder [ + iconBuilder ifNil: [ iconBuilder := StIconBookBuilder new ]. + ^ iconBuilder +] + +{ #category : #protocol } +StGithubDocFolderBuilder >> pharoDocTree [ + "I return an ordered collection of paths for documents in the doc tree" + |url response json| + url := 'https://api.github.com/repos/pharo-project/pharo/git/trees/' + ,self pharoVersion,'?recursive=1.'. + response := ZnClient new beOneShot;get: url. + json := STONJSON fromString: response. + ^ ((json at: 'tree') + select: [ :e| ((e at: 'type') = 'blob') and: [(e at: 'path') beginsWith: 'doc/']]) + collect: [:e| e at: 'path'] +] + +{ #category : #protocol } +StGithubDocFolderBuilder >> pharoVersion [ + ^'Pharo10' +] From 054c6f4a9282d46654c7c21bdf1f62697290ca78 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Tue, 28 Sep 2021 19:44:20 +0200 Subject: [PATCH 02/17] Building help directly from github repository --- .../StGithubDocFolderBuilder.class.st | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st index 23dd314..5bdda37 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -12,19 +12,26 @@ Class { } { #category : #'as yet unclassified' } -StGithubDocFolderBuilder >> buildTopicFor: collectionOfPaths [ +StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ "I assume collectionOfPaths to share a root" - | title subElements files subDirs topic | - collectionOfPaths ifEmpty: [ ^nil ]. - title := collectionOfPaths first first. - subElements := (collectionOfPaths - collect: [ :p | p copyWithoutFirst ]). - files := subElements select: [ :p | p size = 1 ]. - subDirs := subElements select: [ :p | p size > 1 ]. + | documents subTopics title topic | + title := pathCollection first at: level. + documents := self getFiles: (pathCollection select: [ :p | p size = level ]). + subTopics := ((pathCollection select: [ :p | p size > level ]) + groupedBy: [ :p | p at: (level+1)]) + values collect: [ :grp | self buildTopic: grp level: level + 1 ]. topic := StNodeHelpTopic named: title with: self iconBuilder. - self addFiles: files toTopic: topic. - self addDirs: subDirs toTopic: topic. - ^ topic + topic node children: documents. + topic subtopics: subTopics. + ^topic +] + +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> buildTopics [ + ^ self + buildTopic: self pharoDocTree + level: 1 + ] { #category : #'as yet unclassified' } @@ -32,33 +39,15 @@ StGithubDocFolderBuilder >> documentForPath: aPath [ "https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/Epicea/1-Epicea.md" |url response| url := 'https://raw.githubusercontent.com/pharo-project/pharo/' - ,self pharoVersion, aPath pathString. + ,self pharoVersion,'/', aPath pathString. response := ZnClient new beOneShot;get: url. ^ MicroDownParser parse: response. ] { #category : #'as yet unclassified' } StGithubDocFolderBuilder >> getFiles: pathCollection [ - "Return an OrderedDictionary mapping filename (last element in path) to a markdown root node" - ^ pathCollection - inject: OrderedDictionary new - into: [ :dic :path | - dic at: path segments last put: (self documentForPath: path). - dic ] -] - -{ #category : #'as yet unclassified' } -StGithubDocFolderBuilder >> groupPaths: pathCollection level: level [ - |subLevels groups thisLevel files | - thisLevel := pathCollection select: [ :p | p size = level ]. - files := self getFiles: thisLevel. - subLevels := pathCollection select: [ :p | p size > level ]. - groups := subLevels groupedBy: [ :p | p at: level ]. - ^ files addAll: (groups collect: [ :grp | self groupPaths: grp level: level + 1 ]) associations; yourself -] - -{ #category : #'as yet unclassified' } -StGithubDocFolderBuilder >> grouped: splitted [ + "Return an OrderedCollection of documents in the pathCollection" + ^ pathCollection collect: [ :path | self documentForPath: path ]. ] { #category : #accessing } @@ -77,7 +66,7 @@ StGithubDocFolderBuilder >> pharoDocTree [ json := STONJSON fromString: response. ^ ((json at: 'tree') select: [ :e| ((e at: 'type') = 'blob') and: [(e at: 'path') beginsWith: 'doc/']]) - collect: [:e| e at: 'path'] + collect: [:e| Path from: (e at: 'path')] ] { #category : #protocol } From 91b033f1d757c14c1eced24c64bdd09bb668f37a Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Wed, 29 Sep 2021 07:30:59 +0200 Subject: [PATCH 03/17] Minor fixes and stream-lining --- .../StGithubDocFolderBuilder.class.st | 4 ++-- .../StHelpBrowserPresenter.class.st | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st index 5bdda37..13b1324 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -21,8 +21,8 @@ StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ groupedBy: [ :p | p at: (level+1)]) values collect: [ :grp | self buildTopic: grp level: level + 1 ]. topic := StNodeHelpTopic named: title with: self iconBuilder. - topic node children: documents. - topic subtopics: subTopics. + documents do: [ :doc | topic addNode: doc ]. + subTopics do: [ :t | topic addSubtopic: t ]. ^topic ] diff --git a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st index f901cf9..47b70ea 100644 --- a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st +++ b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st @@ -180,6 +180,14 @@ StHelpBrowserPresenter class >> openOnHelpFolder: aFileReference [ yourself ] +{ #category : #'instance creation' } +StHelpBrowserPresenter class >> openPharoRepo [ + "Open a HelpBrowser on the internalized docs." + + + self openOn: (StGithubDocFolderBuilder new buildTopics) +] + { #category : #'basic search' } StHelpBrowserPresenter class >> search: aTopicName in: topicCollection with: aCollection [ From 6a7646789495ddf58272319400a0423b96afb807 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Wed, 29 Sep 2021 07:31:57 +0200 Subject: [PATCH 04/17] Hack to make StMicrodownClassAPIHelpBuilder not crash. --- src/NewTools-DocumentationReader/StIconClassBuilder.class.st | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NewTools-DocumentationReader/StIconClassBuilder.class.st b/src/NewTools-DocumentationReader/StIconClassBuilder.class.st index 1293883..52757ba 100644 --- a/src/NewTools-DocumentationReader/StIconClassBuilder.class.st +++ b/src/NewTools-DocumentationReader/StIconClassBuilder.class.st @@ -9,5 +9,6 @@ Class { { #category : #build } StIconClassBuilder >> buildIcon: aTopic [ + aTopic title = 'Subclasses' ifTrue: [ ^ aTopic icon: (Smalltalk ui icons iconNamed: #hierarchy) ]. ^ aTopic icon: (self class environment at: aTopic title asSymbol) systemIcon ] From f84813e2b9d6937ba47ad55d005a6b76e2dd7c6a Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Wed, 29 Sep 2021 09:22:15 +0200 Subject: [PATCH 05/17] Optimized access to pharo repository. Still takes time to read all the documents though. Cashing needed. --- .../StGithubDocFolderBuilder.class.st | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st index 13b1324..571b2c0 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -11,15 +11,23 @@ Class { #category : #'NewTools-DocumentationReader' } +{ #category : #'as yet unclassified' } +StGithubDocFolderBuilder >> 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)]. + subTopics := subDirectories values collect: [ :grp | self buildTopic: grp level: level ]. + ^ subTopics +] + { #category : #'as yet unclassified' } StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ "I assume collectionOfPaths to share a root" | documents subTopics title topic | title := pathCollection first at: level. documents := self getFiles: (pathCollection select: [ :p | p size = level ]). - subTopics := ((pathCollection select: [ :p | p size > level ]) - groupedBy: [ :p | p at: (level+1)]) - values collect: [ :grp | self buildTopic: grp level: level + 1 ]. + subTopics := self buildSubtopics: pathCollection level: level + 1. topic := StNodeHelpTopic named: title with: self iconBuilder. documents do: [ :doc | topic addNode: doc ]. subTopics do: [ :t | topic addSubtopic: t ]. @@ -28,9 +36,11 @@ StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ { #category : #'as yet unclassified' } StGithubDocFolderBuilder >> buildTopics [ - ^ self - buildTopic: self pharoDocTree - level: 1 + | root subTopics| + root := StNodeHelpTopic named: 'Pharo Help' with: self iconBuilder. + subTopics := self buildSubtopics: self pharoDocTree level: 1. + subTopics do: [ :t | root addSubtopic: t ]. + ^ root ] @@ -39,7 +49,7 @@ StGithubDocFolderBuilder >> documentForPath: aPath [ "https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/Epicea/1-Epicea.md" |url response| url := 'https://raw.githubusercontent.com/pharo-project/pharo/' - ,self pharoVersion,'/', aPath pathString. + ,self pharoVersion,'/doc/', aPath pathString. response := ZnClient new beOneShot;get: url. ^ MicroDownParser parse: response. ] @@ -59,13 +69,17 @@ StGithubDocFolderBuilder >> iconBuilder [ { #category : #protocol } StGithubDocFolderBuilder >> pharoDocTree [ "I return an ordered collection of paths for documents in the doc tree" - |url response json| - url := 'https://api.github.com/repos/pharo-project/pharo/git/trees/' - ,self pharoVersion,'?recursive=1.'. - response := ZnClient new beOneShot;get: url. - json := STONJSON fromString: response. + |pharoURL docURL json| + "get the files in the pharo-project repository" + pharoURL := 'https://api.github.com/repos/pharo-project/pharo/git/trees/',self pharoVersion. + json := STONJSON fromString: (ZnClient new beOneShot;get: pharoURL). + "get the url for reading the doc folder only" + docURL := ((json at: 'tree') detect: [ :e| (e at: 'path') = 'doc']) at: 'url'. + "read the subfolder structure too" + docURL := docURL , '?recursive=1'. + json := STONJSON fromString: (ZnClient new beOneShot;get: docURL). ^ ((json at: 'tree') - select: [ :e| ((e at: 'type') = 'blob') and: [(e at: 'path') beginsWith: 'doc/']]) + select: [ :e| ((e at: 'type') = 'blob')]) collect: [:e| Path from: (e at: 'path')] ] From f939a64c97e89f5964b8bf7946e06b3dcd608790 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Thu, 30 Sep 2021 08:41:35 +0200 Subject: [PATCH 06/17] Optimized a bit. Added a job indicator for stress free loading. --- .../StGithubDocFolderBuilder.class.st | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st index 571b2c0..5e8606f 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -6,12 +6,15 @@ Class { #name : #StGithubDocFolderBuilder, #superclass : #Object, #instVars : [ - 'iconBuilder' + 'iconBuilder', + 'githubClientConnection', + 'readingJob', + 'jobCounter' ], #category : #'NewTools-DocumentationReader' } -{ #category : #'as yet unclassified' } +{ #category : #private } StGithubDocFolderBuilder >> buildSubtopics: pathCollection level: level [ "I assume pachCollection shares path below level" | subDirectories subTopics | @@ -21,7 +24,7 @@ StGithubDocFolderBuilder >> buildSubtopics: pathCollection level: level [ ^ subTopics ] -{ #category : #'as yet unclassified' } +{ #category : #private } StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ "I assume collectionOfPaths to share a root" | documents subTopics title topic | @@ -30,31 +33,43 @@ StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ subTopics := self buildSubtopics: pathCollection level: level + 1. topic := StNodeHelpTopic named: title with: self iconBuilder. documents do: [ :doc | topic addNode: doc ]. - subTopics do: [ :t | topic addSubtopic: t ]. + subTopics do: [ :t | topic addSubtopic: t; addNode: t node ]. ^topic ] -{ #category : #'as yet unclassified' } +{ #category : #'public-api' } StGithubDocFolderBuilder >> buildTopics [ + "I return a topic tree read from the pharo-project repository on github" | root subTopics| - root := StNodeHelpTopic named: 'Pharo Help' with: self iconBuilder. - subTopics := self buildSubtopics: self pharoDocTree level: 1. - subTopics do: [ :t | root addSubtopic: t ]. + [ :job | + readingJob := job. + jobCounter := 1. + githubClientConnection := ZnClient new. + root := StNodeHelpTopic named: 'Pharo Help' with: self iconBuilder. + subTopics := self buildSubtopics: self pharoDocPaths level: 1. + subTopics do: [ :t | root addSubtopic: t ]. + githubClientConnection close. + ] asJob run. ^ root ] -{ #category : #'as yet unclassified' } +{ #category : #private } StGithubDocFolderBuilder >> documentForPath: aPath [ "https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/Epicea/1-Epicea.md" - |url response| + "aPath is the stuff after the doc/" + |url response doc| + readingJob title: aPath segments last. url := 'https://raw.githubusercontent.com/pharo-project/pharo/' ,self pharoVersion,'/doc/', aPath pathString. - response := ZnClient new beOneShot;get: url. - ^ MicroDownParser parse: response. + response := githubClientConnection get: url. + doc := MicroDownParser parse: response. + readingJob progress: (jobCounter / 10). + jobCounter := (jobCounter % 10) + 1. + ^doc ] -{ #category : #'as yet unclassified' } +{ #category : #private } StGithubDocFolderBuilder >> getFiles: pathCollection [ "Return an OrderedCollection of documents in the pathCollection" ^ pathCollection collect: [ :path | self documentForPath: path ]. @@ -66,24 +81,24 @@ StGithubDocFolderBuilder >> iconBuilder [ ^ iconBuilder ] -{ #category : #protocol } -StGithubDocFolderBuilder >> pharoDocTree [ +{ #category : #private } +StGithubDocFolderBuilder >> pharoDocPaths [ "I return an ordered collection of paths for documents in the doc tree" |pharoURL docURL json| "get the files in the pharo-project repository" pharoURL := 'https://api.github.com/repos/pharo-project/pharo/git/trees/',self pharoVersion. - json := STONJSON fromString: (ZnClient new beOneShot;get: pharoURL). + json := STONJSON fromString: (githubClientConnection get: pharoURL). "get the url for reading the doc folder only" docURL := ((json at: 'tree') detect: [ :e| (e at: 'path') = 'doc']) at: 'url'. "read the subfolder structure too" docURL := docURL , '?recursive=1'. - json := STONJSON fromString: (ZnClient new beOneShot;get: docURL). + json := STONJSON fromString: (githubClientConnection get: docURL). ^ ((json at: 'tree') select: [ :e| ((e at: 'type') = 'blob')]) collect: [:e| Path from: (e at: 'path')] ] -{ #category : #protocol } +{ #category : #accessing } StGithubDocFolderBuilder >> pharoVersion [ ^'Pharo10' ] From 9002bd88724211704edea4e7573d1e15f724bf21 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Fri, 1 Oct 2021 13:10:13 +0200 Subject: [PATCH 07/17] Initial split of HelpBrowserPresenter into two classes - Presenter logic and FileReading logic. --- .../StFileFolderBuilder.class.st | 102 ++++++++++++++++++ .../StGithubDocFolderBuilder.class.st | 7 -- .../StHelpBrowserPresenter.class.st | 93 +--------------- .../StIconBookBuilder.class.st | 37 ------- .../StNodeHelpTopic.class.st | 21 +--- 5 files changed, 111 insertions(+), 149 deletions(-) create mode 100644 src/NewTools-DocumentationReader/StFileFolderBuilder.class.st delete mode 100644 src/NewTools-DocumentationReader/StIconBookBuilder.class.st diff --git a/src/NewTools-DocumentationReader/StFileFolderBuilder.class.st b/src/NewTools-DocumentationReader/StFileFolderBuilder.class.st new file mode 100644 index 0000000..52a57a3 --- /dev/null +++ b/src/NewTools-DocumentationReader/StFileFolderBuilder.class.st @@ -0,0 +1,102 @@ +" +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. +" +Class { + #name : #StFileFolderBuilder, + #superclass : #Object, + #instVars : [ + 'rootTopic', + 'helpTopicVisitor' + ], + #category : #'NewTools-DocumentationReader' +} + +{ #category : #internals } +StFileFolderBuilder >> createRootTopicFromFolder: aFolder [ + | topic | + topic := (self createTopicsFromFileOrFolder: aFolder) first. + topic subtopics do: [ :each | self propagateNodeIn: each ]. + self rootTopic: topic. +] + +{ #category : #internals } +StFileFolderBuilder >> createTopicsFromFile: aFileOrFolder [ + + | visitor | + visitor := self helpTopicVisitor new. + visitor visit: (Microdown new resolvedTreeFromFile: aFileOrFolder). + ^ visitor helpTopics subtopics +] + +{ #category : #internals } +StFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ + + | subTopic sorted topic | + (aFileOrFolder isFile and: [ self isMicFile: aFileOrFolder ]) + ifTrue: [ ^ self createTopicsFromFile: aFileOrFolder ]. + + topic := self helpTopicClass named: + aFileOrFolder basenameWithoutExtension capitalized. + sorted := self sortFileAndFolder: aFileOrFolder. + sorted do: [ :fileOrFolder | + (self createTopicsFromFileOrFolder: fileOrFolder) do: [ :each | + topic addSubtopic: each ] ]. + subTopic := OrderedCollection new. + subTopic add: topic. + ^ subTopic +] + +{ #category : #hooks } +StFileFolderBuilder >> helpTopicClass [ + + ^ StNodeHelpTopic +] + +{ #category : #accessing } +StFileFolderBuilder >> helpTopicVisitor [ + + helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ]. + ^ helpTopicVisitor +] + +{ #category : #testing } +StFileFolderBuilder >> isMicFile: aFile [ + + ^ #( 'mic' 'md' ) includes: aFile extension +] + +{ #category : #internals } +StFileFolderBuilder >> propagateNodeIn: aRootTopic [ + "If root node (microdown document) is empty, lift nodes from subtopics into node of root" + aRootTopic node children ifEmpty: [ + aRootTopic subtopics do: [ :each | + self propagateNodeIn: each. + each node children do: [ :node | + aRootTopic addNode: node ] + ] ] + +] + +{ #category : #accessing } +StFileFolderBuilder >> rootTopic [ + ^ rootTopic ifNil: [ self rootTopic: (self helpTopicClass named: 'Help'). rootTopic ] +] + +{ #category : #accessing } +StFileFolderBuilder >> rootTopic: aHelpTopic [ + rootTopic := aHelpTopic asHelpTopic +] + +{ #category : #internals } +StFileFolderBuilder >> sortFileAndFolder: aFileOrFolder [ + + | sorted | + sorted := SortedCollection sortBlock: [ :a :b | + a basename <= b basename ]. + sorted addAll: (aFileOrFolder children select: [ :e | + e isDirectory or: [ self isMicFile: e ] ]). + ^ sorted +] diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st index 5e8606f..9a0157d 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st @@ -6,7 +6,6 @@ Class { #name : #StGithubDocFolderBuilder, #superclass : #Object, #instVars : [ - 'iconBuilder', 'githubClientConnection', 'readingJob', 'jobCounter' @@ -75,12 +74,6 @@ StGithubDocFolderBuilder >> getFiles: pathCollection [ ^ pathCollection collect: [ :path | self documentForPath: path ]. ] -{ #category : #accessing } -StGithubDocFolderBuilder >> iconBuilder [ - iconBuilder ifNil: [ iconBuilder := StIconBookBuilder new ]. - ^ iconBuilder -] - { #category : #private } StGithubDocFolderBuilder >> pharoDocPaths [ "I return an ordered collection of paths for documents in the doc tree" diff --git a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st index 47b70ea..703ccb3 100644 --- a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st +++ b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st @@ -218,46 +218,11 @@ StHelpBrowserPresenter >> connectPresenters [ displayIcon: [ :each | each icon ] ] -{ #category : #internals } -StHelpBrowserPresenter >> createRootTopicFromFolder: aFolder [ - | topic | - topic := (self createTopicsFromFileOrFolder: aFolder) first. - topic subtopics do: [ :each | self propagateNodeIn: each ]. - self rootTopic: topic. -] - { #category : #internals } StHelpBrowserPresenter >> createTopicsFromCache [ self createRootTopicFromFolder: self class helpCache. ] -{ #category : #internals } -StHelpBrowserPresenter >> createTopicsFromFile: aFileOrFolder [ - - | visitor | - visitor := self helpTopicVisitor new. - visitor visit: (Microdown new resolvedTreeFromFile: aFileOrFolder). - ^ visitor helpTopics subtopics -] - -{ #category : #internals } -StHelpBrowserPresenter >> createTopicsFromFileOrFolder: aFileOrFolder [ - - | subTopic sorted topic | - (aFileOrFolder isFile and: [ self isMicFile: aFileOrFolder ]) - ifTrue: [ ^ self createTopicsFromFile: aFileOrFolder ]. - - topic := self helpTopicClass named: - aFileOrFolder basenameWithoutExtension capitalized. - sorted := self sortFileAndFolder: aFileOrFolder. - sorted do: [ :fileOrFolder | - (self createTopicsFromFileOrFolder: fileOrFolder) do: [ :each | - topic addSubtopic: each ] ]. - subTopic := OrderedCollection new. - subTopic add: topic. - ^ subTopic -] - { #category : #internals } StHelpBrowserPresenter >> dummyHelp [ @@ -265,19 +230,6 @@ StHelpBrowserPresenter >> dummyHelp [ This a dummy help.' ] -{ #category : #hooks } -StHelpBrowserPresenter >> helpTopicClass [ - - ^ StNodeHelpTopic -] - -{ #category : #accessing } -StHelpBrowserPresenter >> helpTopicVisitor [ - - helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ]. - ^ helpTopicVisitor -] - { #category : #accessing } StHelpBrowserPresenter >> helpTopicVisitor: aClass [ helpTopicVisitor := aClass @@ -312,12 +264,6 @@ StHelpBrowserPresenter >> initializePresenters [ -] - -{ #category : #testing } -StHelpBrowserPresenter >> isMicFile: aFile [ - - ^ #( 'mic' 'md' ) includes: aFile extension ] { #category : #hooks } @@ -331,18 +277,6 @@ StHelpBrowserPresenter >> parserClass [ ^ MicroDownParser ] -{ #category : #internals } -StHelpBrowserPresenter >> propagateNodeIn: aRootTopic [ - - aRootTopic node children ifEmpty: [ - aRootTopic subtopics do: [ :each | - self propagateNodeIn: each. - each node children do: [ :node | - aRootTopic addNode: node ] - ] ] - -] - { #category : #internals } StHelpBrowserPresenter >> render [ @@ -357,14 +291,9 @@ StHelpBrowserPresenter >> renderNode: aNode [ textOutput morph setText: (self morphWriter visit: aNode) ] -{ #category : #accessing } -StHelpBrowserPresenter >> rootTopic [ - ^ rootTopic ifNil: [ self rootTopic: (self helpTopicClass named: 'Help'). rootTopic ] -] - -{ #category : #accessing } -StHelpBrowserPresenter >> rootTopic: aHelpTopic [ - rootTopic := aHelpTopic asHelpTopic +{ #category : #initialization } +StHelpBrowserPresenter >> rootTopic [ + ^ rootTopic ] { #category : #search } @@ -377,20 +306,8 @@ StHelpBrowserPresenter >> searchAndClick: aTopicName [ ] { #category : #initialization } -StHelpBrowserPresenter >> setModelBeforeInitialization: anHelpTopic [ - - rootTopic := anHelpTopic -] - -{ #category : #internals } -StHelpBrowserPresenter >> sortFileAndFolder: aFileOrFolder [ - - | sorted | - sorted := SortedCollection sortBlock: [ :a :b | - a basename <= b basename ]. - sorted addAll: (aFileOrFolder children select: [ :e | - e isDirectory or: [ self isMicFile: e ] ]). - ^ sorted +StHelpBrowserPresenter >> setModelBeforeInitialization: topic [ + rootTopic := topic ] { #category : #initialization } diff --git a/src/NewTools-DocumentationReader/StIconBookBuilder.class.st b/src/NewTools-DocumentationReader/StIconBookBuilder.class.st deleted file mode 100644 index e955985..0000000 --- a/src/NewTools-DocumentationReader/StIconBookBuilder.class.st +++ /dev/null @@ -1,37 +0,0 @@ -" -I set pageIcon when the topic has not subtopics. -I set bookIcon when the topic has subtopics. -" -Class { - #name : #StIconBookBuilder, - #superclass : #Object, - #instVars : [ - 'bookIcon', - 'pageIcon' - ], - #category : #'NewTools-DocumentationReader' -} - -{ #category : #build } -StIconBookBuilder >> buildBookIcon: aTopic [ - - ^ aTopic iconName: bookIcon -] - -{ #category : #build } -StIconBookBuilder >> buildIcon: aTopic [ - - self buildBookIcon: aTopic -] - -{ #category : #initialization } -StIconBookBuilder >> initialize [ - super initialize. - bookIcon := #bookIcon. - pageIcon := #pageIcon -] - -{ #category : #build } -StIconBookBuilder >> setIconOf: aTopic [ - ^ aTopic iconName: pageIcon -] diff --git a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st index 60ff021..e7d3833 100644 --- a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st +++ b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st @@ -9,8 +9,7 @@ Class { #name : #StNodeHelpTopic, #superclass : #HelpTopic, #instVars : [ - 'node', - 'iconBuilder' + 'node' ], #category : #'NewTools-DocumentationReader' } @@ -33,7 +32,7 @@ StNodeHelpTopic >> addNode: aNode [ { #category : #adding } StNodeHelpTopic >> addSubtopic: aSubTopic [ - iconBuilder buildIcon: self. + self iconName: #bookIcon. super addSubtopic: aSubTopic ] @@ -45,24 +44,12 @@ StNodeHelpTopic >> addSubtopic: aHelpTopic with: aLevel [ ifFalse: [ self addSubtopic: aHelpTopic ] ] -{ #category : #accessing } -StNodeHelpTopic >> iconBuilder [ - ^ iconBuilder -] - -{ #category : #accessing } -StNodeHelpTopic >> iconBuilder: aIconBuilder [ - - iconBuilder := aIconBuilder -] - { #category : #initialize } StNodeHelpTopic >> initialize [ super initialize. + self iconName: #pageIcon. node := MicRootBlock new. - iconBuilder := StIconBookBuilder new. - iconBuilder setIconOf: self ] { #category : #inspecting } @@ -90,6 +77,6 @@ StNodeHelpTopic >> node [ { #category : #accessing } StNodeHelpTopic >> subtopics: aCollection [ - iconBuilder buildIcon: self. + aCollection ifNotEmpty: [self iconName: #bookIcon]. super subtopics: aCollection ] From 2f9345dea926a5278650c39f95e39e440dc5a1c8 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 07:29:22 +0200 Subject: [PATCH 08/17] Refactored StHelpBrowserPresenter into two classes. Presenter to just present (GUI) and TopicFromFileFolderBuilder to build topics from a file structure. --- .../StHelpBrowserPresenter.class.st | 80 +------------------ .../StNodeHelpTopic.class.st | 14 ++-- ... => StTopicFromFileFolderBuilder.class.st} | 27 ++++--- ...s.st => StTopicFromGithubBuilder.class.st} | 26 +++--- 4 files changed, 38 insertions(+), 109 deletions(-) rename src/NewTools-DocumentationReader/{StFileFolderBuilder.class.st => StTopicFromFileFolderBuilder.class.st} (73%) rename src/NewTools-DocumentationReader/{StGithubDocFolderBuilder.class.st => StTopicFromGithubBuilder.class.st} (80%) diff --git a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st index 703ccb3..d3f0078 100644 --- a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st +++ b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st @@ -36,7 +36,6 @@ Class { 'helpTopicVisitor' ], #classInstVars : [ - 'filesystem', 'helpCache', 'lastopenHelp' ], @@ -66,62 +65,12 @@ StHelpBrowserPresenter class >> emptyHelpCache [ helpCache := nil ] -{ #category : #accessing } -StHelpBrowserPresenter class >> filesystem [ - ^ filesystem -] - -{ #category : #accessing } -StHelpBrowserPresenter class >> filesystem: aFileSystem [ - filesystem := aFileSystem -] - -{ #category : #accessing } -StHelpBrowserPresenter class >> helpCache [ - - ^ helpCache ifNil: [ helpCache := FileSystem memory workingDirectory ] -] - -{ #category : #accessing } -StHelpBrowserPresenter class >> helpCache: aCache [ - helpCache := aCache -] - -{ #category : #cache } -StHelpBrowserPresenter class >> internalizeHelpFrom: aFolderOrFile [ - - | fileRef | - fileRef := aFolderOrFile asFileReference. - self filesystem: FileSystem memory. - [ self internalizeHelpFrom: fileRef at: filesystem workingDirectory basename. - self helpCache: self filesystem workingDirectory / fileRef basename ] - on: FileDoesNotExistException - do: [ 'We do not do anything special because the only thing we could do is to reinitialize -and we may lose the contents if there was one.' ] -] - -{ #category : #cache } -StHelpBrowserPresenter class >> internalizeHelpFrom: aFolderOrFile at: aFolderName [ - - aFolderOrFile isDirectory - ifTrue: [ | directoryPath | - directoryPath := aFolderName , '/' , aFolderOrFile basename. - self filesystem createDirectory: directoryPath. - aFolderOrFile children do: [ :folderOrFile | self internalizeHelpFrom: folderOrFile at: directoryPath ] ] - ifFalse: [ | file filePath | - (self new isMicFile: aFolderOrFile) - ifTrue: [ - filePath := aFolderName , '/' , aFolderOrFile basename. - file := self filesystem workingDirectory / filePath. - file writeStreamDo: [ :stream |stream nextPutAll: aFolderOrFile contents ] ] ] -] - { #category : #'instance creation' } StHelpBrowserPresenter class >> open [ "Open a HelpBrowser on the internalized docs." - ^ self openOnHelpFolder: self helpCache + ^ self error: 'We need to define a good starting point' ] { #category : #'instance creation' } @@ -150,34 +99,11 @@ StHelpBrowserPresenter class >> openOnCustomHelp: aDescription [ ] -{ #category : #'instance creation' } -StHelpBrowserPresenter class >> openOnHelpFolder [ - "Open an help browser." - - self openOnHelpFolder: FileSystem workingDirectory / 'pharo-local' / 'doc' - - -] - { #category : #'instance creation' } StHelpBrowserPresenter class >> openOnHelpFolder: aFileReference [ - "Open an help browser on a given folder." - "Implementation note: the logic is not really good because I have to copy the logic from SpPresenter class>>#newApplication:model:. - Especially how to pass a model before the initialization which is normally done via message #on: " - - | fileReference | - lastopenHelp := self basicNew. - fileReference := aFileReference exists - ifFalse: [ self helpCache ] - ifTrue: [ aFileReference ]. - lastopenHelp createRootTopicFromFolder: fileReference. - ^ lastopenHelp - setModelBeforeInitialization: lastopenHelp rootTopic; - initialize; - openWithSpec; - yourself + self openOn: (StTopicFromFileFolderBuilder new createRootTopicFromFolder: aFileReference ) ] { #category : #'instance creation' } @@ -185,7 +111,7 @@ StHelpBrowserPresenter class >> openPharoRepo [ "Open a HelpBrowser on the internalized docs." - self openOn: (StGithubDocFolderBuilder new buildTopics) + self openOn: (StTopicFromGithubBuilder new buildTopics) ] { #category : #'basic search' } diff --git a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st index e7d3833..279c38f 100644 --- a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st +++ b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st @@ -4,6 +4,8 @@ This is in this document that further microdown elements will be added. Note that I can have subtopics in addition to the microdown element. A subtopic is just similar to myself. + +I store the location I was retrieved from. This location is used for caching of help topics " Class { #name : #StNodeHelpTopic, @@ -11,18 +13,12 @@ Class { #instVars : [ 'node' ], + #classInstVars : [ + 'locationCache' + ], #category : #'NewTools-DocumentationReader' } -{ #category : #'instance creation' } -StNodeHelpTopic class >> named: aName with: anIconBuilder [ - | topic | - topic := self named: aName. - topic iconBuilder: anIconBuilder. - topic iconBuilder buildIcon: topic. - ^ topic -] - { #category : #adding } StNodeHelpTopic >> addNode: aNode [ diff --git a/src/NewTools-DocumentationReader/StFileFolderBuilder.class.st b/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st similarity index 73% rename from src/NewTools-DocumentationReader/StFileFolderBuilder.class.st rename to src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st index 52a57a3..c9f715a 100644 --- a/src/NewTools-DocumentationReader/StFileFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st @@ -5,7 +5,7 @@ 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. " Class { - #name : #StFileFolderBuilder, + #name : #StTopicFromFileFolderBuilder, #superclass : #Object, #instVars : [ 'rootTopic', @@ -15,15 +15,17 @@ Class { } { #category : #internals } -StFileFolderBuilder >> createRootTopicFromFolder: aFolder [ +StTopicFromFileFolderBuilder >> createRootTopicFromFolder: aFolder [ + "I am the entry method" | topic | topic := (self createTopicsFromFileOrFolder: aFolder) first. topic subtopics do: [ :each | self propagateNodeIn: each ]. self rootTopic: topic. + ^ topic ] { #category : #internals } -StFileFolderBuilder >> createTopicsFromFile: aFileOrFolder [ +StTopicFromFileFolderBuilder >> createTopicsFromFile: aFileOrFolder [ | visitor | visitor := self helpTopicVisitor new. @@ -32,14 +34,13 @@ StFileFolderBuilder >> createTopicsFromFile: aFileOrFolder [ ] { #category : #internals } -StFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ +StTopicFromFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ | subTopic sorted topic | (aFileOrFolder isFile and: [ self isMicFile: aFileOrFolder ]) ifTrue: [ ^ self createTopicsFromFile: aFileOrFolder ]. - topic := self helpTopicClass named: - aFileOrFolder basenameWithoutExtension capitalized. + topic := self helpTopicClass named: aFileOrFolder basenameWithoutExtension capitalized. sorted := self sortFileAndFolder: aFileOrFolder. sorted do: [ :fileOrFolder | (self createTopicsFromFileOrFolder: fileOrFolder) do: [ :each | @@ -50,26 +51,26 @@ StFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ ] { #category : #hooks } -StFileFolderBuilder >> helpTopicClass [ +StTopicFromFileFolderBuilder >> helpTopicClass [ ^ StNodeHelpTopic ] { #category : #accessing } -StFileFolderBuilder >> helpTopicVisitor [ +StTopicFromFileFolderBuilder >> helpTopicVisitor [ helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ]. ^ helpTopicVisitor ] { #category : #testing } -StFileFolderBuilder >> isMicFile: aFile [ +StTopicFromFileFolderBuilder >> isMicFile: aFile [ ^ #( 'mic' 'md' ) includes: aFile extension ] { #category : #internals } -StFileFolderBuilder >> propagateNodeIn: aRootTopic [ +StTopicFromFileFolderBuilder >> propagateNodeIn: aRootTopic [ "If root node (microdown document) is empty, lift nodes from subtopics into node of root" aRootTopic node children ifEmpty: [ aRootTopic subtopics do: [ :each | @@ -81,17 +82,17 @@ StFileFolderBuilder >> propagateNodeIn: aRootTopic [ ] { #category : #accessing } -StFileFolderBuilder >> rootTopic [ +StTopicFromFileFolderBuilder >> rootTopic [ ^ rootTopic ifNil: [ self rootTopic: (self helpTopicClass named: 'Help'). rootTopic ] ] { #category : #accessing } -StFileFolderBuilder >> rootTopic: aHelpTopic [ +StTopicFromFileFolderBuilder >> rootTopic: aHelpTopic [ rootTopic := aHelpTopic asHelpTopic ] { #category : #internals } -StFileFolderBuilder >> sortFileAndFolder: aFileOrFolder [ +StTopicFromFileFolderBuilder >> sortFileAndFolder: aFileOrFolder [ | sorted | sorted := SortedCollection sortBlock: [ :a :b | diff --git a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st b/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st similarity index 80% rename from src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st rename to src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st index 9a0157d..9dc7980 100644 --- a/src/NewTools-DocumentationReader/StGithubDocFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st @@ -3,7 +3,7 @@ I am read the microdown files in the pharo-project/pharo/doc folder. From these files I create a topic hiearachy. " Class { - #name : #StGithubDocFolderBuilder, + #name : #StTopicFromGithubBuilder, #superclass : #Object, #instVars : [ 'githubClientConnection', @@ -14,7 +14,7 @@ Class { } { #category : #private } -StGithubDocFolderBuilder >> buildSubtopics: pathCollection level: level [ +StTopicFromGithubBuilder >> buildSubtopics: pathCollection level: level [ "I assume pachCollection shares path below level" | subDirectories subTopics | subDirectories := pathCollection select: [ :p | p size >= level ]. @@ -24,27 +24,28 @@ StGithubDocFolderBuilder >> buildSubtopics: pathCollection level: level [ ] { #category : #private } -StGithubDocFolderBuilder >> buildTopic: pathCollection level: level [ +StTopicFromGithubBuilder >> buildTopic: pathCollection level: level [ "I assume collectionOfPaths to share a root" | documents subTopics title topic | + title := pathCollection first at: level. documents := self getFiles: (pathCollection select: [ :p | p size = level ]). subTopics := self buildSubtopics: pathCollection level: level + 1. - topic := StNodeHelpTopic named: title with: self iconBuilder. + topic := StNodeHelpTopic named: title. documents do: [ :doc | topic addNode: doc ]. subTopics do: [ :t | topic addSubtopic: t; addNode: t node ]. ^topic ] { #category : #'public-api' } -StGithubDocFolderBuilder >> buildTopics [ +StTopicFromGithubBuilder >> buildTopics [ "I return a topic tree read from the pharo-project repository on github" | root subTopics| [ :job | readingJob := job. jobCounter := 1. githubClientConnection := ZnClient new. - root := StNodeHelpTopic named: 'Pharo Help' with: self iconBuilder. + root := StNodeHelpTopic named: 'Pharo Help'. subTopics := self buildSubtopics: self pharoDocPaths level: 1. subTopics do: [ :t | root addSubtopic: t ]. githubClientConnection close. @@ -54,7 +55,7 @@ StGithubDocFolderBuilder >> buildTopics [ ] { #category : #private } -StGithubDocFolderBuilder >> documentForPath: aPath [ +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| @@ -69,13 +70,18 @@ StGithubDocFolderBuilder >> documentForPath: aPath [ ] { #category : #private } -StGithubDocFolderBuilder >> getFiles: pathCollection [ +StTopicFromGithubBuilder >> getFiles: pathCollection [ "Return an OrderedCollection of documents in the pathCollection" ^ pathCollection collect: [ :path | self documentForPath: path ]. ] +{ #category : #'as yet unclassified' } +StTopicFromGithubBuilder >> locationFrom: pathCollection level: level [ + ^ (pathCollection first segments copyFrom: 1 to: level) joinUsing: '/' +] + { #category : #private } -StGithubDocFolderBuilder >> pharoDocPaths [ +StTopicFromGithubBuilder >> pharoDocPaths [ "I return an ordered collection of paths for documents in the doc tree" |pharoURL docURL json| "get the files in the pharo-project repository" @@ -92,6 +98,6 @@ StGithubDocFolderBuilder >> pharoDocPaths [ ] { #category : #accessing } -StGithubDocFolderBuilder >> pharoVersion [ +StTopicFromGithubBuilder >> pharoVersion [ ^'Pharo10' ] From 9142b01244d66ccf48151fa5c5bfd09883da4848 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 07:30:12 +0200 Subject: [PATCH 09/17] First step in building test for folder based topic structure. --- .../StTopicFromFileFolderBuilderTest.class.st | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st diff --git a/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st new file mode 100644 index 0000000..6b6aef6 --- /dev/null +++ b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st @@ -0,0 +1,104 @@ +" +A StTopicFromFileFolderBuilderTest is a test class for testing the behavior of StTopicFromFileFolderBuilder +" +Class { + #name : #StTopicFromFileFolderBuilderTest, + #superclass : #TestCase, + #category : #'NewTools-DocumentationReader-Tests' +} + +{ #category : #'test files' } +StTopicFromFileFolderBuilderTest class >> contribute_md [ + ^'# How to Contribute + +Yes you can have an impact on Pharo. +You can join and participate to build a great system and learn so much + +Contributions can be +- answering question on the mailing-list or discord channel (see Documentation item) [https://discord.gg/QewZMZa](https://discord.gg/QewZMZa) +- fixing typos in books [http://books.pharo.org](http://books.pharo.org) +- writing tests +- reproducing and confirming a bug on your OS +- fixing bugs + +You see there are plenty of opportunities to learn while improve Pharo + +To propose a bug fix or enhancement is easy and relatively well documented. +The following website contains a clear description of the change: + [http://pharo.org/contribute-propose-fix](http://pharo.org/contribute-propose-fix) + ' +] + +{ #category : #private } +StTopicFromFileFolderBuilderTest class >> createFilesIn: root from: anArray [ + "Helper method to create a directory hierarchy with files. + Adapted from MemoryFileSystemTest>>createFilesIn:from:" + + | dir path | + + dir := (root / anArray first) createDirectory. + anArray allButFirstDo: [ :each | + each isArray ifTrue: + [ self createFilesIn: dir from: each ] + ifFalse: + [ (path := dir / each) writeStreamDo: [ :stream | + stream nextPutAll: (self fileContents: each) ] ] ]. + ^dir +] + +{ #category : #private } +StTopicFromFileFolderBuilderTest class >> fileContents: fileName [ + ^ self perform: fileName asSymbol + +] + +{ #category : #initialization } +StTopicFromFileFolderBuilderTest class >> initializeTestFileStore [ + "I return a file reference to the root of the test file directory" + "My structure is: + doc + welcome + welcome.md + contribute.md + sunit + sunitFramework.md + The subject files are made in the methods topic1Subject11 etc + " + | docDir | + docDir := self + createFilesIn: FileSystem memory workingDirectory + from: #( doc #(welcome welcome_md contribute_md) #(sunit sunitFramework_md)). + ^docDir parent +] + +{ #category : #'test files' } +StTopicFromFileFolderBuilderTest class >> sunitFramework_md [ + ^'# SUnit framework + +SUnit is the mother of all unit testing frameworks, and serves as one of the cornerstones of test-driven development methodologies such as eXtreme Programming. + +The culture of testing has always been part of the philosophy of development in Smalltalk: +You write a method, accept the code and test it by writing a small script in a workspace, in a comment or an example as a class method. But this approach does not allow to automatically repeat the testing or ensure that the code is working. SUnit is a framework you can use to describe and execute unit tests. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application.' +] + +{ #category : #'test files' } +StTopicFromFileFolderBuilderTest class >> welcome_md [ + ^'# Welcome to Pharo 10 + +Welcome to Pharo, an immersive live programming environment. + +Pharo is a pure object-oriented programming language and a powerful environment, focused on simplicity and immediate feedback (think IDE and OS rolled into one). + +For more information, please visit here: [http://pharo.org](http://pharo.org) + +## Quick setup + +Choose your preferred color theme: +- `PharoLightTheme beCurrent` or `PharoDarkTheme beCurrent` +- and switch fullscreen mode executing `Display toggleFullscreen` + +Click if you have access to a: regular network connection or slow network +or if need to setup a network proxy. + +You can also apply many other other settings by opening the `SettingBrowser open`.' +] From 097be5a7639ee4fc2ac08e5a28987357a4ca4ade Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 11:21:10 +0200 Subject: [PATCH 10/17] Refactor to let StNodeHelpTopic use the field contents to hold its node. --- .../StNodeHelpTopic.class.st | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st index 279c38f..821111c 100644 --- a/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st +++ b/src/NewTools-DocumentationReader/StNodeHelpTopic.class.st @@ -1,18 +1,13 @@ " -I'm a help topic and as such I hold a Microdown root document. -This is in this document that further microdown elements will be added. +I'm a help topic and my content is a Microdown root document. Note that I can have subtopics in addition to the microdown element. A subtopic is just similar to myself. -I store the location I was retrieved from. This location is used for caching of help topics " Class { #name : #StNodeHelpTopic, #superclass : #HelpTopic, - #instVars : [ - 'node' - ], #classInstVars : [ 'locationCache' ], @@ -22,7 +17,7 @@ Class { { #category : #adding } StNodeHelpTopic >> addNode: aNode [ - node addChild: aNode + self node addChild: aNode ] { #category : #adding } @@ -45,7 +40,7 @@ StNodeHelpTopic >> initialize [ super initialize. self iconName: #pageIcon. - node := MicRootBlock new. + contents := MicRootBlock new. ] { #category : #inspecting } @@ -67,7 +62,7 @@ StNodeHelpTopic >> inspectionMCTopicTree [ StNodeHelpTopic >> node [ "Returns the microdown elements holding the document of the help" - ^ node + ^ self contents ] { #category : #accessing } From 67e113cd3ce8798e8e09c8f3c2af99996802fe80 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 11:21:42 +0200 Subject: [PATCH 11/17] Removing more cache stuff. --- .../StHelpBrowserPresenter.class.st | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st index d3f0078..e0395e1 100644 --- a/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st +++ b/src/NewTools-DocumentationReader/StHelpBrowserPresenter.class.st @@ -144,11 +144,6 @@ StHelpBrowserPresenter >> connectPresenters [ displayIcon: [ :each | each icon ] ] -{ #category : #internals } -StHelpBrowserPresenter >> createTopicsFromCache [ - self createRootTopicFromFolder: self class helpCache. -] - { #category : #internals } StHelpBrowserPresenter >> dummyHelp [ From 08cc67de1adeeaf7c7b50f9f9521502a5878edce Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 11:23:31 +0200 Subject: [PATCH 12/17] Refactoring folder and url based building to share lifting of topics from file level to folder level. Renamed the lifting propagation to lifting. --- .../StTopicBuilderVisitor.class.st | 48 +++++++++++-------- .../StTopicFromFileFolderBuilder.class.st | 35 ++------------ .../StTopicFromGithubBuilder.class.st | 2 +- .../StTopicMicrodownBuilder.class.st | 35 ++++++++++++++ 4 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 src/NewTools-DocumentationReader/StTopicMicrodownBuilder.class.st diff --git a/src/NewTools-DocumentationReader/StTopicBuilderVisitor.class.st b/src/NewTools-DocumentationReader/StTopicBuilderVisitor.class.st index a549bbf..3c2cec2 100644 --- a/src/NewTools-DocumentationReader/StTopicBuilderVisitor.class.st +++ b/src/NewTools-DocumentationReader/StTopicBuilderVisitor.class.st @@ -6,12 +6,29 @@ Class { #name : #StTopicBuilderVisitor, #superclass : #MicrodownVisitor, #instVars : [ - 'helpTopics', - 'actualTopic' + '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 ] + + + + +] + +{ #category : #accessing } +StTopicBuilderVisitor >> helpTopic [ + ^ helpTopic +] + { #category : #'visiting-document' } StTopicBuilderVisitor >> helpTopicClass [ @@ -19,27 +36,18 @@ StTopicBuilderVisitor >> helpTopicClass [ ] { #category : #accessing } -StTopicBuilderVisitor >> helpTopics [ - ^ helpTopics +StTopicBuilderVisitor >> helpTopicVisitor [ + + helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ]. + ^ helpTopicVisitor ] { #category : #initialization } StTopicBuilderVisitor >> initialize [ super initialize. - helpTopics := StNodeHelpTopic new. - actualTopic := helpTopics -] - -{ #category : #internals } -StTopicBuilderVisitor >> propagateNode: aNode from: aTopic [ - aTopic owner ifNotNil: [ - aTopic owner addNode: aNode. - self propagateNode: aNode from: aTopic owner ] - - - - + helpTopic := StNodeHelpTopic new. + actualTopic := helpTopic ] { #category : #'visiting-document' } @@ -69,8 +77,8 @@ StTopicBuilderVisitor >> visitAll: aCollection [ aCollection do: [ :each | each accept: self. actualTopic addNode: each. - self propagateNode: each from: actualTopic ]. - ^ helpTopics + self extractNode: each into: actualTopic ]. + ^ helpTopic ] @@ -82,5 +90,5 @@ StTopicBuilderVisitor >> visitHeader: aHeader [ | topic | topic := self helpTopicClass named: aHeader header capitalized. actualTopic := topic. - helpTopics addSubtopic: topic with: aHeader level ] + helpTopic addSubtopic: topic with: aHeader level ] ] diff --git a/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st b/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st index c9f715a..e37fb6c 100644 --- a/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st +++ b/src/NewTools-DocumentationReader/StTopicFromFileFolderBuilder.class.st @@ -6,7 +6,7 @@ It will have subtropics based on subfoldes and the heading hiearchy of the markd " Class { #name : #StTopicFromFileFolderBuilder, - #superclass : #Object, + #superclass : #StTopicMicrodownBuilder, #instVars : [ 'rootTopic', 'helpTopicVisitor' @@ -19,24 +19,20 @@ StTopicFromFileFolderBuilder >> createRootTopicFromFolder: aFolder [ "I am the entry method" | topic | topic := (self createTopicsFromFileOrFolder: aFolder) first. - topic subtopics do: [ :each | self propagateNodeIn: each ]. + topic subtopics do: [ :each | self liftNodesIn: each ]. self rootTopic: topic. ^ topic ] { #category : #internals } StTopicFromFileFolderBuilder >> createTopicsFromFile: aFileOrFolder [ - - | visitor | - visitor := self helpTopicVisitor new. - visitor visit: (Microdown new resolvedTreeFromFile: aFileOrFolder). - ^ visitor helpTopics subtopics + ^ self createTopicsFromDocument: (Microdown new resolvedTreeFromFile: aFileOrFolder). ] { #category : #internals } StTopicFromFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ - | subTopic sorted topic | + | sorted topic | (aFileOrFolder isFile and: [ self isMicFile: aFileOrFolder ]) ifTrue: [ ^ self createTopicsFromFile: aFileOrFolder ]. @@ -45,9 +41,7 @@ StTopicFromFileFolderBuilder >> createTopicsFromFileOrFolder: aFileOrFolder [ sorted do: [ :fileOrFolder | (self createTopicsFromFileOrFolder: fileOrFolder) do: [ :each | topic addSubtopic: each ] ]. - subTopic := OrderedCollection new. - subTopic add: topic. - ^ subTopic + ^ OrderedCollection with: topic. ] { #category : #hooks } @@ -56,31 +50,12 @@ StTopicFromFileFolderBuilder >> helpTopicClass [ ^ StNodeHelpTopic ] -{ #category : #accessing } -StTopicFromFileFolderBuilder >> helpTopicVisitor [ - - helpTopicVisitor ifNil: [ helpTopicVisitor := StTopicBuilderVisitor ]. - ^ helpTopicVisitor -] - { #category : #testing } StTopicFromFileFolderBuilder >> isMicFile: aFile [ ^ #( 'mic' 'md' ) includes: aFile extension ] -{ #category : #internals } -StTopicFromFileFolderBuilder >> propagateNodeIn: aRootTopic [ - "If root node (microdown document) is empty, lift nodes from subtopics into node of root" - aRootTopic node children ifEmpty: [ - aRootTopic subtopics do: [ :each | - self propagateNodeIn: each. - each node children do: [ :node | - aRootTopic addNode: node ] - ] ] - -] - { #category : #accessing } StTopicFromFileFolderBuilder >> rootTopic [ ^ rootTopic ifNil: [ self rootTopic: (self helpTopicClass named: 'Help'). rootTopic ] diff --git a/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st b/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st index 9dc7980..1f31e86 100644 --- a/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st +++ b/src/NewTools-DocumentationReader/StTopicFromGithubBuilder.class.st @@ -4,7 +4,7 @@ From these files I create a topic hiearachy. " Class { #name : #StTopicFromGithubBuilder, - #superclass : #Object, + #superclass : #StTopicMicrodownBuilder, #instVars : [ 'githubClientConnection', 'readingJob', diff --git a/src/NewTools-DocumentationReader/StTopicMicrodownBuilder.class.st b/src/NewTools-DocumentationReader/StTopicMicrodownBuilder.class.st new file mode 100644 index 0000000..67dd720 --- /dev/null +++ b/src/NewTools-DocumentationReader/StTopicMicrodownBuilder.class.st @@ -0,0 +1,35 @@ +" +I implement subtopic generation from headers inside a microdown document. +This is shared behaviour for different kind of builders. +" +Class { + #name : #StTopicMicrodownBuilder, + #superclass : #Object, + #category : #'NewTools-DocumentationReader' +} + +{ #category : #'as yet unclassified' } +StTopicMicrodownBuilder >> createTopicsFromDocument: doc [ + + | visitor | + visitor := self helpTopicVisitor new. + visitor visit: doc. + ^ visitor helpTopic subtopics +] + +{ #category : #accessing } +StTopicMicrodownBuilder >> helpTopicVisitor [ + ^ StTopicBuilderVisitor +] + +{ #category : #internals } +StTopicMicrodownBuilder >> liftNodesIn: aRootTopic [ + "If root node (microdown document) is empty, lift nodes from subtopics into node of root" + aRootTopic node children ifEmpty: [ + aRootTopic subtopics do: [ :each | + self liftNodesIn: each. + each node children do: [ :node | + aRootTopic addNode: node ] + ] ] + +] From d1ca2646acd27d458f4535495fd5df9088268442 Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Mon, 4 Oct 2021 11:25:21 +0200 Subject: [PATCH 13/17] Refactored the tests to suit the refactoring of the code. Simplified the visitor test to test the visitor without using memory files as those should be tested elsewhere (and is). --- .../StHelpBrowserPresenterTest.class.st | 311 +----------------- .../StTopicBuilderVisitorTest.class.st | 120 +++---- .../StTopicFromFileFolderBuilderTest.class.st | 91 ++++- 3 files changed, 120 insertions(+), 402 deletions(-) diff --git a/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st b/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st index ccb1599..4b2f784 100644 --- a/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st +++ b/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st @@ -77,89 +77,15 @@ StHelpBrowserPresenterTest >> tearDown [ super tearDown. ] -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCache [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache basenameWithoutExtension equals: 'doc'. - self - assert: cache children first basenameWithoutExtension - equals: 'file' ] ensure: [ self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheHandleShittyFiles [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - - file := filesystem workingDirectory / 'doc' / '.DS_Store'. - file writeStreamDo: [ :stream | stream nextPutAll: 'crap crap' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache basenameWithoutExtension equals: 'doc'. - self assert: cache children size equals: 1 ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheOnlyAcceptFolderAndMicFiles [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - - file := filesystem workingDirectory / 'doc' / 'Stupid.txt'. - file writeStreamDo: [ :stream | - stream nextPutAll: 'This is a stupid mistyped extension text' ]. - - filesystem createDirectory: 'doc/Epicea'. - file := filesystem workingDirectory / 'doc' / 'Epicea' / 'fileEp.mic'. - file writeStreamDo: [ :stream | - stream nextPutAll: 'this is a text about Epicea' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache children size equals: 2. - self assert: cache allChildren size equals: 4 ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheReturnFileReferenceEmptyIfNil [ - - | cache | - cache := self presenterClass helpCache. - self presenterClass emptyHelpCache. - self assert: self presenterClass helpCache hasChildren not. - self presenterClass helpCache: cache -] - { #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 | - browser := self presenterClass new. - window := browser openWithSpec + self + should: [ + browser := self presenterClass new. + window := browser openWithSpec] + raise: Exception ] { #category : #'tests - interaction' } @@ -185,94 +111,6 @@ StHelpBrowserPresenterTest >> testOpenOnCustomHelp2 [ window := browser openWithSpec ] -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithClass [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: self presenterClass. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithDescription [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: SUnitTutorial. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: 'Tutorial'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithMethod [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: - self presenterClass >> #rootTopic:. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithObject [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: Object new. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithString [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: - self presenterClass >> #rootTopic:. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnDoesNotExistFolder [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnHelpFolder: - FileSystem workingDirectory - / 'ojdoajdjvsaidqsjkjfzeuican'. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - { #category : #tests } StHelpBrowserPresenterTest >> testOpenOnSystemHelp2 [ @@ -283,140 +121,3 @@ StHelpBrowserPresenterTest >> testOpenOnSystemHelp2 [ self assert: rootTopic icon isNil. window := browser openWithSpec ] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotHelpTopicVisitorPerDefault [ - - | visitor browser | - browser := self presenterClass new. - visitor := browser helpTopicVisitor. - self assert: visitor equals: StTopicBuilderVisitor -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotHelpTopicVisitorThatISpecify [ - - | visitor browser | - browser := self presenterClass new. - browser helpTopicVisitor: StTopicBuilderVisitor. - visitor := browser helpTopicVisitor. - self assert: visitor equals: StTopicBuilderVisitor -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotRootTopicThatISpecify [ - - | topic browser | - browser := self presenterClass new. - topic := self helpTopicClass named: 'Test'. - browser rootTopic: topic. - self assert: browser rootTopic equals: topic -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotTopicsPerDefault [ - - | topic browser | - browser := self presenterClass new. - topic := browser rootTopic. - self assert: topic title equals: 'Help' -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotTopicsThatISpecify [ - - | topic browser | - browser := self presenterClass new. - browser rootTopic: (self helpTopicClass named: 'foo'). - topic := browser rootTopic. - self assert: topic title equals: 'foo' -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterDocTopicFromFileSystemOnFile [ - - | file browser rootTopic | - file := filesystem workingDirectory / 'fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := browser createTopicsFromFileOrFolder: file. - self assert: rootTopic size equals: 2 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterDocTopicFromSystem [ - - | file directory browser rootTopic | - filesystem createDirectory: 'test'. - directory := filesystem workingDirectory / 'test'. - file := filesystem workingDirectory / 'test/fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: directory) rootTopic. - self assert: rootTopic subtopics size equals: 2 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterOpenADirectory [ - - | directory browser | - directory := filesystem workingDirectory / self class spDirectoryName. - filesystem createDirectory: self class spDirectoryName. - browser := self presenterClass new. - browser createRootTopicFromFolder: directory. - - self - assert: browser rootTopic title - equals: directory basenameWithoutExtension capitalized -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterTopicFromSystemOnDirectoryWithFiles [ - - | directory file1 file2 browser rootTopic | - filesystem createDirectory: 'test'. - directory := filesystem workingDirectory / 'test'. - - - file1 := filesystem workingDirectory / 'test/fd1.mic'. - file1 writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - - file2 := filesystem workingDirectory / 'test/fd2.mic'. - file2 writeStreamDo: [ :stream | stream nextPutAll: self class spFd2 ]. - - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: directory) rootTopic. - self assert: rootTopic subtopics size equals: 3 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterTopicFromSystemOnFile [ - - | file browser rootTopic | - file := filesystem workingDirectory / 'fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: file) rootTopic. - self assert: rootTopic subtopics size equals: 2 -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testTopicsWithCacheFrom [ - - | docFolder file browser save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | - stream nextPutAll: '# section -this is a text' ]. - self presenterClass internalizeHelpFrom: docFolder. - browser := self presenterClass open. - window := browser window. - self assert: browser rootTopic title equals: 'Doc'. - self assert: browser rootTopic subtopics size equals: 1 ] ensure: [ - self presenterClass helpCache: save ] -] diff --git a/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st b/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st index bc9996b..87cd334 100644 --- a/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st +++ b/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st @@ -1,10 +1,6 @@ Class { #name : #StTopicBuilderVisitorTest, #superclass : #TestCase, - #instVars : [ - 'filesystem', - 'visitor' - ], #category : #'NewTools-DocumentationReader-Tests' } @@ -70,125 +66,85 @@ StTopicBuilderVisitorTest class >> spFileName [ ^ 'test.md' ] -{ #category : #tests } -StTopicBuilderVisitorTest >> helpTopicClass [ - - ^ StNodeHelpTopic -] - -{ #category : #running } -StTopicBuilderVisitorTest >> setUp [ - super setUp. - filesystem := FileSystem memory. - visitor := StTopicBuilderVisitor new - -] - { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorVisitHeader [ - | file text header | + | text topic | text := '# SectionTest This is a paragraphe'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: text ]. - header := (MicroDownParser new parse: file contents) children first. - visitor visitHeader: header. - self assert: visitor helpTopics subtopics first title equals: 'SectionTest'. - self assert: visitor helpTopics subtopics first contents equals: '' + topic := self topicIn: text. + self assert: topic subtopics first title equals: 'SectionTest'. + self assert: topic subtopics first subtopics isEmpty ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorVisitHeaderAtLevel2 [ - | file text header | + | text topic | text := '## SectionTest This is a paragraphe'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: text ]. - header := (MicroDownParser new parse: file contents) children first. - visitor visitHeader: header. - self assert: visitor helpTopics subtopics first title equals: 'SectionTest'. - self assert: visitor helpTopics subtopics first contents equals: '' + topic := self topicIn: text. + self assert: topic subtopics first title equals: 'SectionTest'. + self assert: topic subtopics first subtopics isEmpty ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithLevelsSections [ - | file topics | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsLevelsSections ]. - self visitFile: file. - topics := visitor helpTopics subtopics. - self assert: topics first title equals: 'Section 1'. - self assert: topics first subtopics first title equals: 'Section 2'. + | 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 [ - - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsMoreSections ]. - self visitFile: file. - self assert: (visitor helpTopics subtopics second) title equals: 'Section 2'. - self assert: visitor helpTopics subtopics size equals: 2 + | topic | + topic := self topicIn: self class spFileContentsMoreSections. + self assert: topic subtopics second title equals: 'Section 2'. + self assert: topic subtopics size equals: 2 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSubSection [ - - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsWithMoreSubSection ]. - self visitFile: file. + | topic | + + topic := self topicIn: self class spFileContentsWithMoreSubSection. self - assert: (visitor helpTopics subtopics first subtopics second) title + assert: (topic subtopics first subtopics second) title equals: 'Section 3'. - self assert: visitor helpTopics subtopics size equals: 1. - self assert: visitor helpTopics subtopics first subtopics size equals: 2 + self assert: topic subtopics size equals: 1. + self assert: topic subtopics first subtopics size equals: 2 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithOneSection [ - - | file text | - text := ' -blabla -blabla -'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsOneSection ]. - self visitFile: file. - self assert: (visitor helpTopics subtopics first) title equals: 'Section 1'. - self assert: visitor helpTopics subtopics size equals: 1 + + | topic | + topic := self topicIn: self class spFileContentsOneSection. + self assert: topic subtopics first title equals: 'Section 1'. + self assert: topic subtopics size equals: 1 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithOneSubSection [ - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsWithOneSubSection ]. - self visitFile: file. + | topic | + topic := self topicIn: self class spFileContentsWithOneSubSection. self - assert: ((visitor helpTopics subtopics first) subtopics first) title + assert: topic subtopics first subtopics first title equals: 'Section 2'. - self assert: visitor helpTopics subtopics size equals: 1. - self assert: visitor helpTopics subtopics first subtopics size equals: 1 + self assert: topic subtopics size equals: 1. + self assert: topic subtopics first subtopics size equals: 1 ] { #category : #helper } -StTopicBuilderVisitorTest >> visitFile: file [ - - visitor visit: (MicroDownParser new parse: file contents) +StTopicBuilderVisitorTest >> topicIn: aString [ + | visitor | + visitor := StTopicBuilderVisitor new. + visitor visit: (MicroDownParser new parse: aString). + ^ visitor helpTopic ] diff --git a/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st index 6b6aef6..3e9d121 100644 --- a/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st +++ b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st @@ -4,11 +4,22 @@ A StTopicFromFileFolderBuilderTest is a test class for testing the behavior of S Class { #name : #StTopicFromFileFolderBuilderTest, #superclass : #TestCase, + #instVars : [ + 'docDir', + 'rootTopic' + ], #category : #'NewTools-DocumentationReader-Tests' } -{ #category : #'test files' } -StTopicFromFileFolderBuilderTest class >> contribute_md [ +{ #category : #'as yet unclassified' } +StTopicFromFileFolderBuilderTest class >> eyeballTest [ + "This should be able to open the HelpBrowser on the test data" +