-
Notifications
You must be signed in to change notification settings - Fork 4
/
wordcloud.rb
54 lines (48 loc) · 1.04 KB
/
wordcloud.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
# wordcloud.rb
require 'rubygems'
require 'sinatra'
require 'lib/word_cloud/point.rb'
require 'lib/word_cloud/box.rb'
require 'lib/word_cloud/cloud.rb'
require 'lib/word_cloud/word.rb'
require 'lib/word_cloud/word_cloud.rb'
require 'rmagick'
require 'haml'
require 'sass'
require 'json'
require 'pp'
set :logging, :true
post '/' do
format = params.delete("format")
@debug = params.delete("debug")
wc = WordCloud::WordCloud.new
tags = {}
if params[:text]
params[:text].split(',').each do |item|
tag, weight = item.strip.split(':')
tags[tag] = weight.to_i
end
end
params[:tag].each do |i, tag|
tags[tag] = params[:weight][i].to_i if (tag and tag != "")
end
wc.setTags(tags)
case format
when "jpg"
content_type "image/jpeg"
@image = wc.getImage
@image.format = "JPEG"
@image.to_blob
else
@cloud = wc.getHTML
@wc_dump = wc.pretty_inspect
haml :cloud
end
end
get '/' do
haml :index
end
get '/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8'
sass :stylesheet
end