Sha256: 169c2ac884d5b95655d1a0e066be984fd14576594bf6bc1970d6db0599710bb9

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

class Navbar
  include Rails.application.routes.url_helpers

  def initialize(user)
    @user = user
  end

  def sidebar
    yaml_data = YAML.load_file("#{Rails.application.root}/config/pg_rails.yml")
    sidebar = ActiveSupport::HashWithIndifferentAccess.new(yaml_data)['sidebar']
    # rubocop:disable Security/Eval
    sidebar.map do |item|
      {
        title: item['name'],
        path: eval(item['path']),
        show: true
      }
    end
    # rubocop:enable Security/Eval
  end

  def all_children_hidden?(entry)
    entry[:children].all? { |child| child[:show] == false }
  end

  def any_children_active?(entry, request)
    entry[:children].any? { |child| active_entry?(child, request) }
    true
    # TODO: quitar
  end

  def hide_entry?(entry)
    if entry[:children].present?
      all_children_hidden?(entry)
    else
      entry[:show] == false
    end
  end

  def custom_current_page?(path, request)
    current_route = Rails.application.routes.recognize_path(request.env['PATH_INFO'])
    test_route = Rails.application.routes.recognize_path(path)
    current_route[:controller] == test_route[:controller] && current_route[:action] == test_route[:action]
  rescue ActionController::RoutingError
    false
  end

  def active_entry?(entry, request)
    if entry[:children].present?
      any_children_active?(entry, request)
    elsif entry[:path].present?
      custom_current_page?(entry[:path], request)
    end
  end

  private

  def policy(clase)
    Pundit.policy(@user, clase)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha.9 pg_layout/app/lib/navbar.rb
pg_rails-7.0.8.pre.alpha.8 pg_layout/app/lib/navbar.rb
pg_rails-7.0.8.pre.alpha.7 pg_layout/app/lib/navbar.rb
pg_rails-7.0.8.pre.alpha.6 pg_layout/app/lib/navbar.rb
pg_rails-7.0.8.pre.alpha pg_layout/app/lib/navbar.rb
pg_rails-7.0.7 pg_layout/app/lib/navbar.rb
pg_rails-7.0.6 pg_layout/app/lib/navbar.rb
pg_rails-7.0.5 pg_layout/app/lib/navbar.rb
pg_rails-7.0.4 pg_layout/app/lib/navbar.rb
pg_rails-7.0.3 pg_layout/app/lib/navbar.rb
pg_rails-7.0.2 pg_layout/app/lib/navbar.rb