Skip to content

Instantly share code, notes, and snippets.

@vito
Created December 4, 2010 17:59
Show Gist options
  • Save vito/728358 to your computer and use it in GitHub Desktop.
Save vito/728358 to your computer and use it in GitHub Desktop.
basic atomo blog
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