Skip to content

Commit

Permalink
Adds initial classes for RESTful handling and component rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
eMaringolo committed Apr 17, 2024
1 parent f06db6b commit 173bcb8
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
57 changes: 57 additions & 0 deletions repository/Seaside-Stateless-Core/WAByMethodCleanRoutes.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Class {
#name : #WAByMethodCleanRoutes,
#superclass : #WAByMethodRoutes,
#category : #'Seaside-Stateless-Core'
}

{ #category : #private }
WAByMethodCleanRoutes >> buildContainers: aDictionary [
| result |
result := Dictionary new.
aDictionary keysAndValuesDo: [ :method :subroutes |
| methodRoutes |
methodRoutes := result
at: method
ifAbsentPut: [
SortedCollection sortBlock: [ :a :b |
a pathElementCount <= b pathElementCount ] ].
subroutes do: [ :each |
methodRoutes add: (WACleanRouteContainer routes: each) ] ].
^ result
]

{ #category : #private }
WAByMethodCleanRoutes >> mergedRoutesForContext: aRequestContext [
| routes fixed flexibles |
routes := OrderedCollection new.
fixed := self fixedRoutesForContext: aRequestContext.
fixed isNil ifFalse: [
routes add: fixed ].
flexibles := self flexibleRoutesForContext: aRequestContext.
flexibles isNil ifFalse: [
routes addAll: flexibles ].
routes isEmpty
ifTrue: [ ^ nil ].
routes size = 1
ifTrue: [ ^ routes first ].
^ WACleanRouteContainer routes: (routes gather: [ :each | each routes ])
]

{ #category : #private }
WAByMethodCleanRoutes >> privateRouteForContext: aRequestContext ifAbsent: aNiladicBlock [
| routeContainer parameters elements |
routeContainer := self mergedRoutesForContext: aRequestContext.
routeContainer isNil
ifTrue: [ ^ aNiladicBlock value ].
parameters := Dictionary new.
elements := aRequestContext consumer peekToEnd.
^ WARouteResult
route: (routeContainer
routeForElements: elements
parameters: parameters
contentType: aRequestContext request contentType
accept: aRequestContext request accept
ifAbsent: [ ^ aNiladicBlock value ])
elements: elements
parameters: parameters
]
14 changes: 14 additions & 0 deletions repository/Seaside-Stateless-Core/WACleanRouteBuilder.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : #WACleanRouteBuilder,
#superclass : #WARouteBuilder,
#category : #'Seaside-Stateless-Core'
}

{ #category : #initialization }
WACleanRouteBuilder class >> initialize [
<script>

configuration := IdentitySet new.
(Pragma allNamed: #configuration in: self superclass)
do: [ :pragma | configuration add: pragma method selector ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #WACleanRouteContainer,
#superclass : #WARouteContainer,
#category : #'Seaside-Stateless-Core'
}
13 changes: 13 additions & 0 deletions repository/Seaside-Stateless-Core/WARestfulCleanHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Class {
#name : #WARestfulCleanHandler,
#superclass : #WARestfulHandler,
#category : #'Seaside-Stateless-Core'
}

{ #category : #private }
WARestfulCleanHandler >> routeForContext: aRequestContext ifAbsent: aNiladicBlock [
^ (WAByMethodCleanRoutes routes: self routes)
routeForContext: aRequestContext
consume: self shouldConsumePath
ifAbsent: aNiladicBlock
]
28 changes: 28 additions & 0 deletions repository/Seaside-Stateless-Core/WAStatelessBuilder.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class {
#name : #WAStatelessBuilder,
#superclass : #WABuilder,
#category : #'Seaside-Stateless-Core'
}

{ #category : #rendering }
WAStatelessBuilder >> render: anObject on: aStream [
"Render anObject and return the contents of the resulting Document as a String.
anObject must understand #renderOn:. Commonly anObject will be a one-argument
block, which will be evaluated with the appropriate renderer."

| context document renderer |
document := self documentClass on: aStream codec: self codec.
document scriptGenerator: self scriptGeneratorClass new.
context := WARenderContext new.
context visitor: (WARenderingGuide client: context visitor).
context document: document.
context
actionUrl: self actionUrl;
resourceUrl: self resourceUrl.
renderer := self rendererClass context: context.
self openDocument: document context: context.
renderer
render: anObject;
flush.
self closeDocument: document
]
40 changes: 40 additions & 0 deletions repository/Seaside-Stateless-Core/WAWebHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Class {
#name : #WAWebHandler,
#superclass : #WARestfulCleanHandler,
#category : #'Seaside-Stateless-Core'
}

{ #category : #accessing }
WAWebHandler >> createCanvasBuilder [
^ (WAStatelessBuilder on: WAHtmlCanvas)
rootClass: WAHtmlRoot;
documentClass: WAHtmlDocument;
yourself
]

{ #category : #accessing }
WAWebHandler >> renderComponent: component [

^ self renderComponent: component full: false
]

{ #category : #accessing }
WAWebHandler >> renderComponent: component full: aBoolean [

^ self createCanvasBuilder
fullDocument: aBoolean;
rootBlock: [ :root | component updateRoot: root ];
render: [ :html | html render: component ]
]

{ #category : #accessing }
WAWebHandler >> renderFragment: component [

^ self renderComponent: component full: false
]

{ #category : #accessing }
WAWebHandler >> renderPage: component [

^self renderComponent: component full: true
]
1 change: 1 addition & 0 deletions repository/Seaside-Stateless-Core/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Seaside-Stateless-Core' }

0 comments on commit 173bcb8

Please sign in to comment.