From f2b41dd5460baa0dc1d7cc224e3b01b8f49c03f3 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 20 Mar 2024 11:03:46 -0500 Subject: [PATCH] Associating PubPubContents to their respective files. --- src/MiniDocs/PubPubContent.class.st | 13 +++++++- src/MiniDocs/PubPubWork.class.st | 49 ++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/MiniDocs/PubPubContent.class.st b/src/MiniDocs/PubPubContent.class.st index 2e66f56..19d73d6 100644 --- a/src/MiniDocs/PubPubContent.class.st +++ b/src/MiniDocs/PubPubContent.class.st @@ -6,7 +6,8 @@ Class { 'language', 'url', 'thumbnail', - 'work' + 'work', + 'contents' ], #category : #'MiniDocs-Model' } @@ -40,6 +41,16 @@ PubPubContent >> asMarkdeepFrontPageElement [ ^ response contents ] +{ #category : #accessing } +PubPubContent >> contents: anObject [ + contents := anObject +] + +{ #category : #accessing } +PubPubContent >> fileName [ + ^ self shortName,'--', self id, '.md' +] + { #category : #accessing } PubPubContent >> fromXML: aXMLElement [ | image anchor| diff --git a/src/MiniDocs/PubPubWork.class.st b/src/MiniDocs/PubPubWork.class.st index fcc95d6..a26ccb0 100644 --- a/src/MiniDocs/PubPubWork.class.st +++ b/src/MiniDocs/PubPubWork.class.st @@ -35,6 +35,12 @@ PubPubWork >> address: anUrl [ address := anUrl ] +{ #category : #accessing } +PubPubWork >> bookishFolder [ + ^ { 'en' -> 'book'. + 'es' -> 'libro'} asDictionary +] + { #category : #accessing } PubPubWork >> currentLanguage [ ^ currentLanguage @@ -59,16 +65,17 @@ PubPubWork >> defaultTitle [ { #category : #accessing } PubPubWork >> downloadContents [ | workingDirectory | - workingDirectory := self folder / self currentLanguage / 'book'. - self tableOfContentsDictionary keysAndValuesDo: [ :name :chapterAddress | |currentFileName| - currentFileName := name, '--', chapterAddress, '.md'. - (workingDirectory / currentFileName) asFileReference ensureDelete. - (workingDirectory / 'markdown') asFileReference ensureDelete. - ZnClient new - get: self address, 'pub/', chapterAddress, '/download/markdown'; - downloadTo: workingDirectory . - workingDirectory / 'markdown' renameTo: currentFileName - ]. + workingDirectory := self workingDirectory. + self tableOfContentsDictionary + keysAndValuesDo: [ :name :chapterAddress | + | currentFileName | + currentFileName := name , '--' , chapterAddress , '.md'. + (workingDirectory / currentFileName) asFileReference ensureDelete. + (workingDirectory / 'markdown') asFileReference ensureDelete. + ZnClient new + get: self address , 'pub/' , chapterAddress , '/download/markdown'; + downloadTo: workingDirectory. + workingDirectory / 'markdown' renameTo: currentFileName ]. ^ workingDirectory ] @@ -165,8 +172,12 @@ PubPubWork >> markdownFiles [ PubPubWork >> populateContents [ self tableOfContents isEmptyOrNil ifTrue: [ self populateTableOfContents ]. - ^ self tableOfContents - + self workingDirectory children ifEmpty: [self downloadContents]. + self tableOfContents do: [:pubPubContent | | contentFile| + contentFile := self workingDirectory / pubPubContent fileName. + contentFile exists + ifTrue: [ pubPubContent contents: (Markdown new fromFile: contentFile) ] + ] ] { #category : #accessing } @@ -213,3 +224,17 @@ PubPubWork >> tableOfContentsDictionary [ PubPubWork >> titles [ ^ titles ifNil: [titles := OrderedDictionary new] ] + +{ #category : #accessing } +PubPubWork >> viewContentsFor: aView [ + + ^ aView list + title: 'Contents'; + priority: 10; + items: [ self tableOfContents ] +] + +{ #category : #accessing } +PubPubWork >> workingDirectory [ + ^ self folder / self currentLanguage / (self bookishFolder at: self currentLanguage) +]