Splitting Mustache templates supporting a common pattern.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-08-01 18:49:28 -05:00
parent e759f93afb
commit 8900a33b1b
1 changed files with 38 additions and 1 deletions

View File

@ -9,7 +9,8 @@ Class {
'template',
'templateData',
'namespace',
'bodyTag'
'bodyTag',
'splitters'
],
#category : #Brea
}
@ -48,6 +49,7 @@ BreaWikiPage >> exportAsHTML [
self bodyTag ifNil: [ ^ self ].
allActions := TKTFuture all: {
[ self populateMetadata ] future.
[ self split ] future.
[ self populateBodyAs: self bodyTag ] future.
}.
semaphore := Semaphore new.
@ -120,6 +122,41 @@ BreaWikiPage >> shortName: aString [
shortName := aString
]
{ #category : #'as yet unclassified' }
BreaWikiPage >> split [
self splitters keysAndValuesDo: [ :key :value | self split: key with: value ].
]
{ #category : #'as yet unclassified' }
BreaWikiPage >> split: key with: subkey [
"I split a comma separated collection of subkeys stored in the 'key' field and name each one as 'subkey'
to put it indiviudally in a Mustache template."
| allSubkeys cleaned data |
allSubkeys := (self populateMetadata at: key) splitOn: ','.
cleaned := allSubkeys collect: [ :item | item withBlanksCondensed ].
data := OrderedCollection new.
cleaned do: [ :item |
data add: { subkey -> item } asDictionary ].
self populateMetadata at: key put: data; yourself.
]
{ #category : #'as yet unclassified' }
BreaWikiPage >> splitterAt: key with: subkey [
self splitters at: key put: subkey
]
{ #category : #accessing }
BreaWikiPage >> splitters [
^ splitters ifNil: [ splitters := Dictionary new ]
]
{ #category : #accessing }
BreaWikiPage >> splitters: aDictionary [
"I model the pattern where a Mustache template contains something like
{{# key}} {{value}} {{/ key}} and has data that needs to be split before injecting it in the template."
splitters := aDictionary
]
{ #category : #accessing }
BreaWikiPage >> template [
^ template