Browse Source

Continue progress of task list

- add routes for managing tasks
  - move task listing to partial
  - add css styling
master
jimi 13 years ago
parent
commit
04f5413d76
  1. 16
      main.rb
  2. 36
      public/styles.css
  3. 5
      views/index.haml
  4. 13
      views/task.haml

16
main.rb

@ -19,11 +19,23 @@ get '/' do
end
post '/' do
Task.create name: params[:task]
Task.create params[:task]
redirect '/'
end
delete '/task/:id' do
Task.get(params[:id]).destroy
redirect '/'
end
put '/task/:id' do
task = Task.get params[:id]
task.completed_at = task.completed_at.nil? ? Time.now : nil
task.save
redirect '/'
end
get '/:task' do
@task = params[:task].split('-').join(' ').capitalize
haml :task
# haml :task
end

36
public/styles.css

@ -0,0 +1,36 @@
.completed{
text-decoration: line-through;
}
.tasks{
padding:0;
list-style:none;
width:400px;
}
.task{
position:relative;
padding:2px 0 2px 28px;
border-bottom: dotted 1px #ccc;
}
form.update{
position:absolute;
bottom:2px;
left:0;
}
form.update input{
background:white;
color:gray;
padding:0 2px;
border:none;
cursor:pointer;
}
.tasks li.completed form.update input{
color:#47FD6B;
}
form.delete{
display:inline;
}
form.delete input{
background:none;
cursor:pointer;
border:none;
}

5
views/index.haml

@ -1,8 +1,7 @@
%h2 My Tasks
%form{ action: '/', method: "POST" }
%input{ type: "text", name: "task" }
%input{ type: "text", name: "task[name]" }
%input.button{ type: "submit", value: "New Task >>" }
%h2 My Tasks
%ul.tasks
- @tasks.each do |task|
%li.task= task.name
= render(:haml, :task, locals: { task: task })

13
views/task.haml

@ -1,2 +1,11 @@
%h2 My Tasks
= @task
%li[task]{ class: (task.completed_at.nil? ? "" : "completed") }
= task.name
%form.update(action="/task/#{task.id}" method="POST")
%input{ type: 'hidden', name: '_method', value: 'PUT' }
-if task.completed_at.nil?
%input{type: 'submit', value: '−', title: 'Complete Task'}
-else
%input{type: 'submit', value: '✓', title: 'Uncomplete Task'}
%form.delete(action="/task/#{task.id}" method="POST")
%input(type="hidden" name="_method" value="DELETE")
%input(type="submit" value="✗" title="Delete Task")