all: add webapp

This commit is contained in:
2018-05-07 10:11:38 +02:00
parent a72a110cf7
commit 0d1bcaa39f
13 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
starting/stopping
start
Server ifNil: [ Server := self new start ]

View File

@@ -0,0 +1,3 @@
starting/stopping
stop
Server ifNotNil: [ Server stop. Server := nil ]

View File

@@ -0,0 +1,3 @@
actions
allPosts
^ TBBlog current allVisibleBlogPosts

View File

@@ -0,0 +1,6 @@
actions
errorPage
^ String streamContents: [ :s |
self renderPageHeaderOn: s.
s << '<p>Oops, an error occurred</p>'.
self renderPageFooterOn: s ]

View File

@@ -0,0 +1,14 @@
actions
homePage
^ String streamContents: [ :s |
self renderPageHeaderOn: s.
s << '<h1>TinyBlog Web App</h1>'.
s << '<ul>'.
self allPosts withIndexDo: [ :aPost :index |
s << '<li>';
<< ('<a href="/posts/', index asString, '">');
<< aPost title ;
<< '</a></li>' ].
s << '</ul>'.
self renderPageFooterOn: s.
]

View File

@@ -0,0 +1,7 @@
initialization
initialize
super initialize.
teapot := Teapot configure: {
#port -> 8081.
#debugMode -> true
}.

View File

@@ -0,0 +1,10 @@
starting/stopping
pageForPostNumber: aPostNumber
| currentPost |
currentPost := self allPosts at: aPostNumber ifAbsent: [ ^ self errorPage ].
^ String streamContents: [ :s | self renderPageHeaderOn: s.
s << ('<h1>', currentPost title, '</h1>').
s << ('<h3>', currentPost date mmddyyyy, '</h3>').
s << ('<p> Category: ', currentPost category, '</p>').
s << ('<p>', currentPost text, '</p>').
self renderPageFooterOn: s ]

View File

@@ -0,0 +1,3 @@
actions
renderPageFooterOn: aStream
aStream << '</body></html>'

View File

@@ -0,0 +1,3 @@
actions
renderPageHeaderOn: aStream
aStream << '<html><body>'

View File

@@ -0,0 +1,6 @@
starting/stopping
start
teapot
GET: '/' -> [ self homePage ];
GET: '/posts/<id>' -> [ :request | self pageForPostNumber: (request at: #id) asNumber ];
start

View File

@@ -0,0 +1,3 @@
starting/stopping
stop
teapot stop

View File

@@ -0,0 +1,14 @@
{
"category" : "TinyBlog",
"classinstvars" : [
],
"classvars" : [
"Server" ],
"commentStamp" : "",
"instvars" : [
"teapot" ],
"name" : "TBWebApp",
"pools" : [
],
"super" : "Object",
"type" : "normal" }