Sha256: 654349a1a24120d86f8dbe77ed9dd0f534855d796afcc52765333861e8e80b71

Contents?: true

Size: 959 Bytes

Versions: 24

Compression:

Stored size: 959 Bytes

Contents

module Lookbook
  class Nav::Entity::Component < Nav::Item::Component
    ICONS = {
      page: :file,
      preview: :layers,
      scenario: :eye,
      scenario_group: :eye
    }.freeze

    def nav_icon
      ICONS[collapsed? ? :preview : node.type] || :file
    end

    def href
      if collapsed?
        node.first.url_path
      elsif type != :preview
        node.url_path
      end
    end

    def children
      collapsed? ? [] : super
    end

    def type
      collapsed? ? :scenario : node.type
    end

    def collapsed?
      node.type == :preview && node.children.one?
    end

    def search_terms
      matchers = if collapsed?
        node.first.search_terms
      else
        node.respond_to?(:search_terms) ? Array(node.search_terms) : []
      end
      matchers.flatten.map { |m| m.gsub(/\s/, "").downcase }
    end

    protected

    def alpine_data
      alpine_encode({id: node.id, matchers: search_terms})
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
lookbook-2.3.4 app/components/lookbook/nav/entity/component.rb
lookbook-2.3.3 app/components/lookbook/nav/entity/component.rb
lookbook-2.3.2 app/components/lookbook/nav/entity/component.rb
lookbook-2.3.0 app/components/lookbook/nav/entity/component.rb
lookbook-2.2.2 app/components/lookbook/nav/entity/component.rb
lookbook-2.2.1 app/components/lookbook/nav/entity/component.rb
lookbook-2.2.0 app/components/lookbook/nav/entity/component.rb
lookbook-2.1.1 app/components/lookbook/nav/entity/component.rb
lookbook-2.1.0 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.5 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.4 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.3 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.2 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.1 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.rc.3 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.rc.2 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.rc.1 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.beta.9 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.beta.8 app/components/lookbook/nav/entity/component.rb