Class: Lookbook::ScenarioGroupEntity

Inherits:
Entity
  • Object
show all
Includes:
NavigableEntity
Defined in:
lib/lookbook/entities/scenario_group_entity.rb

Overview

Represents a group of preview scenarios within a preview class

Scenarios collapse

Instance Attribute Summary collapse

Display options collapse

Render Targets collapse

Annotations collapse

URLs collapse

Identity collapse

Instance Method Summary collapse

Methods inherited from Entity

#<=>, #id, #label, #lookup_path, #name

Constructor Details

#initialize(name, scenarios, preview) ⇒ ScenarioGroupEntity

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ScenarioGroupEntity.



26
27
28
29
30
31
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 26

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

Instance Attribute Details

#previewPreviewEntity (readonly) Also known as: parent

The preview that this scenario belongs to.

Returns:



20
21
22
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 20

def preview
  @preview
end

#scenariosArray<ScenarioEntity> (readonly)

Returns all scenarios within the group.

Returns:



13
14
15
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 13

def scenarios
  @scenarios
end

Instance Method Details

#add_scenario(scenario) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



131
132
133
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 131

def add_scenario(scenario)
  @scenarios.add(scenario)
end

#display_optionsHash

Display options hash.

Contains all display options defined via the ‘@display` tag for each scenario in the group, merged with any globally-defined options.

Returns:

  • (Hash)

    The resolved display options



41
42
43
44
45
46
47
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 41

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

#inspect_pathString Also known as: url_path

The inspector URL path for this scenario group

Returns:

  • (String)

    URL path



98
99
100
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 98

def inspect_path
  lookbook_inspect_path(lookup_path)
end

#preview_pathString

The standalone preview URL path for this scenario group

Returns:

  • (String)

    URL path



105
106
107
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 105

def preview_path
  lookbook_preview_path(lookup_path)
end

#render_targetsArray<RenderableEntity> Also known as: components

Collection of render targets (components or partials) from each of the scenarios in the group.

Render targets are guessed where possible (based on the preview class name) but can also be manually specified using the ‘@renders` tag.

Examples:

:ruby

"This group renders: #{group.render_targets.map(&:label).join(", ")}"

Returns:



63
64
65
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 63

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

#search_termsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



126
127
128
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 126

def search_terms
  [parent.search_terms, parent.label, label]
end

#tag(tag_name = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



87
88
89
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 87

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

#tags(tag_name = nil) ⇒ Array<YardTag>

Collection of tags from each of the scenarios in the group. Can be filtered by tag name by providing the name as an argument.

Examples:

:ruby

all_tags = group.tags
display_tags = group.tags(:display)

Parameters:

  • tag_name (Symbol) (defaults to: nil)

    Optional tag type to filter by

Returns:

  • (Array<YardTag>)

    Array of tags



82
83
84
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 82

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

#typeSymbol

Entity type identifier. Returns ‘:scenario_group` for scenario groups.

Returns:

  • (Symbol)

    The entity type



119
120
121
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 119

def type
  :scenario_group
end