Sha256: 7287d2df855c9f85c7470c2938db4bec20f29d10e98fef8db021943dcf474e01

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

module Locomotive
  module ActionController
    module UrlHelpers

      extend ActiveSupport::Concern

      included do
        helper_method :current_site_public_url, :switch_to_site_url, :public_page_url
      end

      def current_site_public_url
        request.protocol + request.host_with_port
      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 = {})
        # Rails.logger.debug "[public_page_url] =====> #{page.attributes.inspect} / #{page.fullpath.inspect} / #{current_site_public_url}\n\n"

        locale    = options[:locale]
        fullpath  = current_site.localized_page_fullpath(page, locale)

        if content = options.delete(:content)
          fullpath = File.join(fullpath.gsub('content_type_template', ''), content._slug)
        end

        File.join(current_site_public_url, fullpath)
      end

    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotive_cms-2.2.2 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.2.1 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.2.0 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.1.4 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.1.3 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.1.2 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.1.1 lib/locomotive/action_controller/url_helpers.rb
locomotive_cms-2.1.0 lib/locomotive/action_controller/url_helpers.rb