Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete Post Feature #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

require 'ostruct'
Blog = OpenStruct.new(
:title => 'a scanty blog',
:author => 'John Doe',
:url_base => 'http://localhost:4567/',
:admin_password => 'changeme',
:admin_cookie_key => 'scanty_admin',
:admin_cookie_value => '51d6d976913ace58',
:title => 'Mind Dump',
:author => 'Alexander Vanadio',
:url_base => 'http://192.168.111.49:3030/',
:admin_password => 'password',
:admin_cookie_key => 'master_007_retsam',
:admin_cookie_value => '51d6Rplk9VNace58',
:disqus_shortname => nil
)
end
Expand All @@ -35,7 +35,7 @@ def admin?
end

def auth
stop [ 401, 'Not authorized' ] unless admin?
halt [ 401, 'Not authorized' ] unless admin?
end
end

Expand All @@ -50,7 +50,7 @@ def auth

get '/past/:year/:month/:day/:slug/' do
post = Post.filter(:slug => params[:slug]).first
stop [ 404, "Page not found" ] unless post
halt [ 404, "Page not found" ] unless post
@title = post.title
erb :post, :locals => { :post => post }
end
Expand Down Expand Up @@ -89,7 +89,12 @@ def auth
end

post '/auth' do
set_cookie(Blog.admin_cookie_key, Blog.admin_cookie_value) if params[:password] == Blog.admin_password
response.set_cookie(Blog.admin_cookie_key, Blog.admin_cookie_value) if params[:password] == Blog.admin_password
redirect '/'
end

get '/logout' do
response.set_cookie(Blog.admin_cookie_key, "")
redirect '/'
end

Expand All @@ -108,18 +113,27 @@ def auth
get '/past/:year/:month/:day/:slug/edit' do
auth
post = Post.filter(:slug => params[:slug]).first
stop [ 404, "Page not found" ] unless post
halt [ 404, "Page not found" ] unless post
erb :edit, :locals => { :post => post, :url => post.url }
end

get '/past/:year/:month/:day/:slug/delete' do
auth
post = Post.filter(:slug => params[:slug]).first
halt [ 404, "Page not found" ] unless post
STDERR.puts "Seems ok?"
post.delete
redirect '/'
end


post '/past/:year/:month/:day/:slug/' do
auth
post = Post.filter(:slug => params[:slug]).first
stop [ 404, "Page not found" ] unless post
halt [ 404, "Page not found" ] unless post
post.title = params[:title]
post.tags = params[:tags]
post.body = params[:body]
post.save
redirect post.url
end

18 changes: 14 additions & 4 deletions public/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ hr {
}

.post .title a {
color: white;
color: #00CCFF;
text-decoration: none;
}

Expand All @@ -174,11 +174,14 @@ hr {
}

#new_post {
position: absolute;
top: 1em;
right: 1em;
}

#login {
}

#logout {
}

/* Post */

.postzoom {
Expand Down Expand Up @@ -214,6 +217,13 @@ hr {
right: 0;
}

.postzoom .delete {
text-align: right;
position: absolute;
top: 30;
right: 0;
}

/* Footer */

#footer {
Expand Down
11 changes: 10 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@
<% end %>

<% if admin? %>
<div id="new_post"><a href="/posts/new"">New post</a></div>
<div id="new_post">
<a href="/posts/new">New post</a>
</div>
<div id="logout">
<a href="/logout">Logout</a>
</div>
<% else %>
<div id="login">
<a href="/auth">Login</a>
</div>
<% end %>
</div>

Expand Down
1 change: 1 addition & 0 deletions views/post.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</div>
<% if admin? %>
<div class="edit"><a href="<%= post.url %>edit">edit</a></div>
<div class="delete"><a href="<%= post.url%>delete">delete</a></div>
<% end %>
</div>

Expand Down