big refactoring of the locomotive config file in order to handle bushido / single / multi sites, ...etc

This commit is contained in:
did 2011-04-01 02:34:19 +02:00
parent 19b6341ace
commit 551d8a5761
32 changed files with 737 additions and 566 deletions

View File

@ -23,7 +23,7 @@ gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave'
gem 'custom_fields', '1.0.0.beta.9'
gem 'fog', '0.3.7'
gem 'mimetype-fu'
gem 'actionmailer-with-request'
gem 'actionmailer_with_request', :git => 'git://github.com/eric1234/actionmailer_with_request.git'
gem 'heroku', '1.18.2'
gem 'bushido'
gem 'httparty', '>= 0.6.1'

View File

@ -1,3 +1,10 @@
GIT
remote: git://github.com/eric1234/actionmailer_with_request.git
revision: 6dd5658d44cc3624596a4fc57e6cde08b7e3bf43
specs:
actionmailer_with_request (0.0.3)
rails (>= 3)
GIT
remote: git://github.com/floehopper/mocha.git
revision: 2b4e868d1907859cd03f407078bd8b630f7d0dd6
@ -14,13 +21,16 @@ GIT
GEM
remote: http://rubygems.org/
specs:
POpen4 (0.1.4)
Platform (>= 0.4.0)
open4
Platform (0.4.0)
RedCloth (4.2.7)
ZenTest (4.5.0)
abstract (1.0.0)
actionmailer (3.0.5)
actionpack (= 3.0.5)
mail (~> 2.2.15)
actionmailer-with-request (0.1.1)
actionpack (3.0.5)
activemodel (= 3.0.5)
activesupport (= 3.0.5)
@ -52,7 +62,7 @@ GEM
bson (1.2.4)
bson_ext (1.2.4)
builder (2.1.2)
bushido (0.0.10)
bushido (0.0.11)
highline (>= 1.6.1)
json (>= 1.4.6)
rest-client (>= 1.6.1)
@ -65,10 +75,10 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.2)
celerity (0.8.8)
celerity (0.8.9)
childprocess (0.1.8)
ffi (~> 1.0.6)
closure-compiler (1.0.0)
closure-compiler (1.1.1)
columnize (0.3.2)
configuration (1.2.0)
crack (0.1.8)
@ -85,7 +95,7 @@ GEM
activesupport (>= 3.0.4)
locomotive_carrierwave
mongoid (~> 2.0.0.rc.7)
daemons (1.1.0)
daemons (1.1.2)
database_cleaner (0.6.6)
delayed_job (2.1.4)
activesupport (~> 3.0)
@ -99,7 +109,7 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
excon (0.5.7)
excon (0.6.0)
factory_girl (1.3.3)
factory_girl_rails (1.0.1)
factory_girl (~> 1.3)
@ -167,20 +177,21 @@ GEM
mimetype-fu (0.1.2)
mongo (1.2.4)
bson (>= 1.2.4)
mongoid (2.0.0.rc.7)
mongoid (2.0.0)
activemodel (~> 3.0)
mongo (~> 1.2)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
net-ssh (2.0.24)
nokogiri (1.4.3.1)
pickle (0.4.6)
open4 (1.0.1)
pickle (0.4.7)
cucumber (>= 0.8)
rake
polyglot (0.3.1)
proxies (0.2.1)
rack (1.2.2)
rack-mount (0.6.13)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
@ -252,7 +263,8 @@ GEM
warden (0.10.7)
rack (>= 1.0.0)
will_paginate (3.0.pre2)
yui-compressor (0.9.4)
yui-compressor (0.9.6)
POpen4 (>= 0.1.4)
PLATFORMS
ruby
@ -260,7 +272,7 @@ PLATFORMS
DEPENDENCIES
RedCloth (= 4.2.7)
ZenTest
actionmailer-with-request
actionmailer_with_request!
autotest
bson_ext (~> 1.2.1)
bushido

View File

@ -1,15 +1,20 @@
module Admin::SitesHelper
def application_domain
domain = Locomotive.config.default_domain
domain = Locomotive.config.domain
domain += ":#{request.port}" if request.port != 80
domain
end
def main_site_url(site = current_site, options = {})
url = "http://#{site.subdomain}.#{Locomotive.config.default_domain}"
# TODO: to be refactored
if multi_sites_enabled?
url = "http://#{site.subdomain}.#{Locomotive.config.domain}"
url += ":#{request.port}" if request.port != 80
url = File.join(url, controller.request.fullpath) if options.has_key?(:uri) && options[:uri]
else
url = "#{request.protocol}#{request.host_with_port}"
end
url = File.join(url, request.fullpath) if options.has_key?(:uri) && options[:uri]
url
end
@ -21,4 +26,16 @@ module Admin::SitesHelper
end
end
def manage_subdomain_or_domains?
Locomotive.config.manage_subdomain || Locomotive.config.manage_domains
end
def manage_domains?
Locomotive.config.manage_domains
end
def multi_sites_enabled?
Locomotive.multi_sites_enabled?
end
end

View File

@ -4,7 +4,7 @@ class Asset
include Mongoid::Timestamps
## Extensions ##
include Models::Extensions::Asset::Vignette
include Extensions::Asset::Vignette
include CustomFields::ProxyClassEnabler
## fields ##

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Asset
module Vignette
@ -16,4 +15,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module EditableElements
@ -114,4 +113,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Listed
@ -14,6 +13,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Parse
@ -104,4 +103,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Redirect
@ -20,6 +19,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Render
@ -10,4 +9,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Templatized
@ -27,6 +26,3 @@ module Models
end
end
end
end

View File

@ -1,4 +1,3 @@
module Models
module Extensions
module Page
module Tree
@ -153,4 +152,3 @@ module Models
end
end
end
end

View File

@ -0,0 +1,79 @@
module Extensions
module Site
module SubdomainDomains
unloadable
extend ActiveSupport::Concern
included do
## fields ##
field :subdomain
field :domains, :type => Array, :default => []
## indexes
index :domains
## validations ##
validates_presence_of :subdomain
validates_uniqueness_of :subdomain
validates_exclusion_of :subdomain, :in => Locomotive.config.multi_sites.reserved_subdomains
validates_format_of :subdomain, :with => Locomotive::Regexps::SUBDOMAIN, :allow_blank => true
validate :domains_must_be_valid_and_unique
## callbacks ##
before_save :add_subdomain_to_domains
## named scopes ##
scope :match_domain, lambda { |domain| { :any_in => { :domains => [*domain] } } }
scope :match_domain_with_exclusion_of, lambda { |domain, site|
{ :any_in => { :domains => [*domain] }, :where => { :_id.ne => site.id } }
}
end
module InstanceMethods
def domains=(array)
array = [] if array.blank?; super(array)
end
def add_subdomain_to_domains
self.domains ||= []
(self.domains << self.full_subdomain).uniq!
end
def domains_without_subdomain
(self.domains || []) - [self.full_subdomain]
end
def domains_with_subdomain
((self.domains || []) + [self.full_subdomain]).uniq
end
def full_subdomain
"#{self.subdomain}.#{Locomotive.config.default_domain}"
end
protected
def domains_must_be_valid_and_unique
return if self.domains.empty?
self.domains_without_subdomain.each do |domain|
if self.class.match_domain_with_exclusion_of(domain, self).any?
self.errors.add(:domains, :domain_taken, :value => domain)
end
if not domain =~ Locomotive::Regexps::DOMAIN
self.errors.add(:domains, :invalid_domain, :value => domain)
end
end
end
end
end
end
end

View File

@ -3,13 +3,13 @@ class Page
include Locomotive::Mongoid::Document
## Extensions ##
include Models::Extensions::Page::Tree
include Models::Extensions::Page::EditableElements
include Models::Extensions::Page::Parse
include Models::Extensions::Page::Render
include Models::Extensions::Page::Templatized
include Models::Extensions::Page::Redirect
include Models::Extensions::Page::Listed
include Extensions::Page::Tree
include Extensions::Page::EditableElements
include Extensions::Page::Parse
include Extensions::Page::Render
include Extensions::Page::Templatized
include Extensions::Page::Redirect
include Extensions::Page::Listed
## fields ##
field :title

View File

@ -4,8 +4,6 @@ class Site
## fields ##
field :name
field :subdomain
field :domains, :type => Array, :default => []
field :meta_keywords
field :meta_description
@ -17,37 +15,19 @@ class Site
references_many :content_types, :dependent => :destroy
embeds_many :memberships
## indexes
index :domains
## validations ##
validates_presence_of :name, :subdomain
validates_uniqueness_of :subdomain
validates_exclusion_of :subdomain, :in => Locomotive.config.reserved_subdomains
validates_format_of :subdomain, :with => Locomotive::Regexps::SUBDOMAIN, :allow_blank => true
validate :domains_must_be_valid_and_unique
validates_presence_of :name
## callbacks ##
after_create :create_default_pages!
before_save :add_subdomain_to_domains
after_destroy :destroy_pages
## named scopes ##
scope :match_domain, lambda { |domain| { :any_in => { :domains => [*domain] } } }
scope :match_domain_with_exclusion_of, lambda { |domain, site|
{ :any_in => { :domains => [*domain] }, :where => { :_id.ne => site.id } }
}
## methods ##
def all_pages_in_once
Page.quick_tree(self)
end
def domains=(array)
array = [] if array.blank?; super(array)
end
def accounts
Account.criteria.in(:_id => self.memberships.collect(&:account_id))
end
@ -56,43 +36,12 @@ class Site
self.memberships.find_all { |m| m.admin? }
end
def add_subdomain_to_domains
self.domains ||= []
(self.domains << self.full_subdomain).uniq!
end
def domains_without_subdomain
(self.domains || []) - [self.full_subdomain]
end
def domains_with_subdomain
((self.domains || []) + [self.full_subdomain]).uniq
end
def full_subdomain
"#{self.subdomain}.#{Locomotive.config.default_domain}"
end
def to_liquid
Locomotive::Liquid::Drops::Site.new(self)
end
protected
def domains_must_be_valid_and_unique
return if self.domains.empty?
self.domains_without_subdomain.each do |domain|
if self.class.match_domain_with_exclusion_of(domain, self).any?
self.errors.add(:domains, :domain_taken, :value => domain)
end
if not domain =~ Locomotive::Regexps::DOMAIN
self.errors.add(:domains, :invalid_domain, :value => domain)
end
end
end
def create_default_pages!
%w{index 404}.each do |slug|
self.pages.create({

View File

@ -9,6 +9,7 @@
= f.input :meta_keywords
= f.input :meta_description
- if manage_subdomain_or_domains?
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
= f.custom_input :subdomain, :css => 'path' do
@ -19,6 +20,7 @@
%em
= application_domain
- if manage_domains?
- @site.domains_without_subdomain.each_with_index do |name, index|
%li{ :class => "item added #{'last' if index == @site.domains.size - 1}"}
%em

View File

@ -6,6 +6,7 @@
- content_for :submenu do
= render 'admin/shared/menu/settings'
- if multi_sites_enabled?
- content_for :buttons do
= admin_button_tag t('.new_site'), new_admin_site_url, :class => 'new'

View File

@ -4,6 +4,7 @@
= f.foldable_inputs :name => :information, :style => "#{'display: none' unless @site.new_record?}" do
= f.input :name, :required => false
- if manage_subdomain_or_domains?
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
= f.custom_input :subdomain, :css => 'path' do
@ -14,6 +15,7 @@
%em
= application_domain
- if manage_domains?
- @site.domains_without_subdomain.each_with_index do |name, index|
%li{ :class => "item added #{'last' if index == @site.domains.size - 1}" }
%em

View File

@ -16,6 +16,8 @@ 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 )
# 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

View File

@ -1,36 +1,107 @@
require File.dirname(__FILE__) + '/../../lib/locomotive.rb'
# require_or_load 'extensions/site/subdomain_domains'
Locomotive.configure do |config|
# 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'
# A single locomotive instance can serve one single site or many.
# If you want to run many different websites, you will have to specify
# your own domain name (ex: locomotivehosting.com).
#
# If you use locomotive for a single site in Heroku, use "heroku.com" as default domain name.
# Your heroku app name (<app_name>.heroku.name) will be used as the sub domain name in Locomotive
# during the installation wizzard.
# Ex:
# config.default_domain = Rails.env.production? ? 'heroku.com' : 'example.com'
config.default_domain = ENV["APP_TLD"] || 'example.com'
config.multi_sites do |multi_sites|
# each new website you add will have a default entry based on a subdomain
# and the multi_site_domain value (ex: website_1.locomotivehosting.com).
multi_sites.domain = 'example.com' #'myhostingplatform.com'
# define the reserved subdomains
# Ex:
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
end
# config.multi_sites = false
# configure the hosting target for the production environment. Locomotive can be installed in:
# - your own server
# - Heroku (you need to create an account in this case)
# - Bushi.do (you need to create an account in this case)
#
# 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).
#
config.hosting = :auto
# In case you host Locomotive in Heroku, the engine uses the heroku api to add / remove domains.
# there are 2 ways of passing heroku credentials to Locomotive
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
# - from this file
# config.heroku = {
# :login => '<your_heroku_login>'
# :password => '<your_heroku_password>'
# }
# 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
# configure how many items we display in sub menu in the "Contents" section.
config.lastest_items_nb = 5
# default locale (for now, only en, de, fr and pt-BR are supported)
config.default_locale = :en
# tell if logs are enabled. Useful for debug purpose.
config.enable_logs = true
# tell if the application is hosted on Heroku.
# Locomotive uses heroku api to add / remove domains.
# there are 2 ways of passing heroku credentials to Locomotive
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
# - from this file
#
# Notes:
# - IMPORTANT: behaviours related to this option will only be applied in production
# - credentials coming from this file take precedence over ENV variables
# Configure the e-mail address which will be shown in the DeviseMailer, NotificationMailer, ...etc
# if you do not put the domain name in the email, Locomotive will take the default domain name depending
# on your deployment target (server, Heroku, Bushido, ...etc)
#
# Ex:
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
config.heroku = false
# 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.
@ -38,16 +109,16 @@ Locomotive.configure do |config|
#
# Ex:
# config.bushido = true
config.bushido = ENV['HOSTING_PLATFORM'] == 'bushido'
# 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'
# 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

View File

@ -9,6 +9,7 @@ x bugs:
- 2 different sites on the same main domain (one in www, the other one in something else) (Raphael Costa)
- seo section for the page form: seo title, seo keywords, seo description
- icon for redirection page in the pages section (back-office)
- write my first tutorial about locomotive
BACKLOG:
@ -20,7 +21,6 @@ BACKLOG:
- editable elements should wrap a tag: div, h1, ...etc (default span)
- edit images (upload new ones, ...etc) => wait for aloha or send them an email ?
- global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating)
- write my first tutorial about locomotive
- cucumber features for admin pages (in progress)
REFACTORING:

View File

@ -8,7 +8,7 @@ require 'locomotive/logger'
require 'locomotive/liquid'
require 'locomotive/mongoid'
require 'locomotive/carrierwave'
require 'locomotive/deployment'
require 'locomotive/hosting'
require 'locomotive/custom_fields'
require 'locomotive/httparty'
require 'locomotive/inherited_resources'
@ -23,8 +23,8 @@ require 'locomotive/session_store'
module Locomotive
include Locomotive::Deployment::Heroku
include Locomotive::Deployment::Bushido
include Locomotive::Hosting::Heroku
include Locomotive::Hosting::Bushido
class << self
attr_accessor :config
@ -37,29 +37,31 @@ module Locomotive
def self.configure
self.config ||= Configuration.new
yield(self.config)
after_configure
end
def self.after_configure
raise '[Error] Locomotive needs a default domain name' if Locomotive.config.default_domain.blank?
# ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '')
ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '')
# 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}"
# cookies stored in mongodb (mongoid_store)
Rails.application.config.session_store :mongoid_store, {
:key => Locomotive.config.cookie_key
:key => self.config.cookie_key
}
# Hosting-platform support
self.enable_heroku if self.heroku?
# Bushido support
self.enable_bushido if self.bushido?
# Devise
Devise.mailer_sender = self.config.mailer_sender
self.define_various_helpers
# Load all the dynamic classes (custom fields)
begin
@ -70,8 +72,44 @@ module Locomotive
end
end
def self.configure_multi_sites
if self.multi_sites_enabled?
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?
self.config.manage_subdomain = self.config.manage_domains = true
else
# FIXME: (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 Locomotive.config.enable_logs == true
if self.config.enable_logs == true
Rails.logger.info(message)
end
end

View File

@ -3,18 +3,20 @@ module Locomotive
@@defaults = {
:name => 'LocomotiveApp',
:default_domain => 'example.com',
:reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
:domain => 'example.com',
# :multi_sites => false,
# :default_domain => 'example.com',
# :reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
# :forbidden_paths => %w{layouts snippets stylesheets javascripts assets admin system api},
:reserved_slugs => %w{stylesheets javascripts assets admin images api pages edit},
:locales => %w{en de fr pt-BR},
:cookie_key => '_locomotive_session',
:enable_logs => false,
:heroku => false,
:bushido => false,
# :heroku => false,
# :bushido => false,
:delayed_job => true,
:default_locale => :en,
:mailer_sender => 'support@example.com'
:mailer_sender => 'support' #support@example.com'
}
cattr_accessor :settings

View File

@ -1 +0,0 @@
Dir[File.join(File.dirname(__FILE__), 'deployment/*.rb')].each { |lib| require lib }

View File

@ -0,0 +1 @@
Dir[File.join(File.dirname(__FILE__), 'hosting/*.rb')].each { |lib| require lib }

View File

@ -1,8 +1,8 @@
require 'bushido'
require 'locomotive/deployment/bushido/custom_domain'
require 'locomotive/hosting/bushido/custom_domain'
module Locomotive
module Deployment
module Hosting
module Bushido
extend ActiveSupport::Concern
@ -17,19 +17,22 @@ module Locomotive
module ClassMethods
def bushido?
ENV["HOSTING_PLATFORM"] == 'bushido'
self.config.hosting == :bushido ||
(self.config.hosting == :auto && ENV['HOSTING_PLATFORM'] == 'bushido')
end
def enable_bushido
self.config.domain = ENV['APP_TLD']
self.enhance_site_model
self.bushido_domains = ::Bushido::App.domains
self.bushido_subdomain = ::Bushido::App.subdomain
end
def enhance_site_model
Site.send :include, Locomotive::Deployment::Bushido::CustomDomain
Site.send :include, Extensions::Site::SubdomainDomains
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
end
# manage domains

View File

@ -1,5 +1,5 @@
module Locomotive
module Deployment
module Hosting
module Bushido
module CustomDomain
@ -20,14 +20,14 @@ module Locomotive
protected
def subdomain_availability
unless ::Bushido::App.check_subdomain_availability?(self.subdomain)
unless ::Bushido::App.subdomain_available?(self.subdomain)
self.errors.add(:subdomain, :exclusion)
end
end
def add_subdomain_to_domains_with_bushido
unless self.domains_change.nil?
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
full_subdomain = "#{self.subdomain}.#{Locomotive.config.domain}"
@bushido_domains_change = {
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]

View File

@ -1,9 +1,9 @@
require 'heroku'
require 'heroku/client'
require 'locomotive/deployment/heroku/custom_domain'
require 'locomotive/hosting/heroku/custom_domain'
module Locomotive
module Deployment
module Hosting
module Heroku
extend ActiveSupport::Concern
@ -18,11 +18,16 @@ module Locomotive
module ClassMethods
def heroku?
!self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
self.config.hosting == :heroku ||
(self.config.hosting == :auto && ENV['HEROKU_SLUG'].present?)
end
def enable_heroku
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
# 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']
self.open_heroku_connection
self.enhance_site_model
@ -33,13 +38,14 @@ module Locomotive
def open_heroku_connection
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
password = self.config.heroku[:password] rescue ENV['HEROKU_PASSWORD']
self.heroku_connection = ::Heroku::Client.new(login, password)
end
def enhance_site_model
Site.send :include, Locomotive::Deployment::Heroku::CustomDomain
Site.send :include, Extensions::Site::SubdomainDomains
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
end
# manage domains

View File

@ -1,5 +1,5 @@
module Locomotive
module Deployment
module Hosting
module Heroku
module CustomDomain
@ -19,7 +19,7 @@ module Locomotive
def add_subdomain_to_domains_with_heroku
unless self.domains_change.nil?
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
full_subdomain = "#{self.subdomain}.#{Locomotive.config.domain}"
@heroku_domains_change = {
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]

View File

@ -3,10 +3,14 @@ module Locomotive
class DefaultConstraint
def self.matches?(request)
if Locomotive.multi_sites_enabled?
domain, subdomain = domain_and_subdomain(request)
subdomain = 'www' if subdomain.blank?
domain == Locomotive.config.default_domain && Locomotive.config.reserved_subdomains.include?(subdomain)
domain == Locomotive.config.domain && Locomotive.config.multi_sites.reserved_subdomains.include?(subdomain)
else
false
end
end
# see actionpack/lib/action_dispatch/http/url.rb for more information

View File

@ -18,7 +18,12 @@ module Locomotive
def fetch_site
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
if Locomotive.multi_sites_enabled?
@current_site ||= Site.match_domain(request.host).first
else
@current_site ||= Site.first
end
end
def current_site
@ -34,7 +39,7 @@ module Locomotive
end
def render_no_site_error
render :template => "/admin/errors/no_site", :layout => false
render :template => '/admin/errors/no_site', :layout => false
end
def validate_site_membership