145 lines
4.3 KiB
Smalltalk
145 lines
4.3 KiB
Smalltalk
"
|
|
I model a documentation object for Grafoscopio.
|
|
Documents are stored in a fossil repository and have
|
|
relative paths to it.
|
|
"
|
|
Class {
|
|
#name : #GrafoscopioDocumentation,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'repository',
|
|
'documents',
|
|
'localPlace',
|
|
'name'
|
|
],
|
|
#category : #'Grafoscopio-Utils'
|
|
}
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation class >> updateAllUI [
|
|
"Updates documentation (manual, tutorials) from the official repository for a given documentation."
|
|
| update |
|
|
update := (UIManager default
|
|
confirm: 'Do you wish to update the documentation?'
|
|
label: 'Update documentation').
|
|
update
|
|
ifTrue: [ self updateAll ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> documents [
|
|
^ documents ifNil: [ documents := OrderedCollection new ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> documents: anObject [
|
|
documents := anObject
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> download: fileNameWithRelativePath [
|
|
| fileName relativePathFolders newPath parentFolder |
|
|
fileName := (fileNameWithRelativePath splitOn: $/) last.
|
|
relativePathFolders := (fileNameWithRelativePath splitOn: $/) allButLast.
|
|
newPath := self localPlace path.
|
|
relativePathFolders do: [ :folder | newPath := newPath / folder ].
|
|
parentFolder := newPath asFileReference.
|
|
parentFolder exists ifFalse: [ parentFolder ensureCreateDirectory ].
|
|
GrafoscopioGenUtils
|
|
downloadingFrom: self repository remote asString, '/doc/tip/', fileNameWithRelativePath
|
|
withMessage: 'Downloading ', fileName
|
|
into: parentFolder
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> isFileUpdatedFor: relativeFilePath [
|
|
"I compare if the local and remote copies of a relativeFilePath are updated for the current
|
|
documentation and return true if they are and false in any other case"
|
|
| localFile |
|
|
localFile := self localPlace / relativeFilePath.
|
|
localFile exists
|
|
ifFalse: [ ^ false ]
|
|
ifTrue: [
|
|
^ ExternalApp
|
|
compareHashFor: localFile
|
|
with: (self repository lastHashNumberFor: relativeFilePath) ]
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> listOutdatedDocs [
|
|
"I return the list of all documentent where the local copy and the remote copy doesn't match"
|
|
^ self documents reject: [ :doc | (self isFileUpdatedFor: doc) ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> localPlace [
|
|
^ localPlace ifNil: [
|
|
localPlace := FileLocator workingDirectory asFileReference / 'Grafoscopio' ].
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> localPlace: aFileDirectory [
|
|
localPlace := aFileDirectory.
|
|
self localPlace exists ifFalse: [ self localPlace ensureCreateDirectory ].
|
|
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> name [
|
|
^ name
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> name: anObject [
|
|
name := anObject
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> openNotebookAt: index [
|
|
"I open a notebook included with the documentation, located at a given index (anInteger)"
|
|
| notebookTemp |
|
|
(index between: 1 and: self documents size)
|
|
ifFalse: [ ^ self ]
|
|
ifTrue: [
|
|
notebookTemp := (self localPlace fullName, '/', (self documents at: index)) asFileReference.
|
|
notebookTemp exists
|
|
ifTrue: [GrafoscopioNotebook new openFromFile: notebookTemp]
|
|
ifFalse: [ self updateUI ]]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> repository [
|
|
^ repository
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioDocumentation >> repository: anObject [
|
|
repository := anObject
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> update [
|
|
(self listOutdatedDocs)
|
|
ifEmpty: [
|
|
self inform: 'All documents in the ', self name,' collection are already updated'.
|
|
^ self ]
|
|
ifNotEmpty: [:outdatedDocs |
|
|
outdatedDocs do: [ :eachDoc | self download: eachDoc].
|
|
self inform: 'Updating of ', self name,' documentation finished.' ]
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> updateDocsPlaceUI [
|
|
self current localPlace: (UIManager default chooseDirectory: 'Path to the documentation folder')
|
|
]
|
|
|
|
{ #category : #updating }
|
|
GrafoscopioDocumentation >> updateUI [
|
|
"Updates documentation (manual, tutorials) from the official repository for a given documentation."
|
|
| update |
|
|
update := (UIManager default
|
|
confirm: 'Do you wish to update the ', self name,' documentation?'
|
|
label: 'Update ', self name, ' documentation').
|
|
update ifTrue: [ self update ]
|
|
]
|