This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-07-27 21:12:00 -05:00
commit e759f93afb

View File

@ -8,7 +8,8 @@ Class {
'shortName', 'shortName',
'template', 'template',
'templateData', 'templateData',
'namespace' 'namespace',
'bodyTag'
], ],
#category : #Brea #category : #Brea
} }
@ -22,14 +23,40 @@ BreaWikiPage >> bodyContentsAsHTML [
^ Pandoc markdownToHtml: sourcePage ^ Pandoc markdownToHtml: sourcePage
] ]
{ #category : #accessing }
BreaWikiPage >> bodyTag [
^ bodyTag
]
{ #category : #accessing }
BreaWikiPage >> bodyTag: aString [
"I represent the Mustache Template tag used to denote the body part of a page.
While the metadata is self describing via YAML metadata blocks in Markddown, so
they map where ever they are needed in a template, the Markdown file that will be converted
in HTML via a template doesn't know which part should occupy once the conversion is done.
I provide such knowledge. So if a page template puts the body content under the mustache tag
{{content}}, I should use bodyTag: 'content'.
bodyTag: is template dependant."
bodyTag := aString
]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> exportAsHTML [ BreaWikiPage >> exportAsHTML [
| htmlContents templateFile | | htmlContents allActions semaphore result |
self shortName ifNil: [ ^ self ]. self shortName ifNil: [ ^ self ].
self template ifNil: [ ^ self ]. self template ifNil: [ ^ self ].
templateFile := self namespace / self template. self bodyTag ifNil: [ ^ self ].
htmlContents := (MustacheTemplate on: templateFile contents) value: self templateData. allActions := TKTFuture all: {
"htmlContents." [ self populateMetadata ] future.
[ self populateBodyAs: self bodyTag ] future.
}.
semaphore := Semaphore new.
allActions onSuccessDo: [ :values |
result := values last.
semaphore signal.
].
semaphore wait.
htmlContents := (MustacheTemplate on: result templateFile contents) value: result templateData.
^ MarkupFile exportAsFileOn: self namespace / (self shortName, '.html' ) containing: htmlContents ^ MarkupFile exportAsFileOn: self namespace / (self shortName, '.html' ) containing: htmlContents
] ]