-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalavreado.rb
53 lines (42 loc) · 947 Bytes
/
palavreado.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
# encoding: utf-8
require 'sinatra'
require 'haml'
require 'yaml'
require 'uri'
disable :session
Words = YAML.load_file('words.yml')
helpers do
def word; params[:word]; end
def syllables; @word['syllables']; end
def description; @word['description']; end
def stress?(i); @word['stress'] == i; end
def examples; @word['examples']; end
def last?(i); @word['syllables'].size - 1 == i; end
def random; Words.keys.shuffle.first(8); end
def escape(string); (URI.escape(string)); end
end
get '/' do
redirect to(escape(Words.keys.last))
end
get '/rss' do
params[:word] = Words.keys.last
@word = Words[word]
content_type "application/rss+xml"
haml :feed, layout: false
end
get '/about' do
haml :about
end
get '/random' do
params[:word] = random.first
@word = Words[word]
haml :word
end
get '/:word' do |word|
@word = Words[word]
if @word
haml :word
else
[404, "Palavra não cadastrada"]
end
end