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}"
url += ":#{request.port}" if request.port != 80
url = File.join(url, controller.request.fullpath) if options.has_key?(:uri) && options[:uri]
# TODO: to be refactored
if multi_sites_enabled?
url = "http://#{site.subdomain}.#{Locomotive.config.domain}"
url += ":#{request.port}" if request.port != 80
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,19 +1,17 @@
module Models
module Extensions
module Asset
module Vignette
module Extensions
module Asset
module Vignette
def vignette_url
if self.image?
if self.width < 80 && self.height < 80
self.source.url
else
self.source.url(:medium)
end
def vignette_url
if self.image?
if self.width < 80 && self.height < 80
self.source.url
else
self.source.url(:medium)
end
end
end
end
end
end

View File

@ -1,117 +1,115 @@
module Models
module Extensions
module Page
module EditableElements
module Extensions
module Page
module EditableElements
extend ActiveSupport::Concern
extend ActiveSupport::Concern
included do
embeds_many :editable_elements
included do
embeds_many :editable_elements
after_save :remove_disabled_editable_elements
after_save :remove_disabled_editable_elements
# editable file callbacks
after_save :store_file_sources!
before_save :write_file_source_identifiers
after_destroy :remove_file_sources!
# editable file callbacks
after_save :store_file_sources!
before_save :write_file_source_identifiers
after_destroy :remove_file_sources!
accepts_nested_attributes_for :editable_elements
accepts_nested_attributes_for :editable_elements
end
module InstanceMethods
def disable_parent_editable_elements(block)
self.editable_elements.each { |el| el.disabled = true if el.from_parent? && el.block == block }
end
module InstanceMethods
def disable_all_editable_elements
self.editable_elements.each { |el| el.disabled = true }
end
def disable_parent_editable_elements(block)
self.editable_elements.each { |el| el.disabled = true if el.from_parent? && el.block == block }
def editable_element_blocks
self.editable_elements.collect(&:block)
end
def editable_elements_grouped_by_blocks
all_enabled = self.editable_elements.reject { |el| el.disabled? }
groups = all_enabled.group_by(&:block)
groups.delete_if { |block, elements| elements.empty? }
end
def find_editable_element(block, slug)
self.editable_elements.detect { |el| el.block == block && el.slug == slug }
end
def find_editable_files
self.editable_elements.find_all { |el| el.respond_to?(:source) }
end
def add_or_update_editable_element(attributes, type)
element = self.find_editable_element(attributes[:block], attributes[:slug])
if element
element.attributes = attributes
else
self.editable_elements.build(attributes, type)
end
end
def disable_all_editable_elements
self.editable_elements.each { |el| el.disabled = true }
end
def enable_editable_elements(block)
self.editable_elements.each { |el| el.disabled = false if el.block == block }
end
def editable_element_blocks
self.editable_elements.collect(&:block)
end
def merge_editable_elements_from_page(source)
source.editable_elements.each do |el|
next if el.disabled? or !el.assignable?
def editable_elements_grouped_by_blocks
all_enabled = self.editable_elements.reject { |el| el.disabled? }
groups = all_enabled.group_by(&:block)
groups.delete_if { |block, elements| elements.empty? }
end
existing_el = self.find_editable_element(el.block, el.slug)
def find_editable_element(block, slug)
self.editable_elements.detect { |el| el.block == block && el.slug == slug }
end
def find_editable_files
self.editable_elements.find_all { |el| el.respond_to?(:source) }
end
def add_or_update_editable_element(attributes, type)
element = self.find_editable_element(attributes[:block], attributes[:slug])
if element
element.attributes = attributes
else
self.editable_elements.build(attributes, type)
end
end
def enable_editable_elements(block)
self.editable_elements.each { |el| el.disabled = false if el.block == block }
end
def merge_editable_elements_from_page(source)
source.editable_elements.each do |el|
next if el.disabled? or !el.assignable?
existing_el = self.find_editable_element(el.block, el.slug)
if existing_el.nil? # new one from parents
new_attributes = el.attributes.merge(:from_parent => true)
if new_attributes['default_attribute'].present?
new_attributes['default_content'] = self.send(new_attributes['default_attribute']) || el.content
else
new_attributes['default_content'] = el.content
end
self.editable_elements.build(new_attributes, el.class)
elsif existing_el.default_attribute.nil?
existing_el.attributes = { :disabled => false, :default_content => el.content }
if existing_el.nil? # new one from parents
new_attributes = el.attributes.merge(:from_parent => true)
if new_attributes['default_attribute'].present?
new_attributes['default_content'] = self.send(new_attributes['default_attribute']) || el.content
else
existing_el.attributes = { :disabled => false }
new_attributes['default_content'] = el.content
end
self.editable_elements.build(new_attributes, el.class)
elsif existing_el.default_attribute.nil?
existing_el.attributes = { :disabled => false, :default_content => el.content }
else
existing_el.attributes = { :disabled => false }
end
end
end
def remove_disabled_editable_elements
return unless self.editable_elements.any? { |el| el.disabled? }
def remove_disabled_editable_elements
return unless self.editable_elements.any? { |el| el.disabled? }
# super fast way to remove useless elements all in once (TODO callbacks)
self.collection.update(self._selector, '$pull' => { 'editable_elements' => { 'disabled' => true } })
end
# super fast way to remove useless elements all in once (TODO callbacks)
self.collection.update(self._selector, '$pull' => { 'editable_elements' => { 'disabled' => true } })
end
protected
protected
## callbacks for editable files
## callbacks for editable files
# equivalent to "after_save :store_source!" in EditableFile
def store_file_sources!
self.find_editable_files.collect(&:store_source!)
end
# equivalent to "after_save :store_source!" in EditableFile
def store_file_sources!
self.find_editable_files.collect(&:store_source!)
end
# equivalent to "before_save :write_source_identifier" in EditableFile
def write_file_source_identifiers
self.find_editable_files.collect(&:write_source_identifier)
end
# equivalent to "after_destroy :remove_source!" in EditableFile
def remove_file_sources!
self.find_editable_files.collect(&:remove_source!)
end
# equivalent to "before_save :write_source_identifier" in EditableFile
def write_file_source_identifiers
self.find_editable_files.collect(&:write_source_identifier)
end
# equivalent to "after_destroy :remove_source!" in EditableFile
def remove_file_sources!
self.find_editable_files.collect(&:remove_source!)
end
end
end
end
end

View File

@ -1,19 +1,15 @@
module Models
module Extensions
module Page
module Listed
extend ActiveSupport::Concern
included do
field :listed, :type => Boolean, :default => true
end
module Extensions
module Page
module Listed
extend ActiveSupport::Concern
included do
field :listed, :type => Boolean, :default => true
end
end
end
end
end

View File

@ -1,107 +1,105 @@
module Models
module Extensions
module Page
module Parse
module Extensions
module Page
module Parse
extend ActiveSupport::Concern
extend ActiveSupport::Concern
included do
field :serialized_template, :type => Binary
field :template_dependencies, :type => Array, :default => []
field :snippet_dependencies, :type => Array, :default => []
included do
field :serialized_template, :type => Binary
field :template_dependencies, :type => Array, :default => []
field :snippet_dependencies, :type => Array, :default => []
attr_reader :template_changed
attr_reader :template_changed
before_validation :serialize_template
after_save :update_template_descendants
before_validation :serialize_template
after_save :update_template_descendants
validate :template_must_be_valid
validate :template_must_be_valid
scope :pages, lambda { |domain| { :any_in => { :domains => [*domain] } } }
scope :pages, lambda { |domain| { :any_in => { :domains => [*domain] } } }
end
module InstanceMethods
def template
@template ||= Marshal.load(read_attribute(:serialized_template).to_s) rescue nil
end
module InstanceMethods
protected
def template
@template ||= Marshal.load(read_attribute(:serialized_template).to_s) rescue nil
end
def serialize_template
if self.new_record? || self.raw_template_changed?
@template_changed = true
protected
@parsing_errors = []
def serialize_template
if self.new_record? || self.raw_template_changed?
@template_changed = true
@parsing_errors = []
begin
self._parse_and_serialize_template
rescue ::Liquid::SyntaxError => error
@parsing_errors << I18n.t(:liquid_syntax, :fullpath => self.fullpath, :error => error.to_s,:scope => [:errors, :messages])
rescue ::Locomotive::Liquid::PageNotFound => error
@parsing_errors << I18n.t(:liquid_extend, :fullpath => self.fullpath,:scope => [:errors, :messages])
end
begin
self._parse_and_serialize_template
rescue ::Liquid::SyntaxError => error
@parsing_errors << I18n.t(:liquid_syntax, :fullpath => self.fullpath, :error => error.to_s,:scope => [:errors, :messages])
rescue ::Locomotive::Liquid::PageNotFound => error
@parsing_errors << I18n.t(:liquid_extend, :fullpath => self.fullpath,:scope => [:errors, :messages])
end
end
end
def _parse_and_serialize_template(context = {})
self.parse(context)
self._serialize_template
def _parse_and_serialize_template(context = {})
self.parse(context)
self._serialize_template
end
def _serialize_template
self.serialized_template = BSON::Binary.new(Marshal.dump(@template))
end
def parse(context = {})
self.disable_all_editable_elements
default_context = { :site => self.site, :page => self, :templates => [], :snippets => [] }
context = default_context.merge(context)
@template = ::Liquid::Template.parse(self.raw_template, context)
self.template_dependencies = context[:templates]
self.snippet_dependencies = context[:snippets]
@template.root.context.clear
end
def template_must_be_valid
@parsing_errors.try(:each) { |msg| self.errors.add :template, msg }
end
def update_template_descendants
return unless @template_changed == true
# we admit at this point that the current template is up-to-date
template_descendants = self.site.pages.any_in(:template_dependencies => [self.id]).to_a
# group them by fullpath for better performance
cached = template_descendants.inject({}) { |memo, page| memo[page.fullpath] = page; memo }
self._update_direct_template_descendants(template_descendants, cached)
# finally save them all
template_descendants.map(&:save)
end
def _update_direct_template_descendants(template_descendants, cached)
direct_descendants = template_descendants.select do |page|
((page.template_dependencies || []) - (self.template_dependencies || [])).size == 1
end
def _serialize_template
self.serialized_template = BSON::Binary.new(Marshal.dump(@template))
direct_descendants.each do |page|
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })
page.send(:_update_direct_template_descendants, template_descendants, cached)
end
def parse(context = {})
self.disable_all_editable_elements
default_context = { :site => self.site, :page => self, :templates => [], :snippets => [] }
context = default_context.merge(context)
@template = ::Liquid::Template.parse(self.raw_template, context)
self.template_dependencies = context[:templates]
self.snippet_dependencies = context[:snippets]
@template.root.context.clear
end
def template_must_be_valid
@parsing_errors.try(:each) { |msg| self.errors.add :template, msg }
end
def update_template_descendants
return unless @template_changed == true
# we admit at this point that the current template is up-to-date
template_descendants = self.site.pages.any_in(:template_dependencies => [self.id]).to_a
# group them by fullpath for better performance
cached = template_descendants.inject({}) { |memo, page| memo[page.fullpath] = page; memo }
self._update_direct_template_descendants(template_descendants, cached)
# finally save them all
template_descendants.map(&:save)
end
def _update_direct_template_descendants(template_descendants, cached)
direct_descendants = template_descendants.select do |page|
((page.template_dependencies || []) - (self.template_dependencies || [])).size == 1
end
direct_descendants.each do |page|
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })
page.send(:_update_direct_template_descendants, template_descendants, cached)
end
end
end
end
end
end
end

View File

@ -1,25 +1,21 @@
module Models
module Extensions
module Page
module Redirect
module Extensions
module Page
module Redirect
extend ActiveSupport::Concern
extend ActiveSupport::Concern
included do
included do
field :redirect, :type => Boolean, :default => false
field :redirect, :type => Boolean, :default => false
field :redirect_url, :type => String
field :redirect_url, :type => String
validates_presence_of :redirect_url, :if => :redirect
validates_presence_of :redirect_url, :if => :redirect
validates_format_of :redirect_url, :with => Locomotive::Regexps::URL, :allow_blank => true
end
validates_format_of :redirect_url, :with => Locomotive::Regexps::URL, :allow_blank => true
end
end
end
end
end

View File

@ -1,13 +1,11 @@
module Models
module Extensions
module Page
module Render
def render(context)
self.template.render(context)
end
module Extensions
module Page
module Render
def render(context)
self.template.render(context)
end
end
end
end
end

View File

@ -1,32 +1,28 @@
module Models
module Extensions
module Page
module Templatized
module Extensions
module Page
module Templatized
extend ActiveSupport::Concern
extend ActiveSupport::Concern
included do
included do
referenced_in :content_type
referenced_in :content_type
field :templatized, :type => Boolean, :default => false
field :templatized, :type => Boolean, :default => false
field :content_type_visible_column
field :content_type_visible_column
before_validation :set_slug_if_templatized
end
before_validation :set_slug_if_templatized
end
module InstanceMethods
def set_slug_if_templatized
self.slug = 'content_type_template' if self.templatized?
end
module InstanceMethods
def set_slug_if_templatized
self.slug = 'content_type_template' if self.templatized?
end
end
end
end
end
end

View File

@ -1,156 +1,154 @@
module Models
module Extensions
module Page
module Tree
module Extensions
module Page
module Tree
extend ActiveSupport::Concern
extend ActiveSupport::Concern
included do
include Mongoid::Acts::Tree
included do
include Mongoid::Acts::Tree
## fields ##
field :position, :type => Integer
## fields ##
field :position, :type => Integer
## behaviours ##
acts_as_tree :order => ['position', 'asc']
## behaviours ##
acts_as_tree :order => ['position', 'asc']
## callbacks ##
before_validation :reset_parent
before_save { |p| p.send(:write_attribute, :parent_id, nil) if p.parent_id.blank? }
before_save :change_parent
before_create { |p| p.send(:fix_position, false) }
before_create :add_to_list_bottom
before_destroy :remove_from_list
## callbacks ##
before_validation :reset_parent
before_save { |p| p.send(:write_attribute, :parent_id, nil) if p.parent_id.blank? }
before_save :change_parent
before_create { |p| p.send(:fix_position, false) }
before_create :add_to_list_bottom
before_destroy :remove_from_list
# Fixme (Didier L.): Instances methods are defined before the include itself
alias :fix_position :hacked_fix_position
alias :descendants :hacked_descendants
# Fixme (Didier L.): Instances methods are defined before the include itself
alias :fix_position :hacked_fix_position
alias :descendants :hacked_descendants
end
module ClassMethods
# Warning: used only in read-only
def quick_tree(site)
pages = site.pages.minimal_attributes.order_by([[:depth, :asc], [:position, :asc]]).to_a
tmp = []
while !pages.empty?
tmp << _quick_tree(pages.delete_at(0), pages)
end
tmp
end
module ClassMethods
def _quick_tree(current_page, pages)
i, children = 0, []
# Warning: used only in read-only
def quick_tree(site)
pages = site.pages.minimal_attributes.order_by([[:depth, :asc], [:position, :asc]]).to_a
while !pages.empty?
page = pages[i]
tmp = []
break if page.nil?
while !pages.empty?
tmp << _quick_tree(pages.delete_at(0), pages)
if page.parent_id == current_page.id
page = pages.delete_at(i)
children << _quick_tree(page, pages)
else
i += 1
end
tmp
end
def _quick_tree(current_page, pages)
i, children = 0, []
while !pages.empty?
page = pages[i]
break if page.nil?
if page.parent_id == current_page.id
page = pages.delete_at(i)
children << _quick_tree(page, pages)
else
i += 1
end
end
current_page.instance_eval do
def children=(list); @children = list; end
def children; @children || []; end
end
current_page.children = children
current_page
current_page.instance_eval do
def children=(list); @children = list; end
def children; @children || []; end
end
current_page.children = children
current_page
end
module InstanceMethods
end
def children?
self.class.where(self.parent_id_field => self.id).count
module InstanceMethods
def children?
self.class.where(self.parent_id_field => self.id).count
end
def children_with_minimal_attributes
self.class.where(self.parent_id_field => self.id).
order_by(self.tree_order).
minimal_attributes
end
def sort_children!(ids)
ids.each_with_index do |id, position|
child = self.children.detect { |p| p._id == BSON::ObjectId(id) }
child.position = position
child.save
end
end
def children_with_minimal_attributes
self.class.where(self.parent_id_field => self.id).
order_by(self.tree_order).
minimal_attributes
end
def parent=(owner) # missing in acts_as_tree
@_parent = owner
self.fix_position(false)
self.instance_variable_set :@_will_move, true
end
def sort_children!(ids)
ids.each_with_index do |id, position|
child = self.children.detect { |p| p._id == BSON::ObjectId(id) }
child.position = position
child.save
end
end
def hacked_descendants
return [] if new_record?
self.class.all_in(path_field => [self._id]).order_by tree_order
end
def parent=(owner) # missing in acts_as_tree
@_parent = owner
protected
def change_parent
if self.parent_id_changed?
self.fix_position(false)
unless self.parent_id_was.nil?
self.position = nil # make it move to bottom
self.add_to_list_bottom
end
self.instance_variable_set :@_will_move, true
end
def hacked_descendants
return [] if new_record?
self.class.all_in(path_field => [self._id]).order_by tree_order
end
protected
def change_parent
if self.parent_id_changed?
self.fix_position(false)
unless self.parent_id_was.nil?
self.position = nil # make it move to bottom
self.add_to_list_bottom
end
self.instance_variable_set :@_will_move, true
end
end
def hacked_fix_position(perform_save = true)
if parent.nil?
self.write_attribute parent_id_field, nil
self[path_field] = []
self[depth_field] = 0
else
self.write_attribute parent_id_field, parent._id
self[path_field] = parent[path_field] + [parent._id]
self[depth_field] = parent[depth_field] + 1
self.save if perform_save
end
end
def reset_parent
if self.parent_id_changed?
@_parent = nil
end
end
def add_to_list_bottom
self.position ||= (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1
end
def remove_from_list
return if (self.site rescue nil).nil?
::Page.where(:parent_id => self.parent_id).and(:position.gt => self.position).each do |p|
p.position -= 1
p.save
end
end
end
def hacked_fix_position(perform_save = true)
if parent.nil?
self.write_attribute parent_id_field, nil
self[path_field] = []
self[depth_field] = 0
else
self.write_attribute parent_id_field, parent._id
self[path_field] = parent[path_field] + [parent._id]
self[depth_field] = parent[depth_field] + 1
self.save if perform_save
end
end
def reset_parent
if self.parent_id_changed?
@_parent = nil
end
end
def add_to_list_bottom
self.position ||= (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1
end
def remove_from_list
return if (self.site rescue nil).nil?
::Page.where(:parent_id => self.parent_id).and(:position.gt => self.position).each do |p|
p.position -= 1
p.save
end
end
end
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,35 +9,37 @@
= f.input :meta_keywords
= f.input :meta_description
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
- if manage_subdomain_or_domains?
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
= f.custom_input :subdomain, :css => 'path' do
%em
http://
= f.text_field :subdomain
\.
%em
= application_domain
- @site.domains_without_subdomain.each_with_index do |name, index|
%li{ :class => "item added #{'last' if index == @site.domains.size - 1}"}
= f.custom_input :subdomain, :css => 'path' do
%em
http://
= text_field_tag 'site[domains][]', name, :class => 'string label void domain'
&nbsp;
= error_on_domain(@site, name)
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
= f.text_field :subdomain
\.
%em
= application_domain
%li.item.template
%em
http://
= text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
&nbsp;
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span!= t('admin.buttons.new_item')
- 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
http://
= text_field_tag 'site[domains][]', name, :class => 'string label void domain'
&nbsp;
= error_on_domain(@site, name)
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%li.item.template
%em
http://
= text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
&nbsp;
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span!= t('admin.buttons.new_item')
= f.foldable_inputs :name => :memberships, :class => 'memberships' do
- @site.memberships.each_with_index do |membership, index|

View File

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

View File

@ -4,32 +4,34 @@
= f.foldable_inputs :name => :information, :style => "#{'display: none' unless @site.new_record?}" do
= f.input :name, :required => false
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
- if manage_subdomain_or_domains?
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
= f.custom_input :subdomain, :css => 'path' do
%em
http://
= f.text_field :subdomain
\.
%em
= application_domain
- @site.domains_without_subdomain.each_with_index do |name, index|
%li{ :class => "item added #{'last' if index == @site.domains.size - 1}"}
= f.custom_input :subdomain, :css => 'path' do
%em
http://
= text_field_tag 'site[domains][]', name, :class => 'string label void domain'
&nbsp;
= error_on_domain(@site, name)
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
= f.text_field :subdomain
\.
%em
= application_domain
%li.item.template
%em
http://
= text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
&nbsp;
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span!= t('admin.buttons.new_item')
- 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
http://
= text_field_tag 'site[domains][]', name, :class => 'string label void domain'
&nbsp;
= error_on_domain(@site, name)
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%li.item.template
%em
http://
= text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
&nbsp;
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span!= t('admin.buttons.new_item')

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)
domain, subdomain = domain_and_subdomain(request)
subdomain = 'www' if subdomain.blank?
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']}"
@current_site ||= Site.match_domain(request.host).first
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