Sha256: 6b97aba5024026216d5d2d4cd2e2ed547513b22fd760ca4d96409924d69cded4

Contents?: true

Size: 974 Bytes

Versions: 8

Compression:

Stored size: 974 Bytes

Contents

module Lookbook
  class PreviewGroup < Entity
    include Navigable

    attr_reader :examples, :preview

    def initialize(name, examples, preview)
      @name = Utils.name(name)
      @examples = PreviewExampleCollection.new(examples)
      @preview = preview
      @lookup_path = "#{parent.lookup_path}/#{@name}"
    end

    def display_options
      merged = {}
      examples.to_a.reverse.map do |example|
        merged.merge!(example.display_options)
      end
      merged
    end

    def components
      @_components ||= ComponentCollection.new(examples.flat_map(&:components).uniq(&:path))
    end

    def search_terms
      [parent.label, label]
    end

    def tags(tag_name = nil)
      examples.flat_map { |example| example.tags(tag_name) }
    end

    def tag(tag_name = nil)
      tags(tag_name).first
    end

    def url_path
      lookbook_inspect_path(path)
    end

    def type
      :group
    end

    alias_method :parent, :preview
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lookbook-1.5.1 lib/lookbook/entities/preview_group.rb
lookbook-1.5.0 lib/lookbook/entities/preview_group.rb
lookbook-1.4.5 lib/lookbook/entities/preview_group.rb
lookbook-1.4.4 lib/lookbook/entities/preview_group.rb
lookbook-1.4.3 lib/lookbook/entities/preview_group.rb
lookbook-1.4.2 lib/lookbook/entities/preview_group.rb
lookbook-1.4.1 lib/lookbook/entities/preview_group.rb
lookbook-1.4.0 lib/lookbook/entities/preview_group.rb