engine/lib/locomotive.rb

112 lines
2.7 KiB
Ruby
Raw Normal View History

2010-09-28 07:46:12 +00:00
require 'mimetype_fu'
require 'devise'
2010-10-15 00:05:21 +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'
require 'locomotive/liquid'
require 'locomotive/mongoid'
require 'locomotive/carrierwave'
require 'locomotive/hosting'
require 'locomotive/custom_fields'
require 'locomotive/httparty'
require 'locomotive/inherited_resources'
require 'locomotive/admin_responder'
2010-07-29 23:21:48 +00:00
require 'locomotive/routing'
require 'locomotive/regexps'
require 'locomotive/render'
require 'locomotive/import'
2011-03-17 16:41:25 +00:00
require 'locomotive/delayed_job'
require 'locomotive/middlewares'
require 'locomotive/session_store'
module Locomotive
include Locomotive::Hosting::Heroku
include Locomotive::Hosting::Bushido
class << self
attr_accessor :config
def config
self.config = Configuration.new unless @config
@config
end
end
def self.engine?
self.const_defined?('Engine')
end
def self.configure
self.config ||= Configuration.new
yield(self.config)
2010-06-03 15:32:40 +00:00
after_configure
end
2010-06-03 15:32:40 +00:00
def self.after_configure
self.define_subdomain_and_domains_options
# multi sites support
self.configure_multi_sites
# hosting platform
self.configure_hosting
# Devise
mail_address = self.config.mailer_sender
Devise.mailer_sender = mail_address =~ /.+@.+/ ? mail_address : "#{mail_address}@#{Locomotive.config.domain}"
2010-06-03 15:32:40 +00:00
# cookies stored in mongodb (mongoid_store)
Rails.application.config.session_store :mongoid_store, {
:key => self.config.cookie_key
2010-06-03 15:32:40 +00:00
}
# Load all the dynamic classes (custom fields)
begin
ContentType.all.collect(&:fetch_content_klass)
AssetCollection.all.collect(&:fetch_asset_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
def self.configure_multi_sites
if self.config.multi_sites?
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
# Heroku support
self.enable_heroku if self.heroku?
# Bushido support
self.enable_bushido if self.bushido?
end
def self.define_subdomain_and_domains_options
if self.config.multi_sites?
self.config.manage_subdomain = self.config.manage_domains = true
else
# Note: (Did) modify the code below if Locomotive handles a new hosting solution
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)
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
end