Browse Source

Initial commit

master
jimi 13 years ago
commit
46969ff940
  1. 1
      .gitignore
  2. 29
      main.rb
  3. 8
      views/index.haml
  4. 9
      views/layout.haml
  5. 2
      views/task.haml

1
.gitignore

@ -0,0 +1 @@
*.db

29
main.rb

@ -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

8
views/index.haml

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

9
views/layout.haml

@ -0,0 +1,9 @@
!!!
%html
%head
%meta(charset="utf-8")
%title Just Do It
%link(rel="stylesheet" href="/styles.css")
%body
%h1 Just Do It
= yield

2
views/task.haml

@ -0,0 +1,2 @@
%h2 My Tasks
= @task