forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
86 lines (70 loc) · 2.32 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
require "sinatra/base"
require "sinatra/activerecord"
require "sinatra/flash"
require "sinatra/contrib/all"
require "rack/ssl"
require "json"
require "i18n"
require "will_paginate"
require "will_paginate/active_record"
require "sprockets"
require "sprockets-helpers"
require "securerandom"
require_relative "app/helpers/authentication_helpers"
require_relative "app/repositories/user_repository"
require_relative "config/asset_pipeline"
I18n.load_path += Dir[File.join(File.dirname(__FILE__), "config/locales", "*.yml").to_s]
I18n.config.enforce_available_locales = false
class Stringer < Sinatra::Base
# need to exclude assets for sinatra assetpack, see https://github.com/swanson/stringer/issues/112
use Rack::SSL, exclude: ->(env) { env["PATH_INFO"] =~ %r{^/(js|css|img)} } if ENV["ENFORCE_SSL"] == "true"
register Sinatra::ActiveRecordExtension
register Sinatra::Flash
register Sinatra::Contrib
register AssetPipeline
configure do
set :database_file, "config/database.yml"
set :views, "app/views"
set :public_dir, "app/public"
set :root, File.dirname(__FILE__)
enable :sessions
set :session_secret, ENV["SECRET_TOKEN"] || SecureRandom.hex(32)
enable :logging
enable :method_override
ActiveRecord::Base.include_root_in_json = false
end
helpers do
include Sinatra::AuthenticationHelpers
def render_partial(name, locals = {})
erb "partials/_#{name}".to_sym, layout: false, locals: locals
end
def render_js_template(name)
erb "js/templates/_#{name}.js".to_sym, layout: false
end
def render_js(name, locals = {})
erb "js/#{name}.js".to_sym, layout: false, locals: locals
end
def t(*args)
I18n.t(*args)
end
end
before do
I18n.locale = ENV["LOCALE"].blank? ? :en : ENV["LOCALE"].to_sym
if !authenticated? && needs_authentication?(request.path)
session[:redirect_to] = request.fullpath
redirect "/login"
end
end
get "/" do
if UserRepository.setup_complete?
redirect to("/news")
else
redirect to("/setup/password")
end
end
end
require_relative "app/controllers/stories_controller"
require_relative "app/controllers/first_run_controller"
require_relative "app/controllers/sessions_controller"
require_relative "app/controllers/feeds_controller"
require_relative "app/controllers/debug_controller"