forked from tkrk10/tkrk10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.rb
157 lines (122 loc) · 3.31 KB
/
routes.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require 'rubygems'
require 'bundler'
Bundler.require
set :public_folder, File.dirname(__FILE__) + '/static'
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml').to_s]
before do
I18n.locale = request.path_info =~ %r{^/en} ? :en : :ja
end
get '/' do
@sessions = TimetableSession.third_day
erb :index
end
get '/en' do
erb :"en/index"
end
get '/en/community' do
@communities = Dir[File.join(File.dirname(__FILE__), 'communities/*')].map {|f| Community.new(YAML.load_file(f)) }
erb :"en/community"
end
get '/en/timetable' do
@sessions = TimetableSession.all
@third_day_sessions = TimetableSession.third_day
erb :timetable
end
get '/program.html' do
redirect to("/timetable")
end
get '/register.html' do
erb :under_construction
end
get '/sponsor.html' do
erb :sponsor
end
get '/community' do
@communities = Dir[File.join(File.dirname(__FILE__), 'communities/*')].map {|f| Community.new(YAML.load_file(f)) }
erb :community
end
get '/timetable' do
@sessions = TimetableSession.all
@third_day_sessions = TimetableSession.third_day
erb :timetable
end
get '/speakers/:id' do
@speaker = Speaker.find(params[:id])
erb :speaker_detail
end
get '/workshops/p4d' do
erb :'workshops/p4d'
end
get '/workshops/toruby' do
erb :'workshops/toruby'
end
get '/workshops/sukusuku' do
erb :'workshops/sukusuku'
end
get '/kurorubykaigi' do
erb :kurorubykaigi
end
get '/jimotorubykaigi' do
erb :jimotorubykaigi
end
get '/favicon.ico' do
File.read(File.join('static', 'img', 'favicon.ico'))
end
helpers do
def t(*args)
I18n.t(*args)
end
end
class Community
attr_reader :name, :id
def initialize(args)
@name = args["name"]
@description = args["description"]
@description_en = args["description_en"]
@id = @name.gsub(/[^a-z]/i, '')
end
def description
I18n.locale == :en && @description_en || @description
end
end
class TimetableSession
attr_reader :time, :speaker_id, :workshop_id, :workshop_sessions, :invited, :video, :link
def self.all
@sessions ||= YAML.load_file(File.join(File.dirname(__FILE__), "sessions.yml")).map {|a| a.map {|h| TimetableSession.new(h)}}
end
def self.third_day
YAML.load_file(File.join(File.dirname(__FILE__), "3rd_day_sessions.yml")).map {|a| a.map {|h| TimetableSession.new(h)}}
end
def initialize(args)
%w[time title title_en speaker_id workshop_id workshop_name workshop_title workshop_title_en workshop_name_en workshop_sessions invited video link].each do |s|
instance_variable_set("@#{s}", args[s])
end
end
def title
I18n.locale == :en && @title_en || @title || speaker.title
end
def workshop_name
I18n.locale == :en && @workshop_name_en || @workshop_name
end
def workshop_title
I18n.locale == :en && @workshop_title_en || @workshop_title
end
def speaker
@speaker = Speaker.find(@speaker_id) unless defined?(@speaker) || !@speaker_id
@speaker
end
end
class Speaker
def self.find(id)
new(YAML.load_file(File.join(File.dirname(__FILE__), "speakers/#{id}.yml")))
end
attr_reader :name, :twitter, :url, :org, :desc, :comment
def initialize(args)
%w[name twitter url org title title_en desc comment].each do |s|
instance_variable_set("@#{s}", args[s.to_sym])
end
end
def title
I18n.locale == :en && @title_en || @title
end
end