| 1 |
require 'rubygems' |
|---|
| 2 |
if ENV['SWIFT'] |
|---|
| 3 |
begin |
|---|
| 4 |
require 'swiftcore/swiftiplied_mongrel' |
|---|
| 5 |
puts "Using Swiftiplied Mongrel" |
|---|
| 6 |
rescue LoadError |
|---|
| 7 |
require 'mongrel' |
|---|
| 8 |
puts "SWIFT variable set but not installed - falling back to normal Mongrel" |
|---|
| 9 |
end |
|---|
| 10 |
elsif ENV['EVENT'] |
|---|
| 11 |
begin |
|---|
| 12 |
require 'swiftcore/evented_mongrel' |
|---|
| 13 |
puts "Using Evented Mongrel" |
|---|
| 14 |
rescue LoadError |
|---|
| 15 |
require 'mongrel' |
|---|
| 16 |
puts "EVENT variable set but swiftiply not installed - falling back to normal Mongrel" |
|---|
| 17 |
end |
|---|
| 18 |
elsif ENV['PACKET'] |
|---|
| 19 |
begin |
|---|
| 20 |
require 'packet_mongrel' |
|---|
| 21 |
puts "Using Packet Mongrel" |
|---|
| 22 |
rescue LoadError |
|---|
| 23 |
require 'mongrel' |
|---|
| 24 |
puts "PACKET variable set but packet not installed - falling back to normal Mongrel" |
|---|
| 25 |
end |
|---|
| 26 |
else |
|---|
| 27 |
require 'mongrel' |
|---|
| 28 |
end |
|---|
| 29 |
require 'set' |
|---|
| 30 |
require 'fileutils' |
|---|
| 31 |
require 'merb/erubis_ext' |
|---|
| 32 |
require 'merb/logger' |
|---|
| 33 |
require 'merb/version' |
|---|
| 34 |
require 'merb/config' |
|---|
| 35 |
|
|---|
| 36 |
autoload :MerbUploadHandler, 'merb/upload_handler' |
|---|
| 37 |
autoload :MerbHandler, 'merb/mongrel_handler' |
|---|
| 38 |
|
|---|
| 39 |
module Merb |
|---|
| 40 |
autoload :AbstractController, 'merb/abstract_controller' |
|---|
| 41 |
autoload :Assets, 'merb/assets' |
|---|
| 42 |
autoload :Authentication, 'merb/mixins/basic_authentication' |
|---|
| 43 |
autoload :Caching, 'merb/caching' |
|---|
| 44 |
autoload :Const, 'merb/constants' |
|---|
| 45 |
autoload :Controller, 'merb/controller' |
|---|
| 46 |
autoload :ControllerExceptions, 'merb/exceptions' |
|---|
| 47 |
autoload :ControllerMixin, 'merb/mixins/controller' |
|---|
| 48 |
autoload :Cookies, 'merb/cookies' |
|---|
| 49 |
autoload :Dispatcher, 'merb/dispatcher' |
|---|
| 50 |
autoload :DrbServiceProvider, 'drb_server' |
|---|
| 51 |
autoload :ErubisCaptureMixin, 'merb/mixins/erubis_capture' |
|---|
| 52 |
autoload :GeneralControllerMixin, 'merb/mixins/general_controller' |
|---|
| 53 |
autoload :InlinePartialMixin, 'merb/mixins/inline_partial' |
|---|
| 54 |
autoload :MailController, 'merb/mail_controller' |
|---|
| 55 |
autoload :Mailer, 'merb/mailer' |
|---|
| 56 |
autoload :PartController, 'merb/part_controller' |
|---|
| 57 |
autoload :Plugins, 'merb/plugins' |
|---|
| 58 |
autoload :Rack, 'merb/rack_adapter' |
|---|
| 59 |
autoload :RenderMixin, 'merb/mixins/render' |
|---|
| 60 |
autoload :Request, 'merb/request' |
|---|
| 61 |
autoload :ResponderMixin, 'merb/mixins/responder' |
|---|
| 62 |
autoload :Router, 'merb/router' |
|---|
| 63 |
autoload :Server, 'merb/server' |
|---|
| 64 |
autoload :SessionMixin, 'merb/session' |
|---|
| 65 |
autoload :Template, 'merb/template' |
|---|
| 66 |
autoload :UploadProgress, 'merb/upload_progress' |
|---|
| 67 |
autoload :ViewContext, 'merb/view_context' |
|---|
| 68 |
autoload :ViewContextMixin, 'merb/mixins/view_context' |
|---|
| 69 |
autoload :WebControllerMixin, 'merb/mixins/web_controller' |
|---|
| 70 |
|
|---|
| 71 |
# This is where Merb-global variables are set and held |
|---|
| 72 |
class << self |
|---|
| 73 |
|
|---|
| 74 |
def environment |
|---|
| 75 |
@environment |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
def environment=(value) |
|---|
| 79 |
@environment = value |
|---|
| 80 |
end |
|---|
| 81 |
|
|---|
| 82 |
def load_paths |
|---|
| 83 |
@load_paths ||= [ "/app/models/**/*.rb", |
|---|
| 84 |
"/app/controllers/application.rb", |
|---|
| 85 |
"/app/controllers/**/*.rb", |
|---|
| 86 |
"/app/helpers/**/*.rb", |
|---|
| 87 |
"/app/mailers/**/*.rb", |
|---|
| 88 |
"/app/parts/**/*.rb", |
|---|
| 89 |
"/config/router.rb" |
|---|
| 90 |
] |
|---|
| 91 |
end |
|---|
| 92 |
|
|---|
| 93 |
# Application paths |
|---|
| 94 |
def root |
|---|
| 95 |
@root || Merb::Config[:merb_root] || Dir.pwd |
|---|
| 96 |
end |
|---|
| 97 |
|
|---|
| 98 |
def root_path(*path) |
|---|
| 99 |
File.join(root, *path) |
|---|
| 100 |
end |
|---|
| 101 |
|
|---|
| 102 |
def view_path |
|---|
| 103 |
root_path 'app/views' |
|---|
| 104 |
end |
|---|
| 105 |
|
|---|
| 106 |
def model_path |
|---|
| 107 |
root_path 'app/models' |
|---|
| 108 |
end |
|---|
| 109 |
|
|---|
| 110 |
def application_controller_path |
|---|
| 111 |
root_path 'app/controllers/application.rb' |
|---|
| 112 |
end |
|---|
| 113 |
|
|---|
| 114 |
def controller_path |
|---|
| 115 |
root_path 'app/controllers' |
|---|
| 116 |
end |
|---|
| 117 |
|
|---|
| 118 |
def helper_path |
|---|
| 119 |
root_path 'app/helpers' |
|---|
| 120 |
end |
|---|
| 121 |
|
|---|
| 122 |
def mailer_path |
|---|
| 123 |
root_path 'app/mailers' |
|---|
| 124 |
end |
|---|
| 125 |
|
|---|
| 126 |
def part_path |
|---|
| 127 |
root_path 'app/parts' |
|---|
| 128 |
end |
|---|
| 129 |
|
|---|
| 130 |
def router_path |
|---|
| 131 |
root_path '/config/router.rb' |
|---|
| 132 |
end |
|---|
| 133 |
|
|---|
| 134 |
def root=(value) |
|---|
| 135 |
@root ||= value |
|---|
| 136 |
end |
|---|
| 137 |
|
|---|
| 138 |
# Logger settings |
|---|
| 139 |
attr :logger, true |
|---|
| 140 |
|
|---|
| 141 |
def log_path |
|---|
| 142 |
if $TESTING |
|---|
| 143 |
"#{Merb.root}/log/merb_test.log" |
|---|
| 144 |
elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster] ) |
|---|
| 145 |
STDOUT |
|---|
| 146 |
else |
|---|
| 147 |
"#{Merb.root}/log/merb.#{Merb::Config[:port]}.log" |
|---|
| 148 |
end |
|---|
| 149 |
end |
|---|
| 150 |
|
|---|
| 151 |
# Framework paths |
|---|
| 152 |
|
|---|
| 153 |
def framework_root |
|---|
| 154 |
@framework_root ||= File.dirname(__FILE__) |
|---|
| 155 |
end |
|---|
| 156 |
|
|---|
| 157 |
def framework_path(path) |
|---|
| 158 |
File.join(framework_root, path) |
|---|
| 159 |
end |
|---|
| 160 |
|
|---|
| 161 |
def lib_path |
|---|
| 162 |
framework_path 'merb' |
|---|
| 163 |
end |
|---|
| 164 |
|
|---|
| 165 |
def skeleton_path |
|---|
| 166 |
framework_path '../app_generators/merb/templates' |
|---|
| 167 |
end |
|---|
| 168 |
end |
|---|
| 169 |
|
|---|
| 170 |
# Set up default generator scope |
|---|
| 171 |
GENERATOR_SCOPE = [:merb_default, :merb, :rspec] |
|---|
| 172 |
end |
|---|
| 173 |
|
|---|
| 174 |
# Load up the core extensions |
|---|
| 175 |
require Merb.framework_path('merb/core_ext') |
|---|
| 176 |
require Merb.framework_path('merb/version') |
|---|
| 177 |
|
|---|
| 178 |
# Set the environment |
|---|
| 179 |
Merb.environment = Merb::Config[:environment] || ($TESTING ? 'test' : 'development') |
|---|
| 180 |
|
|---|
| 181 |
# Create and setup the logger |
|---|
| 182 |
Merb.logger = Merb::Logger.new(Merb.log_path) |
|---|
| 183 |
Merb.logger.level = Merb::Logger.const_get(Merb::Config[:log_level].upcase) rescue Merb::Logger::INFO |
|---|
| 184 |
|
|---|
| 185 |
if $TESTING |
|---|
| 186 |
test_files = File.join(Merb.lib_path, 'test', '*.rb') |
|---|
| 187 |
Dir[test_files].each { |file| require file } |
|---|
| 188 |
end |
|---|