Class: Lookbook::ScenarioEntity

Inherits:
Entity
  • Object
show all
Includes:
AnnotatableEntity, InspectableEntity, NavigableEntity
Defined in:
lib/lookbook/entities/scenario_entity.rb

Overview

Represents a preview scenario method within a preview class

Instance Attribute Summary collapse

Identity collapse

Display options collapse

Render Targets collapse

URLs collapse

Instance Method Summary collapse

Methods inherited from Entity

#<=>, #label, #lookup_path

Constructor Details

#initialize(code_object, preview, priority: nil) ⇒ ScenarioEntity

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 ScenarioEntity.



21
22
23
24
25
26
# File 'lib/lookbook/entities/scenario_entity.rb', line 21

def initialize(code_object, preview, priority: nil)
  @code_object = code_object
  @preview = preview
  @default_priority = priority
  @lookup_path = "#{parent.lookup_path}/#{name}"
end

Instance Attribute Details

#previewPreviewEntity (readonly) Also known as: parent

The preview that this scenario belongs to.

Returns:



15
16
17
# File 'lib/lookbook/entities/scenario_entity.rb', line 15

def preview
  @preview
end

Instance Method Details

#after_render_methodObject

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.



114
115
116
# File 'lib/lookbook/entities/scenario_entity.rb', line 114

def after_render_method
  fetch_config(:after_render) || parent.after_render_method
end

#display_optionsHash

Display options hash.

Contains all display options defined via the ‘@display` tag merged with any globally-defined options.

Returns:

  • (Hash)

    The resolved display options



62
63
64
# File 'lib/lookbook/entities/scenario_entity.rb', line 62

def display_options
  parent.display_options.merge(fetch_config(:display_options, {}))
end

#idString

Human-readable unique scenario ID

Returns:

  • (String)

    The ID



33
34
35
# File 'lib/lookbook/entities/scenario_entity.rb', line 33

def id
  @_id ||= Utils.id(fetch_config(:id) { "#{parent.id}-#{code_object.name}" })
end

#inspect_pathString Also known as: url_path

The inspector URL path for this preview

Returns:

  • (String)

    URL path



100
101
102
# File 'lib/lookbook/entities/scenario_entity.rb', line 100

def inspect_path
  lookbook_inspect_path(lookup_path)
end

#nameString

Parameter-safe scenario name.

Returns:

  • (String)

    The name



40
41
42
# File 'lib/lookbook/entities/scenario_entity.rb', line 40

def name
  @_name ||= Utils.name(code_object.name)
end

#preview_pathString

The standalone preview URL path for this preview

Returns:

  • (String)

    URL path



107
108
109
# File 'lib/lookbook/entities/scenario_entity.rb', line 107

def preview_path
  lookbook_preview_path(lookup_path)
end

#render_targetRenderableEntity Also known as: component

The item (component or partial) that the scenario renders.

The render target is guessed where possible (based on the preview class name) but can also be manually specified using the ‘@renders` tag.

Examples:

:ruby

"This scenario renders: #{scenario.render_target.label}"

Returns:



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

def render_target
  render_targets.first
end

#render_targetsObject Also known as: components

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.



71
72
73
# File 'lib/lookbook/entities/scenario_entity.rb', line 71

def render_targets
  @_render_targets ||= RenderTargetCollection.new(load_render_targets)
end

#scenariosObject Also known as: examples

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.



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

def scenarios
  [self]
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.



136
137
138
# File 'lib/lookbook/entities/scenario_entity.rb', line 136

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

#template_lang(template_path) ⇒ 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.



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

def template_lang(template_path)
  path = template_file_path(template_path)
  Lookbook::Lang.guess(path) || Lookbook::Lang.find(:html)
end

#template_source(template_path) ⇒ 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.



124
125
126
127
# File 'lib/lookbook/entities/scenario_entity.rb', line 124

def template_source(template_path)
  source_path = template_file_path(template_path)
  source_path ? File.read(source_path) : nil
end

#typeSymbol

Entity type identifier. Returns ‘:scenario` for scenarios.

Returns:

  • (Symbol)

    The entity type



48
49
50
# File 'lib/lookbook/entities/scenario_entity.rb', line 48

def type
  :scenario
end