2010-09-28 07:46:12 +00:00
|
|
|
require 'mimetype_fu'
|
2011-01-18 15:06:36 +00:00
|
|
|
require 'devise'
|
2010-10-15 00:05:21 +00:00
|
|
|
|
2010-09-28 06:04:40 +00:00
|
|
|
require 'locomotive/version'
|
2010-10-14 12:37:14 +00:00
|
|
|
require 'locomotive/core_ext'
|
2010-04-22 23:52:11 +00:00
|
|
|
require 'locomotive/configuration'
|
2010-06-14 13:04:01 +00:00
|
|
|
require 'locomotive/logger'
|
2011-06-20 19:05:12 +00:00
|
|
|
require 'locomotive/dragonfly'
|
2010-05-30 23:57:33 +00:00
|
|
|
require 'locomotive/liquid'
|
2010-06-01 00:06:46 +00:00
|
|
|
require 'locomotive/mongoid'
|
2010-06-29 22:09:47 +00:00
|
|
|
require 'locomotive/carrierwave'
|
2010-06-30 13:18:17 +00:00
|
|
|
require 'locomotive/custom_fields'
|
2010-07-06 00:05:47 +00:00
|
|
|
require 'locomotive/httparty'
|
2010-07-13 00:46:17 +00:00
|
|
|
require 'locomotive/inherited_resources'
|
2010-07-13 23:37:02 +00:00
|
|
|
require 'locomotive/admin_responder'
|
2010-07-29 23:21:48 +00:00
|
|
|
require 'locomotive/routing'
|
|
|
|
require 'locomotive/regexps'
|
|
|
|
require 'locomotive/render'
|
2010-09-22 22:59:30 +00:00
|
|
|
require 'locomotive/import'
|
2011-03-17 16:41:25 +00:00
|
|
|
require 'locomotive/delayed_job'
|
2010-10-11 14:26:46 +00:00
|
|
|
require 'locomotive/middlewares'
|
2010-09-28 09:19:55 +00:00
|
|
|
require 'locomotive/session_store'
|
2011-05-28 17:52:36 +00:00
|
|
|
require 'locomotive/hosting'
|
2010-06-10 22:07:59 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
module Locomotive
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
extend Locomotive::Hosting::Heroku
|
|
|
|
extend Locomotive::Hosting::Bushido
|
|
|
|
extend Locomotive::Hosting::Default
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
class << self
|
|
|
|
attr_accessor :config
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def config
|
|
|
|
self.config = Configuration.new unless @config
|
|
|
|
@config
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-05 23:29:11 +00:00
|
|
|
def self.engine?
|
|
|
|
self.const_defined?('Engine')
|
|
|
|
end
|
|
|
|
|
2011-05-29 02:45:29 +00:00
|
|
|
def self.default_site_template_present?
|
|
|
|
File.exists?(self.default_site_template_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_site_template_path
|
|
|
|
File.join(Rails.root, 'tmp/default_site_template.zip')
|
|
|
|
end
|
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def self.configure
|
|
|
|
self.config ||= Configuration.new
|
2011-04-01 00:34:19 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
yield(self.config)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-03 15:32:40 +00:00
|
|
|
after_configure
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-03 15:32:40 +00:00
|
|
|
def self.after_configure
|
2011-04-05 00:18:17 +00:00
|
|
|
self.define_subdomain_and_domains_options
|
|
|
|
|
2011-04-01 00:34:19 +00:00
|
|
|
# multi sites support
|
|
|
|
self.configure_multi_sites
|
|
|
|
|
|
|
|
# hosting platform
|
|
|
|
self.configure_hosting
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-01 00:34:19 +00:00
|
|
|
# Devise
|
|
|
|
mail_address = self.config.mailer_sender
|
2011-05-28 17:52:36 +00:00
|
|
|
::Devise.mailer_sender = mail_address =~ /.+@.+/ ? mail_address : "#{mail_address}@#{Locomotive.config.domain}"
|
2010-06-03 15:32:40 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
# cookies stored in mongodb (mongoid_store)
|
2010-06-10 22:07:59 +00:00
|
|
|
Rails.application.config.session_store :mongoid_store, {
|
2011-04-01 00:34:19 +00:00
|
|
|
:key => self.config.cookie_key
|
2010-06-03 15:32:40 +00:00
|
|
|
}
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-03-04 23:29:40 +00:00
|
|
|
# Load all the dynamic classes (custom fields)
|
2011-03-16 17:24:15 +00:00
|
|
|
begin
|
|
|
|
ContentType.all.collect(&:fetch_content_klass)
|
|
|
|
rescue ::Mongoid::Errors::InvalidDatabase => e
|
|
|
|
# let assume it's because of the first install (meaning no config.yml file)
|
|
|
|
end
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-01 00:34:19 +00:00
|
|
|
def self.configure_multi_sites
|
2011-04-03 23:59:41 +00:00
|
|
|
if self.config.multi_sites?
|
2011-04-01 00:34:19 +00:00
|
|
|
domain_name = self.config.multi_sites.domain
|
|
|
|
|
|
|
|
raise '[Error] Locomotive needs a domain name when used as a multi sites platform' if domain_name.blank?
|
|
|
|
|
|
|
|
self.config.domain = domain_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.configure_hosting
|
2011-04-03 23:59:41 +00:00
|
|
|
# Heroku support
|
|
|
|
self.enable_heroku if self.heroku?
|
2011-04-01 00:34:19 +00:00
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
# Bushido support
|
|
|
|
self.enable_bushido if self.bushido?
|
2011-04-01 00:34:19 +00:00
|
|
|
end
|
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
def self.define_subdomain_and_domains_options
|
|
|
|
if self.config.multi_sites?
|
2011-04-01 00:34:19 +00:00
|
|
|
self.config.manage_subdomain = self.config.manage_domains = true
|
|
|
|
else
|
2011-05-29 02:45:29 +00:00
|
|
|
# Note: (Did) modify the code below if Locomotive handles a new hosting solution (not a perfect solution though)
|
2011-04-01 00:34:19 +00:00
|
|
|
self.config.manage_domains = self.heroku? || self.bushido?
|
|
|
|
self.config.manage_subdomain = self.bushido?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
def self.logger(message)
|
2011-04-01 00:34:19 +00:00
|
|
|
if self.config.enable_logs == true
|
2010-06-14 13:04:01 +00:00
|
|
|
Rails.logger.info(message)
|
|
|
|
end
|
2010-06-03 15:32:40 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|