|
@ -0,0 +1,29 @@ |
|
|
|
|
|
require 'sinatra' |
|
|
|
|
|
require 'data_mapper' |
|
|
|
|
|
require 'haml' |
|
|
|
|
|
|
|
|
|
|
|
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db") |
|
|
|
|
|
|
|
|
|
|
|
class Task |
|
|
|
|
|
include DataMapper::Resource |
|
|
|
|
|
property :id, Serial |
|
|
|
|
|
property :name, String, required: true |
|
|
|
|
|
property :completed_at, DateTime |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
DataMapper.finalize |
|
|
|
|
|
|
|
|
|
|
|
get '/' do |
|
|
|
|
|
@tasks = Task.all |
|
|
|
|
|
haml :index |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
post '/' do |
|
|
|
|
|
Task.create name: params[:task] |
|
|
|
|
|
redirect '/' |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
get '/:task' do |
|
|
|
|
|
@task = params[:task].split('-').join(' ').capitalize |
|
|
|
|
|
haml :task |
|
|
|
|
|
end |