Skip to content

Commit

Permalink
Turbolinks examples: multicounter and todo app
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrichau committed Aug 23, 2023
1 parent 76e1f14 commit e06d397
Show file tree
Hide file tree
Showing 45 changed files with 249 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
counter: aValue

counter := aValue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
accessing
counter

^ counter
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
actions
decrease

counter := counter - 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
actions
increase

counter := counter + 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
initialization
initialize

super initialize.
counter := 0
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
rendering
renderContentOn: html

html heading: counter.
html anchor
attributeAt: 'data-turbo-action' put: 'replace';
turbocallback: [ self increase ];
turboCallback: [ self increase ];
with: '++'.
html space.
html anchor
attributeAt: 'data-turbo-action' put: 'replace';
turbocallback: [ self decrease ];
turboCallback: [ self decrease ];
with: '--'.
html space.
html anchor
url: 'javascript:{}';
onClick: ((html jQuery id: #foo) load html:[ :h | h anchor callback: [ ] ]);
with: 'bla'

with: 'bla'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
testing
register
| app |
app := (WAAdmin register: self asApplicationAt: 'turbocounter').
app := (WAAdmin register: self asApplicationAt: '/examples/turbo/multicounter').
app addLibrary: JQDevelopmentLibrary.
"app addLibrary: TurboFileLibrary "
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hooks
children
^ counters

^ counters, { totals }
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
initialization
initialize

super initialize.
counters := (1 to: 5) collect: [ :each | WATurboCounter new addDecoration: WATurboFrame new; yourself ]
counters := (1 to: 5) collect: [ :each | WATurboCounter new addDecoration: WATurboFrame new; yourself ].
totals := (WAPluggablePresenter new block: [ :html |
html heading
level: 1;
with: (counters inject: 0 into:[ :total :c | c counter + total ]) ]) addDecoration: (WATurboFrame newWithId: 'id-total'); yourself
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
initialization
renderContentOn: html

| theValue |
self renderTurboScriptOn: html.
html div id: #foo.
counters
do: [ :each | html render: each ]
separatedBy: [ html horizontalRule ].
html horizontalRule; horizontalRule.
"(html tag:'turbo-frame')
id: 'id-sum';
with:["
html heading
level: 1;
with: (counters inject: 0 into:[ :total :c | c counter + total ]).
html form: [
html submitButton ]" ]"
html render: totals.
html form: [
html textInput
callback: [ :value | theValue := value ].
html submitButton
turboFrameTarget: 'id-total';
turboCallback: [ self setCountersTo: theValue ] ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
initialization
renderTurboScriptOn: html

html script
type: 'module';
"attributeAt: 'data-turbo-eval' put: false;"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions
setCountersTo: aValue

| theValue |
theValue := Integer readFrom: aValue ifFail: [ 0 ].
counters do: [ :each | each counter: theValue ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hooks
states

^ #()
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
updating
updateRoot: aRoot

super updateRoot: aRoot.
"aRoot javascript url: WATurboFileLibrary/ #turboes2017umdJs"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"counters"
"counters",
"totals"
],
"name" : "WATurboMultiCounter",
"type" : "normal"
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
canBeRoot
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialization
register
(WAAdmin register: self asApplicationAt: '/examples/turbo/todo')
exceptionHandler: WADebugErrorHandler;
addLibrary: WAExamplesLibrary
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions
addTodo: aString

| newTodo |
newTodo := WATurboTodoItem newWithDescription: aString in: todos.
newTodo addDecoration: WATurboFrame new.
todos add: newTodo.
^ newTodo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
children

^ self todos
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialization
initialize

super initialize.
todos := OrderedCollection new.
1 to: 10 do: [ :index |
self addTodo: ('Task {1}' format: { index greaseString }) ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rendering
renderAddNewTodoOn: html

| newTodo |
html form
id: 'new-todo-form';
turboStreamCallback: [ :ts |
ts
append: 'todo-list' with: newTodo;
replace: 'new-todo-form' with: [ :r | self renderAddNewTodoOn: r ] ];
with: [
html textInput
id: 'new-todo';
autofocus;
noAutocomplete;
callback: [ :value | newTodo := self addTodo: value ];
placeholder: 'What needs to be done?' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rendering
renderContentOn: html

self renderTurboScriptOn: html.
html section
id: #todoapp;
with: [
self renderHeaderWithAddTodoOn: html.
self renderTodosOn: html ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rendering
renderHeaderWithAddTodoOn: html

html header
id: #header;
with: [
html heading
level: 1;
with: 'todos'.
self renderAddNewTodoOn: html ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
rendering
renderTodosOn: html

html section
id: 'main';
with: [
html checkbox
id: 'toggle-all'.
html label
for: 'toggle-all';
with: 'Mark all as complete'.
html unorderedList
id: 'todo-list';
with: [ self todos do: [ :todoItem | todoItem renderOn: html ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rendering
renderTurboScriptOn: html

html script
type: 'module';
"attributeAt: 'data-turbo-eval' put: false;"
"with:'import hotwiredTurbo from ''https://cdn.skypack.dev/@hotwired/turbo'';'"
with: 'import * as Turbo from ''',(WATurboFileLibrary / #turboes2017esmJs) greaseString,''';'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
todos

^ todos
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rendering
updateRoot: aRoot

super updateRoot: aRoot.
aRoot stylesheet url: WAExamplesLibrary / #todoCss.
aRoot javascript url: JQDeploymentLibrary / #jQueryJs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "WAExampleComponent",
"category" : "Seaside-HotwireTurbo-Examples",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"todos"
],
"name" : "WATurboTodo",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instance creation
newWithDescription: aString in: aCollection
^ self new initializeWithDescription: aString in: aCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description: anObject
description := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ description
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
done: anObject
done := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
done
^ done
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialization
initializeWithDescription: aString in: aCollection
self initialize.
self done: false.
self description: aString.
editmode := false.
todos := aCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
remove
todos remove: self.
^ self turboframeDecoration id
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
rendering
renderContentOn: html

| id |
html listItem
onDoubleClick: (html javascript turboCallback: [ self turboCall: (WATurboTodoItemEditor on: self) ] frameId: self turboframeDecoration id);
id: (id := html nextId);
with: [
html div
class: 'view';
with:[
html form
turboStreamCallback:[ :ts | ts update: id with: self ];
with:[
html checkbox
class: 'toggle';
callback: [ :value | self done: value ];
onChange: (html javascript: 'this.form.requestSubmit()');
value: done ].
html label: description.
html form: [
html button
class: 'destroy';
turboStreamCallback: [ :ts | ts remove: self remove ] ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"commentStamp" : "",
"super" : "WAComponent",
"category" : "Seaside-HotwireTurbo-Examples",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"todos",
"description",
"done",
"editmode"
],
"name" : "WATurboTodoItem",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
instance creation
on: aWATodoItem

^ self basicNew initializeOn: aWATodoItem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialization
initializeOn: aWATodoItem

self initialize.
todoItem := aWATodoItem
Loading

0 comments on commit e06d397

Please sign in to comment.