forked from geoloqi/MapAttack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.rb
128 lines (110 loc) · 3.57 KB
/
environment.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
# Encoding.default_internal = 'UTF-8'
#$stderr.reopen $stdout
require "rubygems"
require "bundler"
Bundler.setup
Bundler.require
Bundler.require :development if Sinatra::Base.development?
require 'rack/methodoverride'
class Controller < Sinatra::Base
helpers do
def admins_only
unless session[:is_admin] == true
session[:admin_id] ||= geoloqi.get('account/profile').user_id
@admin = Admin.first_or_create :geoloqi_user_id => session[:admin_id]
end
end
def partial(page, options={})
erb page, options.merge!(:layout => false)
end
def h(val)
Rack::Utils.escape_html val
end
def require_login
geoloqi.get_auth(params[:code], request.url) if params[:code] && !geoloqi.access_token?
redirect geoloqi.authorize_url(request.url) unless geoloqi.access_token?
end
def geoloqi_app
@_geoloqi_app ||= Geoloqi::Session.new :access_token => APPLICATION_ACCESS_TOKEN
end
def onclick_delete(msg='Are you sure?')
return onclick_form(:delete) if msg.nil?
%{ if (confirm('#{msg}')) {
#{onclick_form(:delete)}
};
return false;
}
end
def onclick_put(msg=nil)
return onclick_form(:put) if msg.nil?
%{ if (confirm('#{msg}')) {
#{onclick_form(:put)}
};
return false;
}
end
def onclick_form(meth)
%{ var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var m = document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
m.setAttribute('value', '#{meth.to_s.upcase}');
f.appendChild(m);
f.submit();
return false;
}
end
end
configure :development do
DataMapper::Logger.new STDOUT, :debug
end
configure do
use Rack::MobileDetect
if test?
set :sessions, false
else
set :sessions, true
set :session_secret, 'PUT SECRET HERE'
end
set :root, File.expand_path(File.join(File.dirname(__FILE__)))
set :public, File.join(root, 'public')
set :display_errors, true
set :method_override, true
set :admin_usernames, {}
mime_type :woff, 'application/octet-stream'
Dir.glob(File.join(root, 'models', '**/*.rb')).each { |f| require f }
config_hash = YAML.load_file(File.join(root, 'config.yml'))[environment.to_s]
raise "in config.yml, the \"#{environment.to_s}\" configuration is missing" if config_hash.nil?
GA_ID = config_hash['ga_id']
APPLICATION_ACCESS_TOKEN = config_hash['oauth_token']
AWS_KEY = config_hash['aws_key']
AWS_SECRET = config_hash['aws_secret']
Geoloqi.config :client_id => config_hash['client_id'],
:client_secret => config_hash['client_secret'],
:use_hashie_mash => true
DataMapper.finalize
DataMapper.setup :default, ENV['DATABASE_URL'] || config_hash['database']
# DataMapper.auto_upgrade!
DataMapper::Model.raise_on_save_failure = true
settings.admin_usernames = config_hash['admin_users'].nil? ? [] : config_hash['admin_users'].split(',')
end
end
module Rack
class Request
def url_without_path
url = scheme + "://"
url << host
if scheme == "https" && port != 443 ||
scheme == "http" && port != 80
url << ":#{port}"
end
url
end
end
end
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end
require File.join(Controller.root, 'controller.rb')