Skip to content

Commit

Permalink
Cleanup blog.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Jun 11, 2009
1 parent ed9b5e3 commit 957c907
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions examples/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.up
end
User.create :username => 'admin', :password => 'camping'
end

def self.down
drop_table :blog_posts
drop_table :blog_users
Expand Down Expand Up @@ -84,7 +85,7 @@ def get(post_id)

class Edit < R '/post/(\d+)/edit'
def get(post_id)
require_login!
require_login!
@post = Post.find(post_id)
render :edit
end
Expand All @@ -99,24 +100,19 @@ def post(post_id)

class Login
def get
@to = input.to
render :login
end

def post
@user = User.find_by_username_and_password(input.username, input.password)
@to = input.to

if @user
@state.user_id = @user.id
if @to
redirect @to
else
redirect R(Index)
end
redirect R(Index)
else
@info = 'Wrong username or password'
@info = 'Wrong username or password.'
end

render :login
end
end
Expand Down Expand Up @@ -145,7 +141,7 @@ def logged_in?

def require_login!
unless logged_in?
redirect X::Login, :to => @env.REQUEST_URI
redirect Controllers::Login
throw :halt
end
end
Expand All @@ -172,11 +168,11 @@ def layout
if logged_in?
_admin_menu
else
a 'Login', :href => R(Login, :to => @env.REQUEST_URI)
a 'Login', :href => R(Login)
text ' to the adminpanel'
end
text ' &ndash; Powered by '
a 'Camping', :href => 'http://code.whytheluckystiff.net/camping'
a 'Camping', :href => 'http://camping.rubyforge.org/'
end
end
end
Expand All @@ -188,7 +184,7 @@ def index
p do
text 'Could not find any posts. Feel free to '
a 'add one', :href => R(PostNew)
text ' yourself'
text ' yourself. '
end
else
@posts.each do |post|
Expand Down Expand Up @@ -234,7 +230,7 @@ def _admin_menu
end

def _post(post)
h2 post.title
h2 { a post.title, :href => R(PostN, post) }
p.info do
text "Written by <strong>#{post.user.username}</strong> "
text post.updated_at.strftime('%B %M, %Y @ %H:%M ')
Expand All @@ -244,13 +240,9 @@ def _post(post)
end

def _post_menu(post)
text '('
a 'view', :href => R(PostN, post)
if logged_in?
text ', '
a 'edit', :href => R(Edit, post)
a '(edit)', :href => R(Edit, post)
end
text ')'
end

def _form(post, opts)
Expand Down Expand Up @@ -299,14 +291,16 @@ def Blog.create
text-align: center;
}

h1 a { color: #143D55; text-decoration: none }
h1 a:hover { color: #143D55; text-decoration: underline }

h2 {
margin-top: 1em;
font-size: 2em;
color: #287AA9;
}

h1 a { color: #143D55; text-decoration: none }
h1 a:hover { color: #143D55; text-decoration: underline }
h2 a { color: #287AA9; text-decoration: none }
h2 a:hover { color: #287AA9; text-decoration: underline }

#wrapper {
margin: 3em auto;
width: 700px;
Expand Down Expand Up @@ -353,17 +347,18 @@ def Blog.create
}

label {
display: inline-block;
display: block;
width: 100%;
}

input, textarea {
input, textarea {
padding: 5px;
margin-bottom: 1em;
margin-right: 490px;
width: 200px;
}

input.submit {
float: left;
width: auto;
}

Expand Down

0 comments on commit 957c907

Please sign in to comment.