2012-01-20 13:46:09 +00:00
|
|
|
puts "\t...loading core"
|
2011-11-09 01:35:59 +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-11-09 01:35:59 +00:00
|
|
|
require 'locomotive/formtastic'
|
2011-06-20 19:05:12 +00:00
|
|
|
require 'locomotive/dragonfly'
|
2011-11-05 14:18:15 +00:00
|
|
|
require 'locomotive/kaminari'
|
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'
|
2012-01-09 14:49:59 +00:00
|
|
|
require 'locomotive/action_controller'
|
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-07-04 10:22:04 +00:00
|
|
|
require 'locomotive/export'
|
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'
|
2010-06-10 22:07:59 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
module Locomotive
|
2011-11-09 01:35:59 +00:00
|
|
|
extend ActiveSupport::Autoload
|
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
|
|
|
|
|
|
|
|
# Devise
|
|
|
|
mail_address = self.config.mailer_sender
|
2011-11-06 11:18:34 +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-06-28 13:38:13 +00:00
|
|
|
# add middlewares (dragonfly, font, seo, ...etc)
|
|
|
|
self.add_middlewares
|
|
|
|
|
2011-03-04 23:29:40 +00:00
|
|
|
# Load all the dynamic classes (custom fields)
|
2012-01-09 14:49:59 +00:00
|
|
|
begin
|
|
|
|
ContentType.all.collect { |content_type| content_type.klass_with_custom_fields(:entries) }
|
|
|
|
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-06-28 13:38:13 +00:00
|
|
|
def self.add_middlewares
|
|
|
|
self.app_middleware.insert 0, 'Dragonfly::Middleware', :images
|
|
|
|
|
|
|
|
if self.rack_cache?
|
|
|
|
self.app_middleware.insert_before 'Dragonfly::Middleware', '::Locomotive::Middlewares::Cache', self.config.rack_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
self.app_middleware.insert_before Rack::Lock, '::Locomotive::Middlewares::Fonts', :path => %r{^/fonts}
|
|
|
|
self.app_middleware.use '::Locomotive::Middlewares::SeoTrailingSlash'
|
2012-01-20 13:46:09 +00:00
|
|
|
|
|
|
|
self.app_middleware.use '::Locomotive::InlineEditorMiddleware' # TODO
|
2011-06-28 13:38:13 +00:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
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-10-30 12:17:05 +00:00
|
|
|
self.config.manage_domains = self.config.manage_subdomain = false
|
2011-04-01 00:34:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-26 19:20:03 +00:00
|
|
|
def self.log(*args)
|
|
|
|
level = args.size == 1 ? 'info' : args.first
|
|
|
|
message = args.size == 1 ? args.first : args.last
|
|
|
|
|
|
|
|
::Locomotive::Logger.send(level.to_sym, message)
|
2010-06-03 15:32:40 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-28 13:38:13 +00:00
|
|
|
# rack_cache: needed by default
|
|
|
|
def self.rack_cache?
|
|
|
|
self.config.rack_cache != false
|
|
|
|
end
|
|
|
|
|
2012-01-14 13:54:01 +00:00
|
|
|
def self.mounted_on
|
|
|
|
Rails.application.routes.named_routes[:locomotive].path
|
|
|
|
end
|
|
|
|
|
2011-06-28 13:38:13 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def self.app_middleware
|
|
|
|
Rails.application.middleware
|
|
|
|
end
|
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|