-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.rb
116 lines (92 loc) · 3.06 KB
/
application.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
# Set a environment if one does not exist
ENV['RACK_ENV'] ||= 'development'
# Set default encodings
Encoding.default_internal = 'UTF-8'
Encoding.default_external = 'UTF-8'
# Sync stdout for foreman/heroku
$stdout.sync = true
# Require gems
require 'rubygems'
require 'bundler/setup'
Bundler.require
# Start
puts "Starting in #{ENV['RACK_ENV']} mode.."
# Load libs helpers and models
Dir.glob(%w{lib/** helpers models}.map! {|d| File.join d, '*.rb'}).each {|f| require_relative f}
# Start setting up our application by extending Sinatra::Base
class Application < Sinatra::Base
def self.Config
@@config ||= Hashie::Mash.new YAML.load_file('./config.yml')[ENV['RACK_ENV'].to_s]
end
def self.production?
ENV['RACK_ENV'] == 'production'
end
def self.develpoment?
ENV['RACK_ENV'] == 'development'
end
register Sinatra::Flash
helpers Sinatra::UserAgentHelpers
set :root, File.dirname(__FILE__)
set :views, 'views'
set :public_folder, 'public'
set :erubis, :escape_html => true
set :sessions, true
set :session_secret, self.Config.session_secret
# Development Specific Configuration
configure :development do
Bundler.require :development
use Rack::ShowExceptions
end
# Test Specific Configuration
configure :test do
Bundler.require :test
end
# Production Specific Configuration
configure :production do
Bundler.require :production
end
# Setup Caching
Geoloqi::Cache = Dalli::Client.new (ENV['MEMCACHE_SERVERS'] ? "#{ENV['MEMCACHE_USERNAME']}:#{ENV['MEMCACHE_PASSWORD']}@#{ENV['MEMCACHE_SERVERS']}" : 'localhost:11211')
# Set controller names so we can map them in the config.ru file.
set :controller_names, []
Dir.glob('controllers/*.rb').each do |file|
settings.controller_names << File.basename(file, '.rb')
end
# Setup Sprockets
set :sprockets, Sprockets::Environment.new(root)
set :precompile, [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
set :assets_prefix, "/assets"
set :digest_assets, false
set(:assets_path) { File.join public_folder, assets_prefix }
configure do
# Setup Sprockets
sprockets.append_path File.join(root, "assets", "css")
sprockets.append_path File.join(root, "assets", "js")
sprockets.append_path File.join(root, "assets", "img")
# Configure Sprockets::Helpers (if necessary)
Sprockets::Helpers.configure do |config|
config.environment = sprockets
config.prefix = assets_prefix
config.digest = digest_assets
config.public_path = public_folder
end
end
helpers do
include Sprockets::Helpers
end
# Configure Compass so it can find images
Compass.configuration do |compass|
compass.project_path = assets_path
compass.images_dir = 'img'
compass.output_style = ENV['RACK_ENV'] == 'production' ? :compressed : :expanded
end
# Params Shortcut
def p
Hashie::Mash.new params
end
end
# Require Controllers
require_relative './controller.rb'
Dir.glob(['controllers'].map! {|d| File.join d, '*.rb'}).each do |f|
require_relative f
end