forked from mrdoob/glsl-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
75 lines (52 loc) · 1.11 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'rubygems'
require 'sinatra'
require 'mongo'
require 'json'
require 'erb'
require 'cloudinary'
$: << './server'
require 'model'
require 'pp'
configure do
set :public_folder, 'server/assets'
GALLERY=ERB.new(File.read('server/assets/gallery.html'))
$glsl=GlslDatabase.new
EFFECTS_PER_PAGE=50
end
get '/' do
if(params[:page])
page=params[:page].to_i
else
page=0
end
ef=$glsl.get_page(page, EFFECTS_PER_PAGE)
GALLERY.result(ef.bind)
end
get '/e' do
send_file 'static/index.html'
end
get %r{/item/(\d+)([/.](\d+))?} do
code_id=params[:captures][0].to_i
if params[:captures][1]
version_id=params[:captures][2].to_i
else
version_id=nil
end
$glsl.get_code_json(code_id, version_id)
end
post '/e' do
body=request.body.read
$glsl.save_effect(body)
end
get '/diff' do
send_file 'server/assets/diff.html'
end
# redirects
get '/new' do
redirect '/e', 301
end
get %r{^/(\d+)(/(\d+))?$} do
url="/e##{params[:captures][0]}"
url+=".#{params[:captures][2]}" if params[:captures][1]
redirect url, 301
end