Skip to content

Commit

Permalink
added first version of turbo frame navigation and turbostream rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrichau committed Aug 14, 2023
1 parent fb5d0c0 commit be898ae
Show file tree
Hide file tree
Showing 39 changed files with 157 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-attributes
dataAttributeAt: aString

^ self attributes at: 'data-',aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-attributes
dataAttributeAt: aString ifAbsent: aBlock

^ self attributes at: 'data-',aString ifAbsent: aBlock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-attributes
dataAttributeAt: aString put: aValue

self attributes at: 'data-',aString put: aValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-attributes
dataAttributeAt: aString put: aValue if: aBoolean

aBoolean ifTrue:[ self dataAttributeAt: aString put: aValue ]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ handle: aRequestContext
callbacks at: key ifPresent: [ :callback |
(callback isEnabledFor: aRequestContext)
ifTrue: [ set add: callback ] ] ].
"Process the callbacks in order of priority"
set sorted do: [ :callback |
callback evaluateWithFieldValues:
(fields allAt: callback key) ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*Seaside-HotwireTurbo
turboAction: aString
(#('replace' 'advance') includes: aString) ifFalse: [
self error. ].
self dataAttributeAt: 'turbo-action' put: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Seaside-HotwireTurbo
turboFrameTarget: aString

self dataAttributeAt: 'turbo-frame' put: aString
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*Seaside-HotwireTurbo
turbocallback: aNiladicValuable
aNiladicValuable argumentCount > 0 ifTrue: [ GRInvalidArgumentCount signal: 'Anchors expect a niladic callback.' ].
turboCallback: aNiladicValuable
aNiladicValuable argumentCount > 0 ifTrue: [
GRInvalidArgumentCount signal: 'Anchors expect a niladic callback.' ].
self url addField: (self storeCallback: (WATurboFrameActionCallback on: aNiladicValuable))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*Seaside-HotwireTurbo
turboCallback: aNiladicValuable
aNiladicValuable argumentCount > 0 ifTrue: [
GRInvalidArgumentCount signal: 'Buttons expect a niladic callback.' ].
self name: (self storeCallback: (WATurboFrameActionCallback on: aNiladicValuable))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Seaside-HotwireTurbo
turboStreamCallback: aValuable

self name: (self storeCallback: ((WATurboStreamCallback on: aValuable) context: canvas context))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "WAButtonTag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Seaside-HotwireTurbo
turboframeDecoration

^ self decorations detect:[ :dec | dec class == WATurboFrame ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "WAComponent"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*Seaside-HotwireTurbo
turboCallback: aNiladicValuable
aNiladicValuable argumentCount > 0 ifTrue: [
GRInvalidArgumentCount signal: 'Submit buttons expect a niladic callback.' ].
self name: (self storeCallback: (WATurboFrameActionCallback on: aNiladicValuable))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Seaside-HotwireTurbo
turboFrameTarget: aString

self dataAttributeAt: 'turbo-frame' put: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "WASubmitButtonTag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instance creation
new
^ self basicNew initializeWithId: 'id-', UUIDGenerator default next asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instance creation
newWithId: aString
^ self basicNew initializeWithId: aString
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
id
^ 'id-',id
^ id

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
initialization
initializeWithId: aString
self initialize.
id := aString
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"counter",
"id"
],
"name" : "WATurboFrame",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
instance creation
newWithRenderContext: aRenderContext

^ self new initializeWithContext: aRenderContext; yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
after: anId with: aRenderable
self turboStreamAction: 'after' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
append: anId with: aRenderable
self turboStreamAction: 'append' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
before: anId with: aRenderable
self turboStreamAction: 'before' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
initialize
initializeWithContext: aRenderContext

canvas := WAHtmlCanvas context: aRenderContext
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
prepend: anId with: aRenderable
self turboStreamAction: 'prepend' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
remove: anId
self turboStreamAction: 'remove' target: anId with: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
replace: anId with: aRenderable
self turboStreamAction: 'replace' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
private
turboStreamAction: aName target: anId with: aRenderable
(canvas tag: 'turbo-stream')
attributeAt: 'action' put: aName;
attributeAt: 'target' put: anId;
with: [
aRenderable ifNotNil:[
(canvas tag: 'template')
with:[ aRenderable renderOn: canvas ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
update: anId with: aRenderable
self turboStreamAction: 'update' target: anId with: aRenderable
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "WAObject",
"category" : "Seaside-HotwireTurbo",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"canvas"
],
"name" : "WATurboStreamBuilder",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
context: aContext
renderContext := aContext
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
evaluation
evaluateWithArgument: anObject

self requestContext respond: [ :response |
response
doNotCache;
contentType: 'text/vnd.turbo-stream.html'.
self renderTurboStreamOn: response stream ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
evaluation
renderTurboStreamOn: aStream

| document |
document := (WAHtmlDocument
on: aStream
codec: self requestContext codec)
scriptGenerator: self requestContext handler scriptGeneratorClass new;
yourself.
renderContext document: document during: [
block value: (WATurboStreamBuilder newWithRenderContext: renderContext) ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "WAActionCallback",
"category" : "Seaside-HotwireTurbo",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"renderContext"
],
"name" : "WATurboStreamCallback",
"type" : "normal"
}

0 comments on commit be898ae

Please sign in to comment.