diff --git a/repository/Brea/BreaWikiPage.class.st b/repository/Brea/BreaWikiPage.class.st new file mode 100644 index 0000000..dfd8aee --- /dev/null +++ b/repository/Brea/BreaWikiPage.class.st @@ -0,0 +1,103 @@ +" +I model a wiki page of a Brea site. +" +Class { + #name : #BreaWikiPage, + #superclass : #Object, + #instVars : [ + 'shortName', + 'template', + 'templateData', + 'namespace' + ], + #category : #Brea +} + +{ #category : #operation } +BreaWikiPage >> bodyContentsAsHTML [ + | sourcePage | + self markdownFile ifNil: [ ^ self ]. + sourcePage := FileLocator temp / 'wikiPage.md'. + MarkupFile exportAsFileOn: sourcePage containing: self markdownFile contents. + ^ Pandoc markdownToHtml: sourcePage +] + +{ #category : #operation } +BreaWikiPage >> markdownFile [ + | localFile | + self namespace ifNil: [ ^ self ]. + self shortName ifNil: [ ^ self ]. + localFile := self namespace / (self shortName, '.md'). + localFile exists ifFalse: [ ^ self ]. + ^ Markdown fromFile: localFile +] + +{ #category : #accessing } +BreaWikiPage >> namespace [ + ^ namespace +] + +{ #category : #accessing } +BreaWikiPage >> namespace: folderFileReference [ + namespace := folderFileReference +] + +{ #category : #'as yet unclassified' } +BreaWikiPage >> populateBodyAs2: key [ + + [self bodyContentsAsHTML] future + andThen: [:result | self templateData at: key put: result contents] +] + +{ #category : #'as yet unclassified' } +BreaWikiPage >> populateBodyAs: key [ + | allActions result | + allActions := TKTFuture all: { + [self bodyContentsAsHTML] future. + [ self templateData at: key put: FileLocator temp / 'wikiPage.html' contents ] + }. + allActions onSuccessDo: [ :values | + result := values ]. + ^ result. + + +] + +{ #category : #operation } +BreaWikiPage >> populateMetadata [ + self markdownFile metadata keysAndValuesDo: [ :key :value | + self templateData at: key put: value + ]. + ^ templateData +] + +{ #category : #accessing } +BreaWikiPage >> shortName [ + ^ shortName +] + +{ #category : #accessing } +BreaWikiPage >> shortName: aString [ + shortName := aString +] + +{ #category : #accessing } +BreaWikiPage >> template [ + ^ template +] + +{ #category : #accessing } +BreaWikiPage >> template: mustacheFileName [ + "Usually templates and their pages are located in the same folder." + template := mustacheFileName +] + +{ #category : #accessing } +BreaWikiPage >> templateData [ + ^ templateData ifNil: [ templateData := Dictionary new ] +] + +{ #category : #accessing } +BreaWikiPage >> templateData: aDictionary [ + templateData := aDictionary +]