forked from BRUGcz/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
71 lines (58 loc) · 1.68 KB
/
app.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
require "sinatra/base"
require "erubis"
module Brug
class Application < Sinatra::Base
set :public, File.expand_path('../public', __FILE__)
set :views, File.expand_path('../views', __FILE__)
set :environment, "production"
enable :sessions
# ToDo: well, this is not pretty
before do
if params[:lang]
session[:lang] = params[:lang]
end
unless session[:lang]
accept = ["cs", "en"]
lang = env["HTTP_ACCEPT_LANGUAGE"]
lang = "cs" unless lang
lang.split(",").each do |l|
if l.include?(";")
l = l.split(";")[0]
end
if accept.include?(l)
session[:lang] = l
break
else
accept.each do |a|
if l == a or l.match(/^#{a}-/)
session[:lang] = a
break
end
end
break if session[:lang]
end
end
end
end
get '/' do
@menu = "about"
erubis "about.#{session[:lang]}".to_sym, :layout => "layout.#{session[:lang]}".to_sym
end
get '/activities' do
@menu = "activities"
erubis "activities.#{session[:lang]}".to_sym, :layout => "layout.#{session[:lang]}".to_sym
end
get '/projects' do
@menu = "projects"
erubis "projects.#{session[:lang]}".to_sym, :layout => "layout.#{session[:lang]}".to_sym
end
get '/members' do
@menu = "members"
erubis "members.#{session[:lang]}".to_sym, :layout => "layout.#{session[:lang]}".to_sym
end
get '/blog' do
@menu = "blog"
erubis "blog.#{session[:lang]}".to_sym, :layout => "layout.#{session[:lang]}".to_sym
end
end
end