Created
December 4, 2010 17:59
-
-
Save vito/728358 to your computer and use it in GitHub Desktop.
basic atomo blog
This file contains hidden or 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
website: Blog: { | |
"/" -> page: { | |
Post all (sort-by: { a b | a created-at < b created-at }) | |
each: { p | join: p pretty } | |
} | |
"/post" -> page: { | |
(Post get: (parameter: "id")) match: { | |
@(ok: p) -> super join: p pretty | |
@none -> not-found | |
} | |
} | |
"/write" -> page: { | |
not-found unless: logged-in? | |
form: { | |
p: { input: "title" } | |
p: { textarea rows: "15" cols: "100" name: "body" } | |
p: { submit } | |
} action: { | |
@(id: id rev: _) = | |
(Post new: (parameter: "title") | |
body: (parameter: "body") | |
by: session user) save | |
redirect-to: ("/post?id=" .. id) | |
} | |
} | |
"/edit" -> page: { | |
not-found unless: logged-in? | |
find = Post get: (parameter: "id") | |
{ warning: "post not found"; redirect-to: "/" } call | |
when: (find == @none) | |
@(ok: post) = find | |
form: { | |
p: { input type: "text" name: "title" value: post title } | |
p: { textarea: post body rows: "15" cols: "100" name: "body" } | |
p: { submit } | |
} action: { | |
post do: | |
{ title = parameter: "title" | |
body = parameter: "body" | |
save | |
} | |
redirect-to: ("/post?id=" .. post id) | |
} | |
} | |
"/delete" -> page: { | |
not-found unless: logged-in? | |
(Post get: (parameter: "id")) match: { | |
@(ok: p) -> | |
super continue: { url | | |
h1: "are you sure?" | |
ul: { | |
li: { a: "yes, zap it!" href: url } | |
li: { a: "get me out of here!" href: "/" } | |
} | |
} to: { | |
p delete! | |
notify: "post deleted" | |
redirect-to: "/" | |
} | |
@none -> | |
{ warning: "post not found" | |
redirect-to: "/" | |
} call | |
} | |
} | |
"/log-in" -> { | |
{ prompt: { url | | |
join: page: { | |
h2: "log in" | |
form.log-in: { | |
input: "name" | |
password: "password" | |
submit: "log in" | |
} action: url | |
method: "post" | |
} | |
} | |
} until: { | |
name = parameter: "name" | |
pass = parameter: "password" | |
(User get: name by: "name") match: { | |
@none -> warning: "unknown username" | |
@(ok: u) -> | |
if: (u password == pass md5) | |
then: { log-in: u id } | |
else: { warning: "invalid password" } | |
} | |
} | |
notify: "signed in!" | |
redirect-to: "/" | |
} | |
"/log-out" -> { | |
session user match: { | |
"" -> | |
warning: "you aren't logged in!" | |
_ -> | |
log-in: "" | |
} | |
redirect-to: "/" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment