Sha256: a3b6cd7caa140f86e6e1d95a1c3298481bbed6c287fe3ca269d9b4376ed30bef

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shopapp-0.2.6 app/helpers/shopapp_helper.rb
shopapp-0.2.4 app/helpers/shopapp_helper.rb
shopapp-0.2.3 app/helpers/shopapp_helper.rb
shopapp-0.2.02 app/helpers/shopapp_helper.rb
shopapp-0.2.01 app/helpers/shopapp_helper.rb