Skip to content

Commit

Permalink
Merge pull request #8 from sebastianconcept/7-Improve-namedPartial-co…
Browse files Browse the repository at this point in the history
…nvention-for-yield-aNamedPartialToYield-on-aContext-

7 improve named partial convention for yield a named partial to yield on a context
  • Loading branch information
sebastianconcept authored Jan 22, 2024
2 parents 0ed0402 + 82204a7 commit c853361
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Jan 21, 2024
===================================
- Adjusted `STT yield:on:` to allow rendering cases like this one `<st= STT yield: 'shared/alerts.html' on: self alerts>` where `shared/alerts.html` has alerts deeper in the partials sent in the rendering context.

Jan 8, 2024
===================================
- Added `README.md` and how-to guides: one to test it with `Teapot` and another one using it to make an `htmx` based Counter app.
34 changes: 26 additions & 8 deletions STTemplate/STT.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ Class {
#category : #'STTemplate-Core'
}

{ #category : #public }
STT class >> getTemplateFrom: aNamedPartialToYield in: partialsDictionaryish [

| parts selector reminder missing |
parts := aNamedPartialToYield substrings: '/'.
missing := [
STTError signal:
('Partial missing at: {1}' format:
{ aNamedPartialToYield asString }) ].
parts size > 1 ifTrue: [
selector := parts first.
reminder := '/' join: parts allButFirst.
^ self
getTemplateFrom: reminder
in: (partialsDictionaryish at: selector ifAbsent: missing) ].

^ partialsDictionaryish at: parts first ifAbsent: missing
]

{ #category : #public }
STT class >> yield: aNamedPartialToYield [

Expand All @@ -22,16 +41,15 @@ STT class >> yield: aNamedPartialToYield [
{ #category : #public }
STT class >> yield: aNamedPartialToYield on: aContext [

| renderingContext partial outStream result |
| renderingContext template outStream result |
renderingContext := STTCurrentRenderingContext value.
partial := renderingContext partials
at: aNamedPartialToYield
ifAbsent: [
STTError signal:
('Partial missing: {1}' format:
{ aNamedPartialToYield asString }) ].
template := self
getTemplateFrom: aNamedPartialToYield
in: renderingContext partials.
outStream := STTCurrentRenderingStream value.
result := partial renderOn: aContext partials: renderingContext partials.
result := template
renderOn: aContext
partials: renderingContext partials.
outStream nextPutAll: result
]

Expand Down
1 change: 1 addition & 0 deletions STTemplate/STTemplate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ STTemplate >> renderOn: anObject partial: partial [
The STTCurrentRenderingContext dynamic variable and STTCurrentRenderingContext gives them
access to complete its rendering process."

self deprecated: 'not used'.
^ self
renderOn: anObject
partials: { (#_yield -> partial) } asDictionary
Expand Down

0 comments on commit c853361

Please sign in to comment.