Class: Lookbook::ScenarioEntity
- 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
-
#preview ⇒ PreviewEntity
(also: #parent)
readonly
The preview that this scenario belongs to.
Identity collapse
-
#id ⇒ String
Human-readable unique scenario ID.
-
#name ⇒ String
Parameter-safe scenario name.
-
#type ⇒ Symbol
Entity type identifier.
Display options collapse
-
#display_options ⇒ Hash
Display options hash.
Render Targets collapse
-
#render_target ⇒ RenderableEntity
(also: #component)
The item (component or partial) that the scenario renders.
- #render_targets ⇒ Object (also: #components) private
URLs collapse
-
#inspect_path ⇒ String
(also: #url_path)
The inspector URL path for this preview.
-
#preview_path ⇒ String
The standalone preview URL path for this preview.
Instance Method Summary collapse
- #after_render_method ⇒ Object private
-
#initialize(code_object, preview, priority: nil) ⇒ ScenarioEntity
constructor
private
A new instance of ScenarioEntity.
- #scenarios ⇒ Object (also: #examples) private
- #search_terms ⇒ Object private
- #template_lang(template_path) ⇒ Object private
- #template_source(template_path) ⇒ Object private
Methods inherited from Entity
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
#preview ⇒ PreviewEntity (readonly) Also known as: parent
The preview that this scenario belongs to.
15 16 17 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 15 def preview @preview end |
Instance Method Details
#after_render_method ⇒ 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.
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_options ⇒ Hash
Display options hash.
Contains all display options defined via the ‘@display` tag merged with any globally-defined options.
62 63 64 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 62 def parent..merge(fetch_config(:display_options, {})) end |
#id ⇒ String
Human-readable unique scenario 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_path ⇒ String Also known as: url_path
The inspector URL path for this preview
100 101 102 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 100 def inspect_path lookbook_inspect_path(lookup_path) end |
#name ⇒ String
Parameter-safe scenario name.
40 41 42 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 40 def name @_name ||= Utils.name(code_object.name) end |
#preview_path ⇒ String
The standalone preview URL path for this preview
107 108 109 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 107 def preview_path lookbook_preview_path(lookup_path) end |
#render_target ⇒ RenderableEntity 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.
87 88 89 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 87 def render_target render_targets.first end |
#render_targets ⇒ Object 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 |
#scenarios ⇒ Object 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_terms ⇒ 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.
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 |
#type ⇒ Symbol
Entity type identifier. Returns ‘:scenario` for scenarios.
48 49 50 |
# File 'lib/lookbook/entities/scenario_entity.rb', line 48 def type :scenario end |