Sha256: bfe471861c7e54c09233abdc0dc2cd95e1e079bf55a7b5c64836a0f87c9acfa3

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

module Integral
  # Support Helper which contains common helper methods used within backend & frontend
  module SupportHelper
    # @return [Boolean] Whether or not to display media query indicator
    # Green - large screens, medium - tablets, red - mobile
    def display_media_query_indicator?
      Rails.env.development?
    end

    # @return [String] markup listing flash notifications
    def render_flashes
      flash_types = %i[notice alert error]

      content_tag :div, id: :flash_list do
        flash_types.each do |type|
          concat render_flash(type, flash[type]) if flash[type].present?
        end
      end
    end

    # Creates an anchor link
    #
    # @param body [String] body of the link
    # @param location [String] location of the anchor
    #
    # @return [String] anchor to a particular location of the current page
    def anchor_to(body, location)
      current_path = url_for(only_path: false)
      path = "#{current_path}##{location}"

      link_to body, path
    end

    # Override method_missing to check for main app routes before throwing exception
    def method_missing(method, *args, &block)
      if method.to_s.end_with?('_path', '_url')
        if main_app.respond_to?(method)
          main_app.send(method, *args)
        else
          super
        end
      else
        super
      end
    end

    # Override respond_to? to check for main app routes
    def respond_to?(method, include_all = false)
      if method.to_s.end_with?('_path', '_url')
        if main_app.respond_to?(method)
          true
        else
          super
        end
      else
        super
      end
    end

    private

    def render_flash(type, message)
      content_tag(:div, nil, class: :flash, data: { message: message, klass: type })
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
integral-1.5.1 app/helpers/integral/support_helper.rb
integral-1.5.0 app/helpers/integral/support_helper.rb
integral-1.4.0 app/helpers/integral/support_helper.rb
integral-1.3.0 app/helpers/integral/support_helper.rb
integral-1.2.0 app/helpers/integral/support_helper.rb
integral-1.1.0 app/helpers/integral/support_helper.rb
integral-1.0.1 app/helpers/integral/support_helper.rb