Sha256: 5e103804d4aa568c15c9a219683bcd62a6718e6d6404e442fbd64d578090b592

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Lookbook
  # Represents a group of preview scenarios within a preview class
  #
  # @ignore methods
  # @api public
  class ScenarioGroupEntity < Entity
    include NavigableEntity

    attr_reader :scenarios, :preview

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

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

    def render_targets
      @_render_targets ||= RenderTargetCollection.new(scenarios.flat_map(&:render_targets).uniq(&:path))
    end

    def search_terms
      [parent.label, label]
    end

    def tags(tag_name = nil)
      scenarios.flat_map { |scenario| scenario.tags(tag_name) }
    end

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

    def url_path
      lookbook_inspect_path(lookup_path)
    end

    def preview_path
      lookbook_preview_path(lookup_path)
    end

    def type
      :group
    end

    alias_method :parent, :preview
    alias_method :components, :render_targets
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.1 lib/lookbook/entities/scenario_group_entity.rb