Sha256: 7b1aed6d7c8b52c8f5daf3ca2d70402bfbfbaa5df7fc9ba18b2c7acac8b66764

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module ShopappHelper
  def user_allowed?(scope)
    user_scopes = JSON.parse @current_user['scopes']
    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

2 entries across 2 versions & 1 rubygems

Version Path
shopapp-0.2.8 app/helpers/shopapp_helper.rb
shopapp-0.2.7 app/helpers/shopapp_helper.rb