Created
December 24, 2010 14:42
-
-
Save davidrichards/754301 to your computer and use it in GitHub Desktop.
The main application file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================ | |
# = Load Server Dependencies = | |
# ============================ | |
require 'rack-flash' | |
require 'warden' | |
require 'sinatra' | |
require 'haml' | |
require 'sinatra_more/markup_plugin' | |
# =============================== | |
# = Load Buddy Ebsen Components = | |
# =============================== | |
require 'buddy_ebsen/common_helper' | |
require 'buddy_ebsen/login_manager' | |
require 'buddy_ebsen/patient_access' | |
require 'buddy_ebsen/practice_admin' | |
require 'buddy_ebsen/site_admin' | |
# ========================= | |
# = Configure Buddy Ebsen = | |
# ========================= | |
module Sinatra | |
# Sharing a single view directory for now. | |
# Step 5 removes these components into their own gems. | |
class LoginManager < Sinatra::Base | |
set :app_file, __FILE__ | |
set :static, true | |
set :run, false | |
end | |
class PatientAccess < Sinatra::Base | |
set :app_file, __FILE__ | |
set :static, true | |
set :run, false | |
end | |
class PracticeAdmin < Sinatra::Base | |
set :app_file, __FILE__ | |
set :static, true | |
set :run, false | |
end | |
class SiteAdmin < Sinatra::Base | |
set :app_file, __FILE__ | |
set :static, true | |
set :run, false | |
end | |
class BuddyEbsen < Sinatra::Base | |
helpers Sinatra::CommonHelper | |
configure do | |
set :root, File.expand_path(File.dirname(__FILE__)) | |
set :app_file, File.join(settings.root, __FILE__) | |
set :app_file, __FILE__ | |
set :views, File.dirname(__FILE__) + '/views' | |
set :config_path, File.join(settings.root, '..') | |
set :database_config, YAML.load(File.read(File.join(settings.config_path, 'database.yml'))) | |
set :environment, (ENV['RACK_ENV'] ? ENV['RACK_ENV'] : 'development') | |
set :environment_config, settings.database_config[settings.environment] | |
set :database_file, File.expand_path(File.join(settings.root, settings.environment_config["database"])) | |
set :public, File.join(settings.root, '..', 'public') | |
# set :static, settings.public | |
set :static, true | |
set :common_date_format, "%b %d, %Y" | |
set :assume_xhr_is_js, true | |
set :show_exceptions, false | |
domain = case settings.environment | |
when 'development' | |
'http://localhost:9393' | |
when 'test' | |
'http://localhost:9393' | |
when 'production' | |
'https://be.chartlogic.com' | |
else | |
'https://be.chartlogic.com' | |
end | |
set :domain, domain | |
register SinatraMore::MarkupPlugin | |
use Rack::Flash | |
set :sessions, true | |
require 'warden_strategies' | |
ActiveRecord::Base.establish_connection(settings.environment_config) | |
use Rack::Session::Cookie | |
use Warden::Manager do |manager| | |
manager.default_strategies :password, :session_id | |
manager.failure_app = LoginManager | |
end | |
set :run, false | |
end | |
# ==================== | |
# = Local Components = | |
# ==================== | |
use LoginManager | |
use SiteAdmin | |
use PatientAccess | |
use PracticeAdmin | |
# get '/' do | |
# 'Welcome!' | |
# end | |
get '/' do | |
# user = env['warden'].user | |
# if user and user.site_admin | |
# redirect "/admin" | |
# elsif user and user.is_manager? and @practice = user.managed_practices.first | |
# redirect "/#{@practice.short_name}" | |
# elsif user and @patient = user.patient and @practice = user.patient.practice | |
# redirect "/#{@practice.short_name}/patient/#{@patient.id}" | |
# else | |
# haml :login | |
# # haml :index | |
# end | |
'piece by piece' | |
end | |
get '/public/stylesheets/styles.css' do | |
sass :styles | |
end | |
get '/public/stylesheets/ninesixty.css' do | |
sass :ninesixty | |
end | |
# error do redirect '/' end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment