Sha256: 326ddc32556e5591ea3b613250a88cb3482b0020f1a1a39c44cebcc5b62ee32e

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

module ShopappHelper
  def user_allowed?(scope)
    unless @current_user['scopes'].is_a? String
      user_scopes = @current_user['scopes']
    else
      user_scopes = JSON.parse @current_user['scopes']
    end
    user_scopes.include?('admin') || user_scopes.include?(scope.to_s)
  end

  def main_menu_link(url_path, link_text: nil, icon: nil)
    link_class_list = 'nav-link'
    link_class_list << ' active' if request.original_url.include? url_path.to_s
    link_text ||= url_path.to_s.capitalize

    full_link_text = <<~HTML.html_safe
      <i class="fa fa-#{icon}"></i>
      #{link_text}
    HTML
    <<~HTML2.html_safe
      <li class="nav-item">#{ link_to(full_link_text, url_path, class: link_class_list)}</li>
    HTML2
  end

  def secondary_menu(title, &block)
    <<~HTML2.html_safe
      <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
        <span>#{title}</span>
      </h6>
      <ul class="nav flex-column mb-2>
        #{capture &block}
      </ul>
    HTML2
  end

  def secondary_menu_link(url_path, link_text: nil, icon: nil)
    link_text ||= url_path.to_s.capitalize
    link_class_list = 'nav-link'
    link_class_list << ' active' if request.original_url.include? url_path.to_s

    <<~HTML.html_safe
      <li class="nav-item">
        <a class="#{link_class_list}" href="#{url_path}">
          <i class="fa fa-#{icon}"></i>
          #{link_text}
        </a>
      </li>
    HTML
  end

  def search_path
    if controller.class.search_path == :current_path
      request.path
    else
      "#{controller.class.search_path || '/'}"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shopapp-0.2.19 app/helpers/shopapp_helper.rb
shopapp-0.2.18 app/helpers/shopapp_helper.rb
shopapp-0.2.17 app/helpers/shopapp_helper.rb
shopapp-0.2.16 app/helpers/shopapp_helper.rb
shopapp-0.2.15 app/helpers/shopapp_helper.rb
shopapp-0.2.14 app/helpers/shopapp_helper.rb
shopapp-0.2.12 app/helpers/shopapp_helper.rb
shopapp-0.2.11 app/helpers/shopapp_helper.rb
shopapp-0.2.10 app/helpers/shopapp_helper.rb
shopapp-0.2.9 app/helpers/shopapp_helper.rb