Sha256: 257da966d9185a307aca2d2177e2a23e208ad6bbbb7e5384a567c733628eb967

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

module RailsBase::AppearanceHelper
  APPEARANCE_MODE_COOKIE = "_#{Rails.application.class.parent_name}_appearance_mode".gsub(' ', '-').downcase
  APPEARANCE_MODE_ACTUAL_COOKIE = "_#{Rails.application.class.parent_name}_appearance_actual_mode".gsub(' ', '-').downcase
  APPEARANCE_TEXT_CLASS = RailsBase::Configuration::Display::Text::APPEARANCE_TEXT_CLASS

  VIEWPORT_EXTRA_SMALL = 'xs'.freeze
  VIEWPORT_SMALL = 'sm'.freeze
  VIEWPORT_MEDIUM = 'md'.freeze
  VIEWPORT_LARGE = 'lg'.freeze
  VIEWPORT_EXTRA_LARGE = 'xl'.freeze

  VIEWPORT_MOBILE_MAX = VIEWPORT_MEDIUM

  VIEWPORT_SIZES = {
    VIEWPORT_EXTRA_SMALL => 576,
    VIEWPORT_SMALL => 768,
    VIEWPORT_MEDIUM => 992,
    VIEWPORT_LARGE => 1200,
    VIEWPORT_EXTRA_LARGE => nil,
  }

  def footer_mode_case
    return :sticky if @_sticky_mode

    return :bottom if RailsBase.appearance.footer.content_bottom_or_sticky

    sticky_pages = RailsBase.appearance.footer.sticky_pages
    return if sticky_pages.empty?

    full_controller_path = "#{controller_path.camelize}Controller"
    return unless pages = sticky_pages[full_controller_path]

    return :sticky if pages.include?(action_name.to_sym)
    nil
  end

  def force_sticky_mode!
    @_sticky_mode = true
  end

  def appearance_text_class
    APPEARANCE_TEXT_CLASS
  end

  def appearance_mode_drop_down
    @appearance_mode_drop_down ||= begin
      current = cookies[APPEARANCE_MODE_COOKIE]
      actual = cookies[APPEARANCE_MODE_ACTUAL_COOKIE]
      raw_types = RailsBase::Configuration::Appearance::APPEARANCE_TYPES
      types_a = raw_types.map(&:to_a).map(&:flatten).map(&:reverse)
      types = raw_types.keys
      unless types.include?(current&.to_sym)
        cookies[APPEARANCE_MODE_COOKIE] = current = RailsBase.appearance.default_mode
      end
      { types: types, current: current, types_a: types_a, actual: actual }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_base-0.53.0 app/helpers/rails_base/appearance_helper.rb
rails_base-0.52.3 app/helpers/rails_base/appearance_helper.rb
rails_base-0.52.1 app/helpers/rails_base/appearance_helper.rb
rails_base-0.52.0 app/helpers/rails_base/appearance_helper.rb
rails_base-0.51.1 app/helpers/rails_base/appearance_helper.rb
rails_base-0.51.0 app/helpers/rails_base/appearance_helper.rb