Sha256: 155e33956ac7b691c305e317b22636b97130073dfde320658d8449b90d7c926e

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

module Spree
  module Core
    module ControllerHelpers
      module Common
        extend ActiveSupport::Concern
        included do
          helper_method :title
          helper_method :title=
          helper_method :accurate_title

          layout :get_layout

          protected

          # can be used in views as well as controllers.
          # e.g. <% self.title = 'This is a custom title for this view' %>
          attr_writer :title

          def title
            title_string = @title.present? ? @title : accurate_title
            if title_string.present?
              if Spree::Config[:always_put_site_name_in_title]
                [title_string, default_title].join(" #{Spree::Config[:title_site_name_separator]} ")
              else
                title_string
              end
            else
              default_title
            end
          end

          def default_title
            current_store.name
          end

          # this is a hook for subclasses to provide title
          def accurate_title
            current_store.seo_title
          end

          private

          def set_user_language
            ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
              ControllerHelpers::Common#set_user_language is deprecated and will be removed in Spree 5.0.
              Please use `before_action :set_locale` instead
            DEPRECATION

            set_locale
          end

          # Returns which layout to render.
          #
          # You can set the layout you want to render inside your Spree configuration with the +:layout+ option.
          #
          # Default layout is: +app/views/spree/layouts/spree_application+
          #
          def get_layout
            layout ||= Spree::Config[:layout]
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spree_core-4.2.7 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.6 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.5 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.4 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.3.1 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.3 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.2 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.1 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.0 lib/spree/core/controller_helpers/common.rb
spree_core-4.2.0.rc5 lib/spree/core/controller_helpers/common.rb