single site / multi sites option in progress + integrating bushi.do + revert back to mongoid rc.7
This commit is contained in:
parent
551d8a5761
commit
c0a5a4b443
2
Gemfile
2
Gemfile
@ -7,7 +7,7 @@ gem 'rails', '>= 3.0.5'
|
||||
gem 'warden'
|
||||
gem 'devise', '= 1.1.3'
|
||||
|
||||
gem 'mongoid', '~> 2.0.0.rc.7'
|
||||
gem 'mongoid', '2.0.0.rc.7'
|
||||
gem 'bson_ext', '~> 1.2.1'
|
||||
gem 'locomotive_mongoid_acts_as_tree', '0.1.5.5', :require => 'mongoid_acts_as_tree'
|
||||
gem 'will_paginate'
|
||||
|
@ -177,7 +177,7 @@ GEM
|
||||
mimetype-fu (0.1.2)
|
||||
mongo (1.2.4)
|
||||
bson (>= 1.2.4)
|
||||
mongoid (2.0.0)
|
||||
mongoid (2.0.0.rc.7)
|
||||
activemodel (~> 3.0)
|
||||
mongo (~> 1.2)
|
||||
tzinfo (~> 0.3.22)
|
||||
@ -256,7 +256,7 @@ GEM
|
||||
treetop (1.4.9)
|
||||
polyglot (>= 0.3.1)
|
||||
trollop (1.16.2)
|
||||
tzinfo (0.3.25)
|
||||
tzinfo (0.3.26)
|
||||
unicorn (3.5.0)
|
||||
kgio (~> 2.3)
|
||||
rack
|
||||
@ -299,7 +299,7 @@ DEPENDENCIES
|
||||
locomotive_mongoid_acts_as_tree (= 0.1.5.5)
|
||||
mimetype-fu
|
||||
mocha!
|
||||
mongoid (~> 2.0.0.rc.7)
|
||||
mongoid (= 2.0.0.rc.7)
|
||||
pickle
|
||||
rails (>= 3.0.5)
|
||||
rmagick (= 2.12.2)
|
||||
|
@ -8,7 +8,7 @@ module Admin::SitesHelper
|
||||
|
||||
def main_site_url(site = current_site, options = {})
|
||||
# TODO: to be refactored
|
||||
if multi_sites_enabled?
|
||||
if multi_sites?
|
||||
url = "http://#{site.subdomain}.#{Locomotive.config.domain}"
|
||||
url += ":#{request.port}" if request.port != 80
|
||||
else
|
||||
@ -27,15 +27,15 @@ module Admin::SitesHelper
|
||||
end
|
||||
|
||||
def manage_subdomain_or_domains?
|
||||
Locomotive.config.manage_subdomain || Locomotive.config.manage_domains
|
||||
Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains?
|
||||
end
|
||||
|
||||
def manage_domains?
|
||||
Locomotive.config.manage_domains
|
||||
Locomotive.config.manage_domains?
|
||||
end
|
||||
|
||||
def multi_sites_enabled?
|
||||
Locomotive.multi_sites_enabled?
|
||||
def multi_sites?
|
||||
Locomotive.config.multi_sites?
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,11 +2,8 @@ module Extensions
|
||||
module Site
|
||||
module SubdomainDomains
|
||||
|
||||
unloadable
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def enable_subdomain_n_domains_if_multi_sites
|
||||
if Locomotive.config.multi_sites? || Locomotive.config.manage_subdomain_n_domains?
|
||||
|
||||
## fields ##
|
||||
field :subdomain
|
||||
@ -31,6 +28,9 @@ module Extensions
|
||||
{ :any_in => { :domains => [*domain] }, :where => { :_id.ne => site.id } }
|
||||
}
|
||||
|
||||
send :include, InstanceMethods
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
@ -53,7 +53,7 @@ module Extensions
|
||||
end
|
||||
|
||||
def full_subdomain
|
||||
"#{self.subdomain}.#{Locomotive.config.default_domain}"
|
||||
"#{self.subdomain}.#{Locomotive.config.domain}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -2,6 +2,9 @@ class Site
|
||||
|
||||
include Locomotive::Mongoid::Document
|
||||
|
||||
## Extensions ##
|
||||
extend Extensions::Site::SubdomainDomains
|
||||
|
||||
## fields ##
|
||||
field :name
|
||||
field :meta_keywords
|
||||
@ -22,6 +25,9 @@ class Site
|
||||
after_create :create_default_pages!
|
||||
after_destroy :destroy_pages
|
||||
|
||||
## behaviours ##
|
||||
enable_subdomain_n_domains_if_multi_sites
|
||||
|
||||
## methods ##
|
||||
|
||||
def all_pages_in_once
|
||||
|
@ -6,7 +6,7 @@
|
||||
- content_for :submenu do
|
||||
= render 'admin/shared/menu/settings'
|
||||
|
||||
- if multi_sites_enabled?
|
||||
- if multi_sites?
|
||||
- content_for :buttons do
|
||||
= admin_button_tag t('.new_site'), new_admin_site_url, :class => 'new'
|
||||
|
||||
|
@ -16,8 +16,7 @@ module Locomotive
|
||||
|
||||
# Add additional load paths for your own custom dirs
|
||||
# config.load_paths += %W( #{config.root}/extras )
|
||||
# config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset)
|
||||
# config.autoload_paths += %W( #{config.root}/app/models/extensions/site )
|
||||
config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset)
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named
|
||||
|
@ -1,5 +1,4 @@
|
||||
require File.dirname(__FILE__) + '/../../lib/locomotive.rb'
|
||||
# require_or_load 'extensions/site/subdomain_domains'
|
||||
|
||||
Locomotive.configure do |config|
|
||||
|
||||
@ -61,64 +60,4 @@ Locomotive.configure do |config|
|
||||
# config.mailer_sender = 'support'
|
||||
# # => 'support@heroku.com' (Heroku), 'support@bushi.do' (Bushido), 'support@example.com' (Dev) or 'support@<your_hosting_platform>' (Multi-sites)
|
||||
config.mailer_sender = 'support'
|
||||
|
||||
# ===================================================
|
||||
|
||||
# do |deployment|
|
||||
#
|
||||
# # the possible options are: server, heroku, bushido or auto (default)
|
||||
# # if you select 'auto', Locomotive will look after specific ENV variables to check
|
||||
# # the matching platform (Heroku and Bushido set their own ENV variable).
|
||||
# deployment.target = :auto
|
||||
#
|
||||
# # in case you select heroku, it requires your Heroku credentials in order to manage domains.
|
||||
# # If you do not want to store the credentials here, you can add them directly into the Heroku ENV
|
||||
# # (see Heroku documentation)
|
||||
# # deployment.heroku = {
|
||||
# # :login => '<your_heroku_login>'
|
||||
# # :password => '<your_heroku_password>'
|
||||
# # }
|
||||
# end
|
||||
#
|
||||
|
||||
# # define the domain name used in production.cn
|
||||
# deployment.domain = 'example.com'
|
||||
|
||||
|
||||
# set the default domain name used in development/test. By default, 'example.com' is used.
|
||||
# config.local_domain = 'example.com'
|
||||
|
||||
# Locomotive can serve one single site or many. The "many sites" option requires more constraints for
|
||||
# the domain name (see config.domain for more explanation)
|
||||
#
|
||||
# Ex:
|
||||
# config.site_mode = :single
|
||||
# or
|
||||
# config.site_mode = :many
|
||||
# config.site_mode = :single
|
||||
|
||||
# if not defined, locomotive will use example.com as main domain name. Remove prefix www from your domain name.
|
||||
# Ex:
|
||||
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
||||
#
|
||||
# If you use locomotive for a single site in Heroku, use "heroku.com" as default domain name.bzc,
|
||||
|
||||
# tell if the application is hosted on Bushido.
|
||||
# If enabled, there's no further configuration needed.
|
||||
# Bushido will take care of eveything
|
||||
#
|
||||
# Ex:
|
||||
# config.bushido = true
|
||||
# config.bushido = ENV['HOSTING_PLATFORM'] == 'bushido'
|
||||
|
||||
# Locomotive uses the DelayedJob gem for the theme import module.
|
||||
# In case you want to deploy to Heroku, you will have to pay for an extra dyno.
|
||||
# If you do not mind about importing theme without DelayedJob, disable it.
|
||||
# config.delayed_job = false
|
||||
#
|
||||
# # default locale (for now, only en, de, fr and pt-BR are supported)
|
||||
# config.default_locale = :en
|
||||
#
|
||||
# # Configure the e-mail address which will be shown in the DeviseMailer, NotificationMailer, ...etc
|
||||
# config.mailer_sender = ENV['BUSHIDO_DOMAIN'] ? "support@#{ENV['BUSHIDO_DOMAIN']}" : 'support@example.com'
|
||||
end
|
||||
|
@ -38,11 +38,10 @@ Capybara.javascript_driver = :selenium
|
||||
# of your scenarios, as this makes it hard to discover errors in your application.
|
||||
ActionController::Base.allow_rescue = false
|
||||
|
||||
Locomotive.configure do |config|
|
||||
config.default_domain = 'example.com'
|
||||
end
|
||||
|
||||
Capybara.default_host = 'test.example.com'
|
||||
# Capybara.app_host = 'http://test.example.com'
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/carrierwave')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/locomotive')
|
||||
|
||||
Locomotive.configure_for_test
|
@ -44,8 +44,6 @@ module Locomotive
|
||||
end
|
||||
|
||||
def self.after_configure
|
||||
# ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '')
|
||||
|
||||
# multi sites support
|
||||
self.configure_multi_sites
|
||||
|
||||
@ -61,7 +59,7 @@ module Locomotive
|
||||
:key => self.config.cookie_key
|
||||
}
|
||||
|
||||
self.define_various_helpers
|
||||
self.define_subdomain_and_domains_options
|
||||
|
||||
# Load all the dynamic classes (custom fields)
|
||||
begin
|
||||
@ -73,41 +71,33 @@ module Locomotive
|
||||
end
|
||||
|
||||
def self.configure_multi_sites
|
||||
if self.multi_sites_enabled?
|
||||
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?
|
||||
|
||||
# Site.send :include, Extensions::Site::SubdomainDomains
|
||||
|
||||
self.config.domain = domain_name
|
||||
end
|
||||
end
|
||||
|
||||
def self.configure_hosting
|
||||
if Rails.env.production?
|
||||
# Heroku support
|
||||
self.enable_heroku if self.heroku?
|
||||
|
||||
# Bushido support
|
||||
self.enable_bushido if self.bushido?
|
||||
end
|
||||
end
|
||||
|
||||
def self.define_various_helpers
|
||||
if self.multi_sites_enabled?
|
||||
def self.define_subdomain_and_domains_options
|
||||
if self.config.multi_sites?
|
||||
self.config.manage_subdomain = self.config.manage_domains = true
|
||||
else
|
||||
# FIXME: (Did) modify the code below if Locomotive handles a new hosting solution
|
||||
# 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
|
||||
|
||||
def self.multi_sites_enabled?
|
||||
self.config.multi_sites != false
|
||||
end
|
||||
|
||||
def self.logger(message)
|
||||
if self.config.enable_logs == true
|
||||
Rails.logger.info(message)
|
||||
|
@ -14,9 +14,12 @@ module Locomotive
|
||||
:enable_logs => false,
|
||||
# :heroku => false,
|
||||
# :bushido => false,
|
||||
:hosting => :auto,
|
||||
:delayed_job => true,
|
||||
:default_locale => :en,
|
||||
:mailer_sender => 'support' #support@example.com'
|
||||
:mailer_sender => 'support', #support@example.com'
|
||||
:manage_subdomain => false,
|
||||
:manage_manage_domains => false
|
||||
}
|
||||
|
||||
cattr_accessor :settings
|
||||
@ -29,6 +32,22 @@ module Locomotive
|
||||
@@settings
|
||||
end
|
||||
|
||||
def multi_sites?
|
||||
self.multi_sites != false
|
||||
end
|
||||
|
||||
def manage_subdomain?
|
||||
self.manage_subdomain == true
|
||||
end
|
||||
|
||||
def manage_domains?
|
||||
self.manage_domains == true
|
||||
end
|
||||
|
||||
def manage_subdomain_n_domains?
|
||||
self.manage_subdomain? && self.manage_domains?
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
self.settings.send(name, *args, &block)
|
||||
end
|
||||
|
@ -24,14 +24,13 @@ module Locomotive
|
||||
def enable_bushido
|
||||
self.config.domain = ENV['APP_TLD']
|
||||
|
||||
self.enhance_site_model
|
||||
self.enhance_site_model_with_bushido
|
||||
|
||||
self.bushido_domains = ::Bushido::App.domains
|
||||
self.bushido_subdomain = ::Bushido::App.subdomain
|
||||
end
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Extensions::Site::SubdomainDomains
|
||||
def enhance_site_model_with_bushido
|
||||
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
||||
end
|
||||
|
||||
|
@ -23,14 +23,16 @@ module Locomotive
|
||||
end
|
||||
|
||||
def enable_heroku
|
||||
# raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||
self.config.domain = 'heroku.com'
|
||||
|
||||
self.config.heroku ||= {}
|
||||
self.config.heroku[:name] = ENV['APP_NAME']
|
||||
|
||||
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||
|
||||
self.open_heroku_connection
|
||||
self.enhance_site_model
|
||||
|
||||
self.enhance_site_model_with_heroku
|
||||
|
||||
# "cache" domains for better performance
|
||||
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
||||
@ -38,13 +40,12 @@ module Locomotive
|
||||
|
||||
def open_heroku_connection
|
||||
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
||||
password = self.config.heroku[:password] rescue ENV['HEROKU_PASSWORD']
|
||||
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
||||
|
||||
self.heroku_connection = ::Heroku::Client.new(login, password)
|
||||
end
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Extensions::Site::SubdomainDomains
|
||||
def enhance_site_model_with_heroku
|
||||
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,6 @@ module Locomotive
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
after_save :add_heroku_domains
|
||||
after_destroy :remove_heroku_domains
|
||||
|
||||
|
@ -3,7 +3,7 @@ module Locomotive
|
||||
class DefaultConstraint
|
||||
|
||||
def self.matches?(request)
|
||||
if Locomotive.multi_sites_enabled?
|
||||
if Locomotive.config.multi_sites?
|
||||
domain, subdomain = domain_and_subdomain(request)
|
||||
subdomain = 'www' if subdomain.blank?
|
||||
|
||||
|
@ -19,7 +19,7 @@ module Locomotive
|
||||
def fetch_site
|
||||
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
||||
|
||||
if Locomotive.multi_sites_enabled?
|
||||
if Locomotive.config.multi_sites?
|
||||
@current_site ||= Site.match_domain(request.host).first
|
||||
else
|
||||
@current_site ||= Site.first
|
||||
|
@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency "rails", ">= 3.0.5"
|
||||
s.add_dependency "warden"
|
||||
s.add_dependency "devise", "1.1.3"
|
||||
s.add_dependency "mongoid", "~> 2.0.0.rc.7"
|
||||
s.add_dependency "mongoid", "2.0.0.rc.7"
|
||||
s.add_dependency "bson_ext", "~> 1.2.0"
|
||||
s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.5"
|
||||
s.add_dependency "will_paginate"
|
||||
|
@ -28,7 +28,7 @@ describe 'Heroku support' do
|
||||
|
||||
before(:each) do
|
||||
Locomotive.configure do |config|
|
||||
config.heroku = false
|
||||
config.hosting = :none
|
||||
end
|
||||
end
|
||||
|
||||
@ -49,7 +49,13 @@ describe 'Heroku support' do
|
||||
|
||||
context '#enabled' do
|
||||
|
||||
it 'tells heroku is disabled' do
|
||||
it 'tells heroku is enabled from ENV' do
|
||||
ENV['HEROKU_SLUG'] = 'test'
|
||||
Locomotive.config.hosting = :auto
|
||||
Locomotive.heroku?.should be_true
|
||||
end
|
||||
|
||||
it 'tells heroku is enabled when forcing it' do
|
||||
configure_locomotive_with_heroku
|
||||
Locomotive.heroku?.should be_true
|
||||
end
|
||||
@ -69,8 +75,9 @@ describe 'Heroku support' do
|
||||
end
|
||||
|
||||
it 'opens a heroku connection with env credentials' do
|
||||
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'
|
||||
Locomotive.configure { |config| config.heroku = true }
|
||||
::Heroku::Client.any_instance.stubs(:list_domains).returns([])
|
||||
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'; ENV['APP_NAME'] = 'test'
|
||||
Locomotive.configure { |config| config.hosting = :heroku; config.heroku = {} }
|
||||
Locomotive.heroku_connection.user.should == 'john@doe.net'
|
||||
Locomotive.heroku_connection.password.should == 'easyone'
|
||||
end
|
||||
@ -138,12 +145,25 @@ describe 'Heroku support' do
|
||||
end
|
||||
|
||||
def configure_locomotive_with_heroku(options = {}, domains = nil)
|
||||
::Heroku::Client.any_instance.stubs(:list_domains).with('locomotive').returns(domains || [
|
||||
if options.has_key?(:name)
|
||||
ENV['APP_NAME'] = options.delete(:name)
|
||||
else
|
||||
ENV['APP_NAME'] = 'locomotive'
|
||||
end
|
||||
|
||||
::Heroku::Client.any_instance.stubs(:list_domains).with(ENV['APP_NAME']).returns(domains || [
|
||||
{ :domain => "www.acme.com" }, { :domain => "example.com" }, { :domain => "www.example.com" }
|
||||
])
|
||||
|
||||
Locomotive.configure do |config|
|
||||
config.heroku = { :name => 'locomotive', :login => 'john@doe.net', :password => 'easyone' }.merge(options)
|
||||
config.hosting = :heroku
|
||||
config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options)
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
|
||||
Locomotive.configure_for_test
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -7,6 +7,8 @@ require 'rspec/rails'
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||
|
||||
Locomotive.configure_for_test
|
||||
|
||||
RSpec.configure do |config|
|
||||
# == Mock Framework
|
||||
#
|
||||
|
32
spec/support/controller.rb
Normal file
32
spec/support/controller.rb
Normal file
@ -0,0 +1,32 @@
|
||||
module Locomotive
|
||||
class TestController < ApplicationController
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
attr_accessor :output, :status, :current_site, :current_admin
|
||||
|
||||
def render(options = {})
|
||||
self.output = options[:text]
|
||||
self.status = options[:status]
|
||||
end
|
||||
|
||||
def response
|
||||
@_response ||= TestResponse.new
|
||||
end
|
||||
|
||||
def request
|
||||
@_request ||= TestRequest.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class TestResponse < ActionDispatch::TestResponse
|
||||
|
||||
end
|
||||
|
||||
class TestRequest < ActionDispatch::TestRequest
|
||||
|
||||
attr_accessor :fullpath
|
||||
|
||||
end
|
||||
end
|
@ -1,37 +1,10 @@
|
||||
Locomotive.configure do |config|
|
||||
config.default_domain = 'example.com'
|
||||
def Locomotive.configure_for_test
|
||||
Locomotive.configure do |config|
|
||||
config.multi_sites do |multi_sites|
|
||||
multi_sites.domain = 'example.com'
|
||||
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
|
||||
end
|
||||
config.hosting = :none
|
||||
config.enable_logs = true
|
||||
end
|
||||
|
||||
module Locomotive
|
||||
class TestController < ApplicationController
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
attr_accessor :output, :status, :current_site, :current_admin
|
||||
|
||||
def render(options = {})
|
||||
self.output = options[:text]
|
||||
self.status = options[:status]
|
||||
end
|
||||
|
||||
def response
|
||||
@_response ||= TestResponse.new
|
||||
end
|
||||
|
||||
def request
|
||||
@_request ||= TestRequest.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class TestResponse < ActionDispatch::TestResponse
|
||||
|
||||
end
|
||||
|
||||
class TestRequest < ActionDispatch::TestRequest
|
||||
|
||||
attr_accessor :fullpath
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user