-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
53 lines (43 loc) · 882 Bytes
/
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
require 'sinatra'
require 'sass'
require 'slim'
require 'words_counted'
configure :production do
require 'newrelic_rpm'
end
get '/' do
slim :index
end
post '/' do
options = {}
unless params[:regexp].empty?
if regexp = Regexp.try_convert(params[:filter])
options.merge!({ regexp: regexp })
end
end
unless params[:filter].empty?
if regexp_filter = Regexp.try_convert(params[:filter])
options.merge!({ exclude: regexp_filter })
else
options.merge!({ exclude: params[:filter] })
end
end
@counter = WordsCounted.count(params[:text], options) unless params[:text].empty?
slim :index
end
get '/styles.css' do
scss :styles
end
helpers do
def id_from(string)
string.downcase.gsub(/\s/, '-')
end
def class_for_index(i)
if i > 3
'hidden'
end
end
def collapsed?(array)
array.size > 3
end
end