You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
855 B
35 lines
855 B
%w[sinatra dm-core dm-migrations haml sass coffee_script].each{ |lib| require lib }
|
|
DataMapper.setup(:default, File.join("sqlite3://",settings.root,"development.db"))
|
|
|
|
class Robot
|
|
include DataMapper::Resource
|
|
property :id, Serial
|
|
property :top, Integer, default: proc { |m,p| 1+rand(6) }
|
|
property :middle, Integer, default: proc { |m,p| 1+rand(4) }
|
|
property :bottom, Integer, default: proc { |m,p| 1+rand(5) }
|
|
end
|
|
|
|
DataMapper.finalize
|
|
|
|
get ('/styles.css'){ scss :styles }
|
|
|
|
get('/application.js'){ coffee :application }
|
|
|
|
get '/' do
|
|
@robots = Robot.all
|
|
haml :index
|
|
end
|
|
|
|
post '/build/robot' do
|
|
robot = Robot.create
|
|
if request.xhr?
|
|
haml :robot, { layout: false, locals: { robot: robot } }
|
|
else
|
|
redirect to('/')
|
|
end
|
|
end
|
|
|
|
delete '/delete/robot/:id' do
|
|
Robot.get(params[:id]).destroy
|
|
redirect to('/') unless request.xhr?
|
|
end
|