get rid of warnings about InstanceMethods (deprecated) + make the engine work smoother with an existing app + clean code
This commit is contained in:
parent
25e08596ef
commit
fa36b95a9d
@ -1,15 +1,17 @@
|
|||||||
class Locomotive::ContentLocalePickerCell < Cell::Base
|
module Locomotive
|
||||||
|
class ContentLocalePickerCell < Cell::Base
|
||||||
|
|
||||||
def show(args)
|
def show(args)
|
||||||
site = args[:site]
|
site = args[:site]
|
||||||
locale = args[:locale].to_s
|
locale = args[:locale].to_s
|
||||||
|
|
||||||
if site.locales.empty? || site.locales.size < 2
|
if site.locales.empty? || site.locales.size < 2
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
@locales = site.locales - [locale]
|
@locales = site.locales - [locale]
|
||||||
render
|
render
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
@ -1,34 +1,36 @@
|
|||||||
class Locomotive::GlobalActionsCell < ::Locomotive::MenuCell
|
module Locomotive
|
||||||
|
class GlobalActionsCell < MenuCell
|
||||||
|
|
||||||
attr_reader :current_locomotive_account, :current_site_url
|
attr_reader :current_locomotive_account, :current_site_url
|
||||||
|
|
||||||
def show(args)
|
def show(args)
|
||||||
@current_locomotive_account = args[:current_locomotive_account]
|
@current_locomotive_account = args[:current_locomotive_account]
|
||||||
@current_site_url = args[:current_site_url]
|
@current_site_url = args[:current_site_url]
|
||||||
super
|
super
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def build_list
|
|
||||||
add :welcome, :url => edit_my_account_url, :i18n_options => {
|
|
||||||
:key => 'locomotive.shared.header.welcome',
|
|
||||||
:arg => :name,
|
|
||||||
:value => @current_locomotive_account.name
|
|
||||||
}
|
|
||||||
|
|
||||||
add :see, :url => current_site_url, :id => 'viewsite', :target => '_blank'
|
|
||||||
|
|
||||||
if Locomotive.config.multi_sites? && current_locomotive_account.sites.size > 1
|
|
||||||
add :switch, :url => '#', :id => 'sites-picker-link'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add :help, :url => '#', :class => 'tutorial', :id => 'help'
|
protected
|
||||||
add :logout, :url => destroy_locomotive_session_url, :confirm => t('locomotive.messages.confirm'), :method => :delete
|
|
||||||
end
|
|
||||||
|
|
||||||
def localize_label(label, options = {})
|
def build_list
|
||||||
I18n.t("locomotive.shared.header.#{label}", options)
|
add :welcome, :url => edit_my_account_url, :i18n_options => {
|
||||||
end
|
:key => 'locomotive.shared.header.welcome',
|
||||||
|
:arg => :name,
|
||||||
|
:value => @current_locomotive_account.name
|
||||||
|
}
|
||||||
|
|
||||||
end
|
add :see, :url => current_site_url, :id => 'viewsite', :target => '_blank'
|
||||||
|
|
||||||
|
if Locomotive.config.multi_sites? && current_locomotive_account.sites.size > 1
|
||||||
|
add :switch, :url => '#', :id => 'sites-picker-link'
|
||||||
|
end
|
||||||
|
|
||||||
|
add :help, :url => '#', :class => 'tutorial', :id => 'help'
|
||||||
|
add :logout, :url => destroy_locomotive_session_url, :confirm => t('locomotive.messages.confirm'), :method => :delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def localize_label(label, options = {})
|
||||||
|
I18n.t("locomotive.shared.header.#{label}", options)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,10 +1,12 @@
|
|||||||
class Locomotive::MainMenuCell < ::Locomotive::MenuCell
|
module Locomotive
|
||||||
|
class MainMenuCell < MenuCell
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def build_list
|
||||||
|
add :contents, :url => pages_url
|
||||||
|
add :settings, :url => edit_current_site_url
|
||||||
|
end
|
||||||
|
|
||||||
def build_list
|
|
||||||
add :contents, :url => pages_url
|
|
||||||
add :settings, :url => edit_current_site_url
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
@ -1,100 +1,102 @@
|
|||||||
class Locomotive::MenuCell < Cell::Rails
|
module Locomotive
|
||||||
|
class MenuCell < Cell::Rails
|
||||||
|
|
||||||
include ::Locomotive::Engine.routes.url_helpers
|
include ::Locomotive::Engine.routes.url_helpers
|
||||||
|
|
||||||
delegate :sections, :to => :parent_controller
|
delegate :main_app, :sections, :to => :parent_controller
|
||||||
|
|
||||||
attr_accessor :list
|
attr_accessor :list
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super
|
super
|
||||||
self.list = []
|
self.list = []
|
||||||
end
|
|
||||||
|
|
||||||
def show(args = {})
|
|
||||||
self.build_list
|
|
||||||
render
|
|
||||||
end
|
|
||||||
|
|
||||||
def url_options
|
|
||||||
super.reverse_merge(
|
|
||||||
:host => request.host_with_port,
|
|
||||||
:protocol => request.protocol,
|
|
||||||
:_path_segments => request.symbolized_path_parameters
|
|
||||||
).merge(:script_name => request.script_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
class MenuProxy
|
|
||||||
|
|
||||||
def initialize(cell)
|
|
||||||
@cell = cell
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(meth, *args)
|
def show(args = {})
|
||||||
@cell.send(meth, *args)
|
self.build_list
|
||||||
|
render
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
def url_options
|
||||||
|
super.reverse_merge(
|
||||||
|
:host => request.host_with_port,
|
||||||
|
:protocol => request.protocol,
|
||||||
|
:_path_segments => request.symbolized_path_parameters
|
||||||
|
).merge(:script_name => request.script_name)
|
||||||
|
end
|
||||||
|
|
||||||
def self.update_for(name, &block)
|
class MenuProxy
|
||||||
method_name = "build_list_with_#{name}".to_sym
|
|
||||||
previous_method_name = "build_list_without_#{name}".to_sym
|
|
||||||
|
|
||||||
unless self.instance_methods.include?(method_name) # prevents the method to be called twice which will raise a "stack level too deep" exception
|
def initialize(cell)
|
||||||
|
@cell = cell
|
||||||
self.send(:define_method, method_name) do
|
|
||||||
self.send(previous_method_name)
|
|
||||||
block.call(MenuProxy.new(self))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Note: this might cause "stack level too deep" if called twice for the same name
|
def method_missing(meth, *args)
|
||||||
alias_method_chain :build_list, name.to_sym
|
@cell.send(meth, *args)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
def self.update_for(name, &block)
|
||||||
|
method_name = "build_list_with_#{name}".to_sym
|
||||||
|
previous_method_name = "build_list_without_#{name}".to_sym
|
||||||
|
|
||||||
def build_list
|
unless self.instance_methods.include?(method_name) # prevents the method to be called twice which will raise a "stack level too deep" exception
|
||||||
raise 'the build_list method must be overridden'
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_item(name, attributes)
|
self.send(:define_method, method_name) do
|
||||||
unless attributes.key?(:label)
|
self.send(previous_method_name)
|
||||||
attributes[:label] = localize_label(name)
|
block.call(MenuProxy.new(self))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Note: this might cause "stack level too deep" if called twice for the same name
|
||||||
|
alias_method_chain :build_list, name.to_sym
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes.merge!(:name => name, :class => name.to_s.dasherize.downcase)
|
protected
|
||||||
end
|
|
||||||
|
|
||||||
def add(name, attributes)
|
def build_list
|
||||||
self.list << build_item(name, attributes)
|
raise 'the build_list method must be overridden'
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_after(pivot, name, attributes)
|
def build_item(name, attributes)
|
||||||
index = self.list.index { |i| i[:name] == pivot }
|
unless attributes.key?(:label)
|
||||||
self.list.insert(index + 1, self.build_item(name, attributes))
|
attributes[:label] = localize_label(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_before(pivot, name, attributes)
|
attributes.merge!(:name => name, :class => name.to_s.dasherize.downcase)
|
||||||
index = self.list.index { |i| i[:name] == pivot }
|
end
|
||||||
self.list.insert(index, self.build_item(name, attributes))
|
|
||||||
end
|
|
||||||
|
|
||||||
def modify(name, attributes)
|
def add(name, attributes)
|
||||||
self.find(name).merge!(attributes)
|
self.list << build_item(name, attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove(name)
|
def add_after(pivot, name, attributes)
|
||||||
self.list.delete_if { |i| i[:name] == name }
|
index = self.list.index { |i| i[:name] == pivot }
|
||||||
end
|
self.list.insert(index + 1, self.build_item(name, attributes))
|
||||||
|
end
|
||||||
|
|
||||||
def find(name)
|
def add_before(pivot, name, attributes)
|
||||||
self.list.detect { |i| i[:name] == name }
|
index = self.list.index { |i| i[:name] == pivot }
|
||||||
end
|
self.list.insert(index, self.build_item(name, attributes))
|
||||||
|
end
|
||||||
|
|
||||||
def localize_label(label)
|
def modify(name, attributes)
|
||||||
I18n.t("locomotive.shared.menu.#{label}")
|
self.find(name).merge!(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
def remove(name)
|
||||||
|
self.list.delete_if { |i| i[:name] == name }
|
||||||
|
end
|
||||||
|
|
||||||
|
def find(name)
|
||||||
|
self.list.detect { |i| i[:name] == name }
|
||||||
|
end
|
||||||
|
|
||||||
|
def localize_label(label)
|
||||||
|
I18n.t("locomotive.shared.menu.#{label}")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,11 +1,13 @@
|
|||||||
class Locomotive::SettingsMenuCell < ::Locomotive::SubMenuCell
|
module Locomotive
|
||||||
|
class SettingsMenuCell < SubMenuCell
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def build_list
|
||||||
|
add :site, :url => edit_current_site_url
|
||||||
|
add :theme_assets, :url => theme_assets_url
|
||||||
|
add :account, :url => edit_my_account_url
|
||||||
|
end
|
||||||
|
|
||||||
def build_list
|
|
||||||
add :site, :url => edit_current_site_url
|
|
||||||
add :theme_assets, :url => theme_assets_url
|
|
||||||
add :account, :url => edit_my_account_url
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
@ -1,11 +1,13 @@
|
|||||||
class Locomotive::SubMenuCell < ::Locomotive::MenuCell
|
module Locomotive
|
||||||
|
class SubMenuCell < MenuCell
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def build_item(name, attributes)
|
||||||
|
item = super
|
||||||
|
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
|
||||||
|
item.merge(:class => enhanced_class)
|
||||||
|
end
|
||||||
|
|
||||||
def build_item(name, attributes)
|
|
||||||
item = super
|
|
||||||
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
|
|
||||||
item.merge(:class => enhanced_class)
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
@ -14,37 +14,33 @@ module Locomotive
|
|||||||
validate :item_template_must_be_valid
|
validate :item_template_must_be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def item_template
|
||||||
|
@item_template ||= Marshal.load(read_attribute(:serialized_item_template).to_s) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
def item_template
|
protected
|
||||||
@item_template ||= Marshal.load(read_attribute(:serialized_item_template).to_s) rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
def serialize_item_template
|
||||||
|
if self.new_record? || self.raw_item_template_changed?
|
||||||
|
@item_parsing_errors = []
|
||||||
|
|
||||||
def serialize_item_template
|
begin
|
||||||
if self.new_record? || self.raw_item_template_changed?
|
self._parse_and_serialize_item_template
|
||||||
@item_parsing_errors = []
|
rescue ::Liquid::SyntaxError => error
|
||||||
|
@item_parsing_errors << I18n.t(:liquid_syntax, :error => error.to_s, :scope => [:errors, :messages])
|
||||||
begin
|
|
||||||
self._parse_and_serialize_item_template
|
|
||||||
rescue ::Liquid::SyntaxError => error
|
|
||||||
@item_parsing_errors << I18n.t(:liquid_syntax, :error => error.to_s, :scope => [:errors, :messages])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def _parse_and_serialize_item_template
|
def _parse_and_serialize_item_template
|
||||||
item_template = ::Liquid::Template.parse(self.raw_item_template, {})
|
item_template = ::Liquid::Template.parse(self.raw_item_template, {})
|
||||||
self.serialized_item_template = BSON::Binary.new(Marshal.dump(item_template))
|
self.serialized_item_template = BSON::Binary.new(Marshal.dump(item_template))
|
||||||
|
end
|
||||||
|
|
||||||
|
def item_template_must_be_valid
|
||||||
|
@item_parsing_errors.try(:each) do |msg|
|
||||||
|
%w(item_template raw_item_template).each { |field| self.errors.add field.to_sym, msg }
|
||||||
end
|
end
|
||||||
|
|
||||||
def item_template_must_be_valid
|
|
||||||
@item_parsing_errors.try(:each) do |msg|
|
|
||||||
%w(item_template raw_item_template).each { |field| self.errors.add field.to_sym, msg }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -16,71 +16,49 @@ module Locomotive
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
# Returns the fullpath of a page in the context of the current locale (I18n.locale)
|
||||||
|
# or the one passed in parameter. It also depends on the default site locale.
|
||||||
|
#
|
||||||
|
# Ex:
|
||||||
|
# For a site with its default site locale to 'en'
|
||||||
|
# # context 1: i18n.locale is 'en'
|
||||||
|
# contact_us.fullpath <= 'contact_us'
|
||||||
|
#
|
||||||
|
# # context 2: i18n.locale is 'fr'
|
||||||
|
# contact_us.fullpath <= 'fr/nous_contacter'
|
||||||
|
#
|
||||||
|
# @params [ Page ] page The page we want the localized fullpath
|
||||||
|
# @params [ String ] locale The optional locale in place of the current one
|
||||||
|
#
|
||||||
|
# @returns [ String ] The localized fullpath according to the current locale
|
||||||
|
#
|
||||||
|
def localized_page_fullpath(page, locale = nil)
|
||||||
|
locale = (locale || I18n.locale).to_s
|
||||||
|
fullpath = page.fullpath_translations[locale] || page.fullpath_translations[self.default_locale]
|
||||||
|
|
||||||
# Returns the fullpath of a page in the context of the current locale (I18n.locale)
|
locale == self.default_locale ? fullpath : File.join(locale, fullpath)
|
||||||
# or the one passed in parameter. It also depends on the default site locale.
|
end
|
||||||
#
|
|
||||||
# Ex:
|
|
||||||
# For a site with its default site locale to 'en'
|
|
||||||
# # context 1: i18n.locale is 'en'
|
|
||||||
# contact_us.fullpath <= 'contact_us'
|
|
||||||
#
|
|
||||||
# # context 2: i18n.locale is 'fr'
|
|
||||||
# contact_us.fullpath <= 'fr/nous_contacter'
|
|
||||||
#
|
|
||||||
# @params [ Page ] page The page we want the localized fullpath
|
|
||||||
# @params [ String ] locale The optional locale in place of the current one
|
|
||||||
#
|
|
||||||
# @returns [ String ] The localized fullpath according to the current locale
|
|
||||||
#
|
|
||||||
def localized_page_fullpath(page, locale = nil)
|
|
||||||
locale = (locale || I18n.locale).to_s
|
|
||||||
fullpath = page.fullpath_translations[locale] || page.fullpath_translations[self.default_locale]
|
|
||||||
|
|
||||||
locale == self.default_locale ? fullpath : File.join(locale, fullpath)
|
def locales=(array)
|
||||||
end
|
array = [] if array.blank?; super(array)
|
||||||
|
end
|
||||||
|
|
||||||
def locales=(array)
|
def default_locale
|
||||||
array = [] if array.blank?; super(array)
|
self.locales.first || Locomotive.config.site_locales.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_locale
|
def locale_fallbacks(locale)
|
||||||
self.locales.first || Locomotive.config.site_locales.first
|
[locale.to_s] + (locales - [locale.to_s])
|
||||||
end
|
end
|
||||||
|
|
||||||
def locale_fallbacks(locale)
|
protected
|
||||||
[locale.to_s] + (locales - [locale.to_s])
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def add_default_locale
|
|
||||||
self.locales = [Locomotive.config.site_locales.first] if self.locales.blank?
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
|
||||||
# def add_missing_locales_for_all_pages
|
|
||||||
# if self.locales_changed?
|
|
||||||
# list = self.pages.to_a
|
|
||||||
#
|
|
||||||
# while !list.empty? do
|
|
||||||
# page = list.pop
|
|
||||||
# begin
|
|
||||||
# page.send(:set_slug_and_fullpath_for_all_locales, self.locales)
|
|
||||||
#
|
|
||||||
# page.save
|
|
||||||
#
|
|
||||||
# rescue TypeError => e
|
|
||||||
# list.insert(0, page)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
def add_default_locale
|
||||||
|
self.locales = [Locomotive.config.site_locales.first] if self.locales.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,5 +1,5 @@
|
|||||||
%h1
|
%h1
|
||||||
= link_to current_site.name, pages_url
|
= link_to current_site.name, locomotive.pages_url
|
||||||
|
|
||||||
= render_cell 'locomotive/global_actions', :show, :current_locomotive_account => current_locomotive_account, :current_site_url => current_site_public_url
|
= render_cell 'locomotive/global_actions', :show, :current_locomotive_account => current_locomotive_account, :current_site_url => current_site_public_url
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
- current_locomotive_account.sites.each do |site|
|
- current_locomotive_account.sites.each do |site|
|
||||||
- unless current_site._id == site._id
|
- unless current_site._id == site._id
|
||||||
%li
|
%li
|
||||||
= link_to site.name, pages_url(:host => site.full_subdomain, :port => request.port)
|
= link_to site.name, locomotive.pages_url(:host => site.full_subdomain, :port => request.port)
|
||||||
|
|
||||||
- if can?(:manage, Locomotive::Site)
|
- if can?(:manage, Locomotive::Site)
|
||||||
%p.action
|
%p.action
|
||||||
= link_to t('locomotive.sites_picker.new'), new_site_url
|
= link_to t('locomotive.sites_picker.new'), locomotive.new_site_url
|
19
config/initializers/locomotive_loaded_first.rb
Normal file
19
config/initializers/locomotive_loaded_first.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
require 'active_support/dependencies'
|
||||||
|
|
||||||
|
module ActiveSupport::Dependencies
|
||||||
|
|
||||||
|
alias_method :require_or_load_without_multiple, :require_or_load
|
||||||
|
|
||||||
|
def require_or_load(file_name, const_path = nil)
|
||||||
|
if file_name.starts_with?(Rails.root.to_s + '/app')
|
||||||
|
relative_name = file_name.gsub(Rails.root.to_s, '')
|
||||||
|
@engine_paths ||= Rails::Application::Railties.engines.collect{|engine| engine.config.root.to_s }
|
||||||
|
@engine_paths.each do |path|
|
||||||
|
engine_file = File.join(path, relative_name)
|
||||||
|
require_or_load_without_multiple(engine_file, const_path) if File.file?(engine_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
require_or_load_without_multiple(file_name, const_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -2,4 +2,4 @@ require 'locomotive/action_controller/locale_helpers'
|
|||||||
require 'locomotive/action_controller/section_helpers'
|
require 'locomotive/action_controller/section_helpers'
|
||||||
require 'locomotive/action_controller/url_helpers'
|
require 'locomotive/action_controller/url_helpers'
|
||||||
require 'locomotive/action_controller/responder'
|
require 'locomotive/action_controller/responder'
|
||||||
require 'locomotive/action_controller/public_responder'
|
require 'locomotive/action_controller/public_responder'
|
||||||
|
@ -8,42 +8,38 @@ module Locomotive
|
|||||||
helper_method :current_content_locale
|
helper_method :current_content_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def current_content_locale
|
||||||
|
::Mongoid::Fields::I18n.locale
|
||||||
|
end
|
||||||
|
|
||||||
def current_content_locale
|
def set_current_content_locale
|
||||||
::Mongoid::Fields::I18n.locale
|
if params[:content_locale].present?
|
||||||
|
session[:content_locale] = params[:content_locale]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_current_content_locale
|
unless current_site.locales.include?(session[:content_locale])
|
||||||
if params[:content_locale].present?
|
session[:content_locale] = current_site.default_locale
|
||||||
session[:content_locale] = params[:content_locale]
|
|
||||||
end
|
|
||||||
|
|
||||||
unless current_site.locales.include?(session[:content_locale])
|
|
||||||
session[:content_locale] = current_site.default_locale
|
|
||||||
end
|
|
||||||
|
|
||||||
::Mongoid::Fields::I18n.locale = session[:content_locale]
|
|
||||||
|
|
||||||
self.setup_i18n_fallbacks
|
|
||||||
|
|
||||||
# logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_back_office_locale
|
::Mongoid::Fields::I18n.locale = session[:content_locale]
|
||||||
::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
|
|
||||||
end
|
|
||||||
|
|
||||||
def back_to_default_site_locale
|
self.setup_i18n_fallbacks
|
||||||
session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_i18n_fallbacks
|
# logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}"
|
||||||
(current_site.locales || []).each do |locale|
|
end
|
||||||
::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def set_back_office_locale
|
||||||
|
::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def back_to_default_site_locale
|
||||||
|
session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_i18n_fallbacks
|
||||||
|
(current_site.locales || []).each do |locale|
|
||||||
|
::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -4,16 +4,12 @@ module Locomotive
|
|||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
module InstanceMethods
|
def sections(key = nil)
|
||||||
|
if !key.nil? && key.to_sym == :sub
|
||||||
def sections(key = nil)
|
@locomotive_sections[:sub] || self.controller_name.dasherize
|
||||||
if !key.nil? && key.to_sym == :sub
|
else
|
||||||
@locomotive_sections[:sub] || self.controller_name.dasherize
|
@locomotive_sections[:main]
|
||||||
else
|
|
||||||
@locomotive_sections[:main]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
@ -8,33 +8,30 @@ module Locomotive
|
|||||||
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url
|
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def current_site_public_url
|
||||||
|
request.protocol + request.host_with_port
|
||||||
|
end
|
||||||
|
|
||||||
def current_site_public_url
|
def switch_to_site_url(site, options = {})
|
||||||
request.protocol + request.host_with_port
|
options = { :fullpath => true, :protocol => true }.merge(options)
|
||||||
|
|
||||||
|
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
||||||
|
url += ":#{request.port}" if request.port != 80
|
||||||
|
|
||||||
|
url = File.join(url, request.fullpath) if options[:fullpath]
|
||||||
|
url = "http://#{url}" if options[:protocol]
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
|
def public_page_url(page, options = {})
|
||||||
|
if content = options.delete(:content)
|
||||||
|
File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
||||||
|
else
|
||||||
|
File.join(current_site_public_url, page.fullpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def switch_to_site_url(site, options = {})
|
|
||||||
options = { :fullpath => true, :protocol => true }.merge(options)
|
|
||||||
|
|
||||||
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
|
||||||
url += ":#{request.port}" if request.port != 80
|
|
||||||
|
|
||||||
url = File.join(url, request.fullpath) if options[:fullpath]
|
|
||||||
url = "http://#{url}" if options[:protocol]
|
|
||||||
url
|
|
||||||
end
|
|
||||||
|
|
||||||
def public_page_url(page, options = {})
|
|
||||||
if content = options.delete(:content)
|
|
||||||
File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
|
||||||
else
|
|
||||||
File.join(current_site_public_url, page.fullpath)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -12,46 +12,43 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
protected
|
||||||
|
|
||||||
protected
|
def fetch_site
|
||||||
|
Locomotive.log "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
||||||
|
|
||||||
def fetch_site
|
if Locomotive.config.multi_sites?
|
||||||
Locomotive.log "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
@current_site ||= Site.match_domain(request.host).first
|
||||||
|
else
|
||||||
if Locomotive.config.multi_sites?
|
@current_site ||= Site.first
|
||||||
@current_site ||= Site.match_domain(request.host).first
|
|
||||||
else
|
|
||||||
@current_site ||= Site.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def current_site
|
def current_site
|
||||||
@current_site || fetch_site
|
@current_site || fetch_site
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_site
|
def require_site
|
||||||
return true if current_site
|
return true if current_site
|
||||||
|
|
||||||
redirect_to installation_url and return false if Locomotive::Account.count == 0 || Locomotive::Site.count == 0
|
redirect_to installation_url and return false if Locomotive::Account.count == 0 || Locomotive::Site.count == 0
|
||||||
|
|
||||||
render_no_site_error and return false
|
render_no_site_error and return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_no_site_error
|
def render_no_site_error
|
||||||
render :template => '/Locomotive/errors/no_site', :layout => false, :status => :not_found
|
render :template => '/Locomotive/errors/no_site', :layout => false, :status => :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_site_membership
|
def validate_site_membership
|
||||||
return true if current_site.present? && current_site.accounts.include?(current_locomotive_account)
|
return true if current_site.present? && current_site.accounts.include?(current_locomotive_account)
|
||||||
|
|
||||||
sign_out(current_locomotive_account)
|
|
||||||
flash[:alert] = I18n.t(:no_membership, :scope => [:devise, :failure, :locomotive])
|
|
||||||
redirect_to new_locomotive_account_session_url and return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
sign_out(current_locomotive_account)
|
||||||
|
flash[:alert] = I18n.t(:no_membership, :scope => [:devise, :failure, :locomotive])
|
||||||
|
redirect_to new_locomotive_account_session_url and return false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,17 +29,12 @@ Gem::Specification.new do |s|
|
|||||||
s.add_dependency 'bson_ext', '~> 1.5.2'
|
s.add_dependency 'bson_ext', '~> 1.5.2'
|
||||||
s.add_dependency 'mongoid', '~> 2.4.3'
|
s.add_dependency 'mongoid', '~> 2.4.3'
|
||||||
s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2'
|
s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2'
|
||||||
# s.add_dependency 'locomotive_mongoid_acts_as_tree', '~> 0.1.5.8'
|
|
||||||
|
|
||||||
s.add_dependency 'custom_fields', '~> 2.0.0.rc3'
|
s.add_dependency 'custom_fields', '~> 2.0.0.rc3'
|
||||||
|
|
||||||
s.add_dependency 'kaminari', '~> 0.13.0'
|
s.add_dependency 'kaminari', '~> 0.13.0'
|
||||||
|
|
||||||
s.add_dependency 'haml', '~> 3.1.4'
|
s.add_dependency 'haml', '~> 3.1.4'
|
||||||
# # s.add_dependency 'sass-rails', '~> 3.1.5'
|
|
||||||
# # s.add_dependency 'coffee-script', '~> 2.2.0'
|
|
||||||
# # s.add_dependency 'uglifier', '~> 1.2.2'
|
|
||||||
# # # s.add_dependency 'compass', '~> 0.12.rc.0'
|
|
||||||
s.add_dependency 'jquery-rails', '~> 1.0.16'
|
s.add_dependency 'jquery-rails', '~> 1.0.16'
|
||||||
s.add_dependency 'rails-backbone', '~> 0.6.1'
|
s.add_dependency 'rails-backbone', '~> 0.6.1'
|
||||||
s.add_dependency 'codemirror-rails', '~> 2.21'
|
s.add_dependency 'codemirror-rails', '~> 2.21'
|
||||||
|
9
spec/dummy/app/cells/locomotive/main_menu_cell.rb
Normal file
9
spec/dummy/app/cells/locomotive/main_menu_cell.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module Locomotive
|
||||||
|
class MainMenuCell < MenuCell
|
||||||
|
|
||||||
|
update_for :foo do |new_menu|
|
||||||
|
new_menu.add_before :settings, :foo, :url => new_menu.main_app.foo_url
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,8 +1,10 @@
|
|||||||
class FooController < ApplicationController
|
class FooController < Locomotive::BaseController
|
||||||
|
|
||||||
|
skip_load_and_authorize_resource
|
||||||
|
|
||||||
|
sections :foo
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render :text => 'Foo'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
1
spec/dummy/app/views/foo/index.html.haml
Normal file
1
spec/dummy/app/views/foo/index.html.haml
Normal file
@ -0,0 +1 @@
|
|||||||
|
%p Hello world !!!
|
@ -3,3 +3,8 @@
|
|||||||
|
|
||||||
en:
|
en:
|
||||||
hello: "Hello world"
|
hello: "Hello world"
|
||||||
|
|
||||||
|
locomotive:
|
||||||
|
shared:
|
||||||
|
menu:
|
||||||
|
foo: My FOO menu
|
Loading…
Reference in New Issue
Block a user