radar / fixedbytm2

Sinatra App for tracking what's been fixed in TextMate 2

This URL has Read+Write access

fixedbytm2 / fixedbytm2.rb
100644 104 lines (86 sloc) 1.842 kb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'rubygems'
require 'sequel'
require 'sinatra'
require 'haml'
# Database configuration and models
require 'models'
 
require 'sinatra/cache'
 
# toggle for the cache functionality.
set :cache_enabled, true
# sets the default extension for cached files
set :cache_page_extension, '.html'
# sets the Cache dir to the root of the /public directory.
set :cache_output_dir, '' # was :cache_dir
 
 
get '/' do
  count = Fix.count
  @fix = Fix.limit(1, Kernel.rand(count)).first
  haml :fix
end
 
get '/about' do
  
end
 
get '/style.css' do
  "body {
background: #4d085b;
font: 14pt Helvetica;
color: white;
}
 
a {
color: #FF5CD4;
text-decoration: underline;
}
 
.fix h1 {
font-size:72pt;
}
 
.yours {
color: #97377d;
padding: 10px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
width: 50%;
background: white;
}
 
.yours textarea {
width: 75%;
height: 4em;
font-size: 24pt;
}
 
#footer {
position: absolute;
bottom: 5px;
right: 5px;
font-size: 75%;
margin-top: 50pt;
}
"
end
 
 
get '/:id' do
  @hide_count = true
  @fix = Fix.filter(:id => params[:id]).first
  if @fix
    cache haml(:fix)
  else
    redirect '/'
  end
end
 
post '/fixes' do
  if fix = Fix.filter(:text => params[:text]).first
    redirect "/#{fix[:id]}"
  else
    fix_id = Fix.insert(:text => params[:text], :votes_count => 1)
    FixesUser.insert(:user_id => current_user, :fix_id => fix_id)
  end
  redirect "/#{fix_id}"
end
 
private
 
  def current_user
    ip = request["REMOTE_ADDR"]
    if u = User.filter(:ip => ip).first
      return u[:id]
    else
      User.insert(:ip => ip)
    end
  end
  
  # Subverts people's attempts to put in nasty things.
  def h(text)
    text.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
  end