From fa36b95a9d0578d04216db5be1455f272ef70a85 Mon Sep 17 00:00:00 2001 From: did Date: Mon, 6 Feb 2012 00:54:09 +0100 Subject: [PATCH] get rid of warnings about InstanceMethods (deprecated) + make the engine work smoother with an existing app + clean code --- .../locomotive/content_locale_picker_cell.rb | 22 +-- app/cells/locomotive/global_actions_cell.rb | 58 +++---- app/cells/locomotive/main_menu_cell.rb | 16 +- app/cells/locomotive/menu_cell.rb | 148 +++++++++--------- app/cells/locomotive/settings_menu_cell.rb | 18 ++- app/cells/locomotive/sub_menu_cell.rb | 18 ++- .../extensions/content_type/item_template.rb | 44 +++--- .../locomotive/extensions/site/locales.rb | 90 ++++------- app/views/locomotive/shared/_header.html.haml | 2 +- .../locomotive/shared/_site_picker.html.haml | 4 +- .../initializers/locomotive_loaded_first.rb | 19 +++ lib/locomotive/action_controller.rb | 2 +- .../action_controller/locale_helpers.rb | 52 +++--- .../action_controller/section_helpers.rb | 14 +- .../action_controller/url_helpers.rb | 43 +++-- lib/locomotive/routing/site_dispatcher.rb | 53 +++---- locomotive_cms.gemspec | 5 - .../app/cells/locomotive/main_menu_cell.rb | 9 ++ spec/dummy/app/controllers/foo_controller.rb | 8 +- spec/dummy/app/views/foo/index.html.haml | 1 + spec/dummy/config/locales/en.yml | 5 + 21 files changed, 317 insertions(+), 314 deletions(-) create mode 100644 config/initializers/locomotive_loaded_first.rb create mode 100644 spec/dummy/app/cells/locomotive/main_menu_cell.rb create mode 100644 spec/dummy/app/views/foo/index.html.haml diff --git a/app/cells/locomotive/content_locale_picker_cell.rb b/app/cells/locomotive/content_locale_picker_cell.rb index 26c687fe..9b7cbd53 100644 --- a/app/cells/locomotive/content_locale_picker_cell.rb +++ b/app/cells/locomotive/content_locale_picker_cell.rb @@ -1,15 +1,17 @@ -class Locomotive::ContentLocalePickerCell < Cell::Base +module Locomotive + class ContentLocalePickerCell < Cell::Base - def show(args) - site = args[:site] - locale = args[:locale].to_s + def show(args) + site = args[:site] + locale = args[:locale].to_s - if site.locales.empty? || site.locales.size < 2 - '' - else - @locales = site.locales - [locale] - render + if site.locales.empty? || site.locales.size < 2 + '' + else + @locales = site.locales - [locale] + render + end end - end + end end \ No newline at end of file diff --git a/app/cells/locomotive/global_actions_cell.rb b/app/cells/locomotive/global_actions_cell.rb index cd9b8537..944bad5d 100644 --- a/app/cells/locomotive/global_actions_cell.rb +++ b/app/cells/locomotive/global_actions_cell.rb @@ -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) - @current_locomotive_account = args[:current_locomotive_account] - @current_site_url = args[:current_site_url] - 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' + def show(args) + @current_locomotive_account = args[:current_locomotive_account] + @current_site_url = args[:current_site_url] + super end - add :help, :url => '#', :class => 'tutorial', :id => 'help' - add :logout, :url => destroy_locomotive_session_url, :confirm => t('locomotive.messages.confirm'), :method => :delete - end + protected - def localize_label(label, options = {}) - I18n.t("locomotive.shared.header.#{label}", options) - end + def build_list + add :welcome, :url => edit_my_account_url, :i18n_options => { + :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 \ No newline at end of file diff --git a/app/cells/locomotive/main_menu_cell.rb b/app/cells/locomotive/main_menu_cell.rb index 3712accb..9cbd0468 100644 --- a/app/cells/locomotive/main_menu_cell.rb +++ b/app/cells/locomotive/main_menu_cell.rb @@ -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 \ No newline at end of file diff --git a/app/cells/locomotive/menu_cell.rb b/app/cells/locomotive/menu_cell.rb index 128b4c59..794bd760 100644 --- a/app/cells/locomotive/menu_cell.rb +++ b/app/cells/locomotive/menu_cell.rb @@ -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) - super - 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 + def initialize(*args) + super + self.list = [] end - def method_missing(meth, *args) - @cell.send(meth, *args) + def show(args = {}) + self.build_list + render 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) - method_name = "build_list_with_#{name}".to_sym - previous_method_name = "build_list_without_#{name}".to_sym + class MenuProxy - unless self.instance_methods.include?(method_name) # prevents the method to be called twice which will raise a "stack level too deep" exception - - self.send(:define_method, method_name) do - self.send(previous_method_name) - block.call(MenuProxy.new(self)) + def initialize(cell) + @cell = cell end - # Note: this might cause "stack level too deep" if called twice for the same name - alias_method_chain :build_list, name.to_sym + def method_missing(meth, *args) + @cell.send(meth, *args) + 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 - raise 'the build_list method must be overridden' - end + unless self.instance_methods.include?(method_name) # prevents the method to be called twice which will raise a "stack level too deep" exception - def build_item(name, attributes) - unless attributes.key?(:label) - attributes[:label] = localize_label(name) + self.send(:define_method, method_name) do + self.send(previous_method_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 - attributes.merge!(:name => name, :class => name.to_s.dasherize.downcase) - end + protected - def add(name, attributes) - self.list << build_item(name, attributes) - end + def build_list + raise 'the build_list method must be overridden' + end - def add_after(pivot, name, attributes) - index = self.list.index { |i| i[:name] == pivot } - self.list.insert(index + 1, self.build_item(name, attributes)) - end + def build_item(name, attributes) + unless attributes.key?(:label) + attributes[:label] = localize_label(name) + end - def add_before(pivot, name, attributes) - index = self.list.index { |i| i[:name] == pivot } - self.list.insert(index, self.build_item(name, attributes)) - end + attributes.merge!(:name => name, :class => name.to_s.dasherize.downcase) + end - def modify(name, attributes) - self.find(name).merge!(attributes) - end + def add(name, attributes) + self.list << build_item(name, attributes) + end - def remove(name) - self.list.delete_if { |i| i[:name] == name } - end + def add_after(pivot, name, attributes) + index = self.list.index { |i| i[:name] == pivot } + self.list.insert(index + 1, self.build_item(name, attributes)) + end - def find(name) - self.list.detect { |i| i[:name] == name } - end + def add_before(pivot, name, attributes) + index = self.list.index { |i| i[:name] == pivot } + self.list.insert(index, self.build_item(name, attributes)) + end - def localize_label(label) - I18n.t("locomotive.shared.menu.#{label}") - end + def modify(name, attributes) + self.find(name).merge!(attributes) + 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 \ No newline at end of file diff --git a/app/cells/locomotive/settings_menu_cell.rb b/app/cells/locomotive/settings_menu_cell.rb index e8683067..8cac5030 100644 --- a/app/cells/locomotive/settings_menu_cell.rb +++ b/app/cells/locomotive/settings_menu_cell.rb @@ -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 \ No newline at end of file diff --git a/app/cells/locomotive/sub_menu_cell.rb b/app/cells/locomotive/sub_menu_cell.rb index 9e8dd1e0..56e2cacd 100644 --- a/app/cells/locomotive/sub_menu_cell.rb +++ b/app/cells/locomotive/sub_menu_cell.rb @@ -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 \ No newline at end of file diff --git a/app/models/locomotive/extensions/content_type/item_template.rb b/app/models/locomotive/extensions/content_type/item_template.rb index d1d1848f..6103caf8 100644 --- a/app/models/locomotive/extensions/content_type/item_template.rb +++ b/app/models/locomotive/extensions/content_type/item_template.rb @@ -14,37 +14,33 @@ module Locomotive validate :item_template_must_be_valid end - module InstanceMethods + def item_template + @item_template ||= Marshal.load(read_attribute(:serialized_item_template).to_s) rescue nil + end - def item_template - @item_template ||= Marshal.load(read_attribute(:serialized_item_template).to_s) rescue nil - end + protected - protected + def serialize_item_template + if self.new_record? || self.raw_item_template_changed? + @item_parsing_errors = [] - def serialize_item_template - if self.new_record? || self.raw_item_template_changed? - @item_parsing_errors = [] - - 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 + 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 - def _parse_and_serialize_item_template - item_template = ::Liquid::Template.parse(self.raw_item_template, {}) - self.serialized_item_template = BSON::Binary.new(Marshal.dump(item_template)) + def _parse_and_serialize_item_template + item_template = ::Liquid::Template.parse(self.raw_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 - - 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 diff --git a/app/models/locomotive/extensions/site/locales.rb b/app/models/locomotive/extensions/site/locales.rb index 611f390a..5fbfc8d4 100644 --- a/app/models/locomotive/extensions/site/locales.rb +++ b/app/models/locomotive/extensions/site/locales.rb @@ -16,71 +16,49 @@ module Locomotive 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) - # 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] + locale == self.default_locale ? fullpath : File.join(locale, fullpath) + end - locale == self.default_locale ? fullpath : File.join(locale, fullpath) - end + def locales=(array) + array = [] if array.blank?; super(array) + end - def locales=(array) - array = [] if array.blank?; super(array) - end + def default_locale + self.locales.first || Locomotive.config.site_locales.first + end - def default_locale - self.locales.first || Locomotive.config.site_locales.first - end + def locale_fallbacks(locale) + [locale.to_s] + (locales - [locale.to_s]) + end - def locale_fallbacks(locale) - [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 + protected + def add_default_locale + self.locales = [Locomotive.config.site_locales.first] if self.locales.blank? end end + end end end \ No newline at end of file diff --git a/app/views/locomotive/shared/_header.html.haml b/app/views/locomotive/shared/_header.html.haml index 4ddc7e96..a837c56c 100644 --- a/app/views/locomotive/shared/_header.html.haml +++ b/app/views/locomotive/shared/_header.html.haml @@ -1,5 +1,5 @@ %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 diff --git a/app/views/locomotive/shared/_site_picker.html.haml b/app/views/locomotive/shared/_site_picker.html.haml index 369565db..8f7da7bd 100644 --- a/app/views/locomotive/shared/_site_picker.html.haml +++ b/app/views/locomotive/shared/_site_picker.html.haml @@ -3,8 +3,8 @@ - current_locomotive_account.sites.each do |site| - unless current_site._id == site._id %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) %p.action - = link_to t('locomotive.sites_picker.new'), new_site_url \ No newline at end of file + = link_to t('locomotive.sites_picker.new'), locomotive.new_site_url \ No newline at end of file diff --git a/config/initializers/locomotive_loaded_first.rb b/config/initializers/locomotive_loaded_first.rb new file mode 100644 index 00000000..ad1c757d --- /dev/null +++ b/config/initializers/locomotive_loaded_first.rb @@ -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 diff --git a/lib/locomotive/action_controller.rb b/lib/locomotive/action_controller.rb index 28771bb3..4cc56ae0 100644 --- a/lib/locomotive/action_controller.rb +++ b/lib/locomotive/action_controller.rb @@ -2,4 +2,4 @@ require 'locomotive/action_controller/locale_helpers' require 'locomotive/action_controller/section_helpers' require 'locomotive/action_controller/url_helpers' require 'locomotive/action_controller/responder' -require 'locomotive/action_controller/public_responder' \ No newline at end of file +require 'locomotive/action_controller/public_responder' diff --git a/lib/locomotive/action_controller/locale_helpers.rb b/lib/locomotive/action_controller/locale_helpers.rb index 3834fe34..fb54b7c8 100644 --- a/lib/locomotive/action_controller/locale_helpers.rb +++ b/lib/locomotive/action_controller/locale_helpers.rb @@ -8,42 +8,38 @@ module Locomotive helper_method :current_content_locale end - module InstanceMethods + def current_content_locale + ::Mongoid::Fields::I18n.locale + end - def current_content_locale - ::Mongoid::Fields::I18n.locale + def set_current_content_locale + if params[:content_locale].present? + session[:content_locale] = params[:content_locale] end - def set_current_content_locale - if params[:content_locale].present? - 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}" + unless current_site.locales.include?(session[:content_locale]) + session[:content_locale] = current_site.default_locale end - def set_back_office_locale - ::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale - end + ::Mongoid::Fields::I18n.locale = session[:content_locale] - def back_to_default_site_locale - session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale - end + self.setup_i18n_fallbacks - def setup_i18n_fallbacks - (current_site.locales || []).each do |locale| - ::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale)) - end - end + # logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}" + 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 diff --git a/lib/locomotive/action_controller/section_helpers.rb b/lib/locomotive/action_controller/section_helpers.rb index 6cdbc67d..7e55f04e 100644 --- a/lib/locomotive/action_controller/section_helpers.rb +++ b/lib/locomotive/action_controller/section_helpers.rb @@ -4,16 +4,12 @@ module Locomotive extend ActiveSupport::Concern - module InstanceMethods - - def sections(key = nil) - if !key.nil? && key.to_sym == :sub - @locomotive_sections[:sub] || self.controller_name.dasherize - else - @locomotive_sections[:main] - end + def sections(key = nil) + if !key.nil? && key.to_sym == :sub + @locomotive_sections[:sub] || self.controller_name.dasherize + else + @locomotive_sections[:main] end - end module ClassMethods diff --git a/lib/locomotive/action_controller/url_helpers.rb b/lib/locomotive/action_controller/url_helpers.rb index b3851988..03707b43 100644 --- a/lib/locomotive/action_controller/url_helpers.rb +++ b/lib/locomotive/action_controller/url_helpers.rb @@ -8,33 +8,30 @@ module Locomotive helper_method :current_site_public_url, :switch_to_site_url, :public_page_url end - module InstanceMethods + def current_site_public_url + request.protocol + request.host_with_port + end - def current_site_public_url - request.protocol + request.host_with_port + 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 - - 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 \ No newline at end of file diff --git a/lib/locomotive/routing/site_dispatcher.rb b/lib/locomotive/routing/site_dispatcher.rb index 08d3e2dc..bf458316 100644 --- a/lib/locomotive/routing/site_dispatcher.rb +++ b/lib/locomotive/routing/site_dispatcher.rb @@ -12,46 +12,43 @@ module Locomotive end end - module InstanceMethods + protected - protected + def fetch_site + Locomotive.log "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}" - def fetch_site - Locomotive.log "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}" - - if Locomotive.config.multi_sites? - @current_site ||= Site.match_domain(request.host).first - else - @current_site ||= Site.first - end + if Locomotive.config.multi_sites? + @current_site ||= Site.match_domain(request.host).first + else + @current_site ||= Site.first end + end - def current_site - @current_site || fetch_site - end + def current_site + @current_site || fetch_site + end - def require_site - return true if current_site + def require_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 - end + render_no_site_error and return false + end - def render_no_site_error - render :template => '/Locomotive/errors/no_site', :layout => false, :status => :not_found - end + def render_no_site_error + render :template => '/Locomotive/errors/no_site', :layout => false, :status => :not_found + end - def validate_site_membership - 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 + def validate_site_membership + 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 end + end end diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 91134388..8dee6403 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -29,17 +29,12 @@ Gem::Specification.new do |s| s.add_dependency 'bson_ext', '~> 1.5.2' s.add_dependency 'mongoid', '~> 2.4.3' 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 'kaminari', '~> 0.13.0' 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 'rails-backbone', '~> 0.6.1' s.add_dependency 'codemirror-rails', '~> 2.21' diff --git a/spec/dummy/app/cells/locomotive/main_menu_cell.rb b/spec/dummy/app/cells/locomotive/main_menu_cell.rb new file mode 100644 index 00000000..fdcf84e0 --- /dev/null +++ b/spec/dummy/app/cells/locomotive/main_menu_cell.rb @@ -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 \ No newline at end of file diff --git a/spec/dummy/app/controllers/foo_controller.rb b/spec/dummy/app/controllers/foo_controller.rb index 6f6a96df..1924b646 100644 --- a/spec/dummy/app/controllers/foo_controller.rb +++ b/spec/dummy/app/controllers/foo_controller.rb @@ -1,8 +1,10 @@ -class FooController < ApplicationController +class FooController < Locomotive::BaseController + + skip_load_and_authorize_resource + + sections :foo def index - render :text => 'Foo' end - end \ No newline at end of file diff --git a/spec/dummy/app/views/foo/index.html.haml b/spec/dummy/app/views/foo/index.html.haml new file mode 100644 index 00000000..8b1aa9a3 --- /dev/null +++ b/spec/dummy/app/views/foo/index.html.haml @@ -0,0 +1 @@ +%p Hello world !!! \ No newline at end of file diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml index 179c14ca..a794b887 100644 --- a/spec/dummy/config/locales/en.yml +++ b/spec/dummy/config/locales/en.yml @@ -3,3 +3,8 @@ en: hello: "Hello world" + + locomotive: + shared: + menu: + foo: My FOO menu \ No newline at end of file