-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathapp.rb
106 lines (90 loc) · 2.55 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
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
# frozen_string_literal: true
require 'active_support/inflector'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/output_safety'
require_relative 'app/year_2013/app'
require_relative 'app/year_2014/app'
require_relative 'app/year_2015/app'
require_relative 'app/year_2016/app'
require_relative 'app/year_2017/app'
require_relative 'app/year_2018/app'
require_relative 'app/year_2019/app'
require_relative 'app/year_2020/app'
require_relative 'app/year_2023/app'
require_relative 'app/year_2024/app'
module RubyConf
class App < Sinatra::Application
configure do
set :haml, :format => :html5
set :views, File.join(Dir.pwd, 'views')
set :root, File.join(Dir.pwd)
set :public_folder, File.join(Dir.pwd, 'public')
set :force_ssl, true
end
configure :development do
require 'sinatra/reloader'
end
helpers do
def asset_path(file)
@manifest ||= JSON.parse(File.read("public/assets/manifest.json"))
@manifest[file]
end
end
# Haml file-not-found exception bubbling up from the depths.
error Errno::ENOENT do
halt(404)
end
register Year2013::App
register Year2014::App
register Year2015::App
register Year2016::App
register Year2017::App
register Year2018::App
register Year2019::App
register Year2020::App
register Year2023::App
register Year2024::App
get '/' do
status_code 302
redirect "/#{years.last}"
end
post '/subscribe' do
content_type :json
begin
CreateSend::Subscriber.add(
{:api_key => ENV["CAMPAIGN_MONITOR_API_KEY"]},
ENV["CAMPAIGN_MONITOR_LIST_ID"],
params[:email],
"",
nil, # custom fields
true, # resubscribe
'Unchanged' # consent_to_track
)
rescue CreateSend::BadRequest => br
puts "Bad request error: #{br}"
puts "Error Code: #{br.data.Code}"
puts "Error Message: #{br.data.Message}"
rescue Exception => e
puts "Error: #{e}"
end
{success: true}.to_json
end
get "/:year/stylesheets/main.css" do
content_type 'text/css', :charset => 'utf-8'
scss :"#{params[:year]}/styles/main"
end
private
def current_year
years.last
end
def years
@years ||= configs.map{ |f| f.match(/\d{4}/)[0] }.sort
end
def configs
Dir.glob(File.join(self.settings.root, "app", "year_????", "app.rb"))
end
def self.file_root
Dir.pwd
end
end
end