Sha256: c8ef97547b6361a18d92b241f88f5f31f0f5aadd668fd44a181a13360315c1a3

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8

module PagesCore
  module PagePathHelper
    def page_path(locale, page, options = {})
      page.localize(locale) do |p|
        if p.full_path? && PagesCore.config.localizations?
          "/#{locale}/" + URI.escape(p.full_path)
        elsif p.full_path?
          "/" + URI.escape(p.full_path)
        else
          super(locale, p, options)
        end
      end
    end

    def page_url(page_or_locale, page = nil, opts = {})
      locale, page = page_url_locale_and_page(page_or_locale, page, opts)
      page.localize(locale) do |p|
        if p.redirects?
          p.redirect_path(locale: locale)
        elsif p.full_path
          "#{request.protocol}#{request.host_with_port}" + page_path(locale, p)
        else
          super(locale, p, opts)
        end
      end
    end

    private

    def page_url_locale_and_page(page_or_locale, page, opts)
      return [page_or_locale, page] if page
      ActiveSupport::Deprecation.warn(
        "Calling page_url without locale is deprecated"
      )
      [(opts[:locale] || @locale), page_or_locale]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 app/helpers/pages_core/page_path_helper.rb