From 6a87402fef4592d58402f3e41936a0839181781a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 10 Jul 2020 17:55:42 -0500 Subject: [PATCH] BreaWikiPage added. --- repository/Brea/BreaWikiPage.class.st | 103 ++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 repository/Brea/BreaWikiPage.class.st 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 +]