Sha256: d904891c07b7f4f8a39952f9720b46593994e577df77bdf3e44203062ff7c221

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

module Locomotive
  module ActionController
    class PublicResponder < ::ActionController::Responder

      def navigation_behavior(error)
        if get?
          raise error
        elsif has_errors? && default_action
          # get the content entry from the controller
          entry = self.controller.instance_variable_get :@entry

          if navigation_location =~ %r(^http://)
            # simple redirection for outside urls
            redirect_to navigation_location
          else
            # render the locomotive page
            self.controller.send :render_locomotive_page, navigation_location_for_locomotive, {
              entry.content_type.slug.singularize => entry.to_presenter(include_errors: true).as_json
            }
          end
        else
          entry = self.controller.instance_variable_get :@entry

          self.controller.flash['submitted_entry_id'] = entry.try(:_id).try(:to_s)

          # redirect to a locomotive page
          redirect_to navigation_location
        end
      end

      def navigation_location_for_locomotive
        locale, location = self.extract_locale_and_location

        if locale
          ::I18n.locale = ::Mongoid::Fields::I18n.locale = locale
          location
        else
          navigation_location
        end
      end

      protected

      def extract_locale_and_location
        locales = self.controller.send(:current_site).locales.join('|')

        if navigation_location =~ /\/(#{locales})+\/(.+)/
          [$1, $2]
        else
          nil
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
locomotive_cms-2.5.5 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.4 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.3 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.2 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.1 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.0 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.0.rc3 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.0.rc2 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.5.0.rc1 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.4.1 lib/locomotive/action_controller/public_responder.rb
locomotive_cms-2.4.0 lib/locomotive/action_controller/public_responder.rb