Organized
This commit is contained in:
parent
409d3f26e2
commit
ab5072c1c5
|
@ -1 +1 @@
|
||||||
config.rb
|
app/config.rb
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -7,3 +7,6 @@ gem 'pygments.rb'
|
||||||
|
|
||||||
gem 'haml'
|
gem 'haml'
|
||||||
gem 'sass'
|
gem 'sass'
|
||||||
|
|
||||||
|
gem 'unicorn'
|
||||||
|
gem 'shotgun'
|
||||||
|
|
10
Gemfile.lock
10
Gemfile.lock
|
@ -3,6 +3,7 @@ GEM
|
||||||
specs:
|
specs:
|
||||||
haml (4.0.3)
|
haml (4.0.3)
|
||||||
tilt
|
tilt
|
||||||
|
kgio (2.8.0)
|
||||||
pg (0.15.1)
|
pg (0.15.1)
|
||||||
posix-spawn (0.3.6)
|
posix-spawn (0.3.6)
|
||||||
pygments.rb (0.5.1)
|
pygments.rb (0.5.1)
|
||||||
|
@ -11,13 +12,20 @@ GEM
|
||||||
rack (1.5.2)
|
rack (1.5.2)
|
||||||
rack-protection (1.5.0)
|
rack-protection (1.5.0)
|
||||||
rack
|
rack
|
||||||
|
raindrops (0.11.0)
|
||||||
sass (3.2.9)
|
sass (3.2.9)
|
||||||
sequel (4.0.0)
|
sequel (4.0.0)
|
||||||
|
shotgun (0.9)
|
||||||
|
rack (>= 1.0)
|
||||||
sinatra (1.4.3)
|
sinatra (1.4.3)
|
||||||
rack (~> 1.4)
|
rack (~> 1.4)
|
||||||
rack-protection (~> 1.4)
|
rack-protection (~> 1.4)
|
||||||
tilt (~> 1.3, >= 1.3.4)
|
tilt (~> 1.3, >= 1.3.4)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
|
unicorn (4.6.3)
|
||||||
|
kgio (~> 2.6)
|
||||||
|
rack
|
||||||
|
raindrops (~> 0.7)
|
||||||
yajl-ruby (1.1.0)
|
yajl-ruby (1.1.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
@ -29,4 +37,6 @@ DEPENDENCIES
|
||||||
pygments.rb
|
pygments.rb
|
||||||
sass
|
sass
|
||||||
sequel
|
sequel
|
||||||
|
shotgun
|
||||||
sinatra
|
sinatra
|
||||||
|
unicorn
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
DB = Sequel.connect(CONFIG[:database_url])
|
||||||
|
|
||||||
|
DB.create_table(:pastes) do
|
||||||
|
primary_key :id
|
||||||
|
String :handle
|
||||||
|
String :type
|
||||||
|
Text :contents
|
||||||
|
end unless DB.table_exists?(:pastes)
|
|
@ -0,0 +1,20 @@
|
||||||
|
module Paste
|
||||||
|
def get(params)
|
||||||
|
table.where(params).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def add(params)
|
||||||
|
id = table.insert(params)
|
||||||
|
return unless id.is_a?(Integer)
|
||||||
|
|
||||||
|
get(id: id)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def table
|
||||||
|
DB[:pastes]
|
||||||
|
end
|
||||||
|
|
||||||
|
extend self
|
||||||
|
end
|
|
@ -1,32 +0,0 @@
|
||||||
require 'securerandom'
|
|
||||||
require 'bundler/setup'
|
|
||||||
require 'sinatra'
|
|
||||||
require 'sequel'
|
|
||||||
require 'haml'
|
|
||||||
|
|
||||||
require File.expand_path('../config', __FILE__)
|
|
||||||
|
|
||||||
DB = Sequel.connect(CONFIG[:database_url])
|
|
||||||
DB.create_table :pastes do
|
|
||||||
primary_key :id
|
|
||||||
String :handle
|
|
||||||
String :type
|
|
||||||
Text :contents
|
|
||||||
end unless DB.table_exists? :pastes
|
|
||||||
|
|
||||||
set :public_folder, 'public'
|
|
||||||
|
|
||||||
get '/' do
|
|
||||||
haml :form, layout: :default
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/' do
|
|
||||||
id = DB[:pastes].insert(handle: SecureRandom.hex, contents: params[:contents])
|
|
||||||
record = DB[:pastes].where(id: id).first
|
|
||||||
redirect "/#{id}/#{record[:handle]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/:id/:handle' do
|
|
||||||
@record = DB[:pastes].where(id: params[:id], handle: params[:handle]).first
|
|
||||||
haml :show, layout: :default
|
|
||||||
end
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
$:.unshift File.dirname(__FILE__)
|
||||||
|
require 'pastemaster'
|
||||||
|
|
||||||
|
use Rack::ShowExceptions
|
||||||
|
|
||||||
|
run Pastemaster.new
|
|
@ -0,0 +1,28 @@
|
||||||
|
require 'securerandom'
|
||||||
|
|
||||||
|
require 'bundler/setup'
|
||||||
|
require 'sinatra'
|
||||||
|
require 'sequel'
|
||||||
|
require 'haml'
|
||||||
|
|
||||||
|
require 'app/config'
|
||||||
|
require 'app/database'
|
||||||
|
require 'app/paste'
|
||||||
|
|
||||||
|
class Pastemaster < Sinatra::Application
|
||||||
|
set :public_folder, 'public'
|
||||||
|
|
||||||
|
get '/' do
|
||||||
|
haml :form, layout: :default
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/' do
|
||||||
|
record = Paste.add(handle: SecureRandom.hex, contents: params[:contents])
|
||||||
|
redirect record ? "/#{id}/#{record[:handle]}" : ''
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/:id/:handle' do
|
||||||
|
@record = Paste.get(id: params[:id], handle: params[:handle])
|
||||||
|
haml :show, layout: :default
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue