Sha256: d0ca12c12c12b91e93ffd0fbd4b7a9be46d7d304ce31b20056ba16b877af3a15

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Application helpers
  #
  module ApplicationHelper
    ##
    # Frontend resource permalink.
    #
    # Same as `frontend_page_path` except it prints out nested resources in a
    # nice way.
    #
    # Example
    #   <%= frontend_resource_path('amazing/grace') %> #=> /amazing/grace
    #   <%= frontend_resource_path(@page) %> #=> /amazing/grace
    #
    # @return [String] frontend resource permalink
    #
    def frontend_resource_path(resource)
      permalink_path = proc do |permalink|
        archangel.frontend_page_path(permalink).sub("%2F", "/")
      end

      return permalink_path.call(resource) unless resource.class == Page
      return archangel.frontend_root_path if resource.homepage?

      permalink_path.call(resource.permalink)
    end

    ##
    # Site locale. Default `en`
    #
    # Example
    #   <%= locale %> #=> "en"
    #
    # @return [String] site locale
    #
    def locale
      current_site.locale || Archangel::LANGUAGE_DEFAULT
    end

    ##
    # Language direction ("ltr" or "rtl"). Default `ltr`
    #
    # Example
    #   <%= text_direction %> #=> "ltr"
    #
    # @return [String] language direction
    #
    def text_direction
      Archangel.t("language.#{locale}.direction", default: "ltr")
    end

    ##
    # Check if active backend menu for a controller
    #
    # Example
    #   <%= active_backend_menu_for("users") %> #=> true
    #   <%= active_backend_menu_for("pages") %> #=> false
    #
    # @return [Boolean] if current controller
    #
    def active_backend_menu_for(ctrlr)
      params.fetch(:controller) == "archangel/backend/#{ctrlr}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
archangel-0.4.0 app/helpers/archangel/application_helper.rb