-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds initial classes for RESTful handling and component rendering
- Loading branch information
1 parent
f06db6b
commit 173bcb8
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
repository/Seaside-Stateless-Core/WAByMethodCleanRoutes.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
repository/Seaside-Stateless-Core/WACleanRouteBuilder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
] |
5 changes: 5 additions & 0 deletions
5
repository/Seaside-Stateless-Core/WACleanRouteContainer.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
repository/Seaside-Stateless-Core/WARestfulCleanHandler.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
repository/Seaside-Stateless-Core/WAStatelessBuilder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Seaside-Stateless-Core' } |