API / Entities

PreviewEntity

Represents a preview class.

Instance Methods

Annotations

# notes → String

Any notes added to the entity. Returns the raw (unrendered) string which may contain markdown formatting.

# tag (name = nil) → Array<YardTag>

The first tag (optionally of a particular type) added to the entity.

Arguments:

name Symbol

Optional tag type to filter by

Example:

first_tag = entity.tag
first_display_tag = entity.tag(:display)
# tags (name = nil) → Array<YardTag>

All tags that have been added to the entity. Can be filtered by tag name by providing the name as an argument.

Arguments:

name Symbol

Optional tag type to filter by

Example:

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

Identity

# id → String

Human-readable unique ID for the entity.

# label → String

Titlized name for use in navigation etc.

Can be customized using the @label tag where supported.

# name → String

Parameter-safe entity name.

# type → Symbol

Entity type identifier.

Paths

# directory_path → Pathname

Full directory path for the entity file.

Aliases:

#dir_path
# file_extension → String

Extension of the entity file.

# file_name (strip_ext = false) → String

Name of the entity file.

Includes file extension unless the strip_ext argument is true.

Arguments:

strip_ext Boolean

Whether or not to remove the file extension

# file_path → Pathname

Full path to the entity file.

Aliases:

#full_path
# last_modified → Time

Time that the entity file was last modified.

# lookup_path → String

Canonical reference path.

Used for generating URL paths and looking up entities.

Aliases:

#path
# relative_directory_path → Pathname

Relative directory path for the entity file.

Returned path is relative to the appropriate base directory (i.e. the preview directory for previews).

# relative_file_path → Pathname

Relative path to the entity file.

Returned path is relative to the appropriate base directory (i.e. the preview directory for previews).

Aliases:

#rel_path

Render Targets

# render_targets → Array<RenderableEntity>

All 'render targets' (i.e. components or partials) that are known to be rendered within the scenarios defined within this preview.

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

Example:

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

Aliases:

#components

Scenarios

# default_scenario → ScenarioEntity

The scenario used when a preview is rendered without explicity specifying a scenario.

Example:

default_scenario_name = preview.default_scenario.name
# hidden_scenarios → Array<ScenarioEntity>

Get all scenarios defined in the preview class that are hidden (using the @hidden tag) and so will not show up in the navigation.

Example:

hidden_scenario_names = preview.hidden_scenarios.map(&:name)
# scenario (scenario_name) → ScenarioEntity

Find a specific scenario by (i.e. method) name.

Arguments:

scenario_name Symbol,String

Name of the scenario

Example:

default_scenario_preview_path = preview.scenario(:default).preview_path

Aliases:

#example
# scenarios → Array<ScenarioEntity>

Get all scenarios defined in the preview class.

Example:

scenario_names = preview.scenarios.map(&:name)

Aliases:

#examples
# visible_scenarios → Array<ScenarioEntity>

Get all scenarios defined in the preview class that have not been hidden (by using the @hidden tag).

Example:

visible_scenario_names = preview.visible_scenarios.map(&:name)

URLs

# inspect_path → String

The inspector URL path for this preview.

Aliases:

#url_path
# preview_path → String

The standalone preview URL path for this preview.

Visibility

# hidden? → Boolean

Whether or not the entity is hidden (i.e. hidden from navigation).

# visible? → Boolean

Whether or not the entity is visible (i.e. present in navigation).

Other

# preview_class_name → String

The name of the associated preview class.

User Guide

Extending Lookbook

API

Elsewhere