Splitting Mustache templates supporting a common pattern.
This commit is contained in:
parent
e759f93afb
commit
8900a33b1b
@ -9,7 +9,8 @@ Class {
|
|||||||
'template',
|
'template',
|
||||||
'templateData',
|
'templateData',
|
||||||
'namespace',
|
'namespace',
|
||||||
'bodyTag'
|
'bodyTag',
|
||||||
|
'splitters'
|
||||||
],
|
],
|
||||||
#category : #Brea
|
#category : #Brea
|
||||||
}
|
}
|
||||||
@ -48,6 +49,7 @@ BreaWikiPage >> exportAsHTML [
|
|||||||
self bodyTag ifNil: [ ^ self ].
|
self bodyTag ifNil: [ ^ self ].
|
||||||
allActions := TKTFuture all: {
|
allActions := TKTFuture all: {
|
||||||
[ self populateMetadata ] future.
|
[ self populateMetadata ] future.
|
||||||
|
[ self split ] future.
|
||||||
[ self populateBodyAs: self bodyTag ] future.
|
[ self populateBodyAs: self bodyTag ] future.
|
||||||
}.
|
}.
|
||||||
semaphore := Semaphore new.
|
semaphore := Semaphore new.
|
||||||
@ -120,6 +122,41 @@ BreaWikiPage >> shortName: aString [
|
|||||||
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 }
|
{ #category : #accessing }
|
||||||
BreaWikiPage >> template [
|
BreaWikiPage >> template [
|
||||||
^ template
|
^ template
|
||||||
|
Loading…
Reference in New Issue
Block a user