class Lookbook::ScenarioEntity

@api public
Represents a preview scenario method within a preview class

def display_options

Returns:
  • (Hash) - The resolved display options
def display_options
  parent.display_options.merge(fetch_config(:display_options, {}))
end

def format_source(source)

def format_source(source)
  source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n")
end

def id

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

def initialize(code_object, preview, priority: nil)

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

def inspect_path

Returns:
  • (String) - URL path
def inspect_path
  lookbook_inspect_path(lookup_path)
end

def load_render_targets

def load_render_targets
  render_target_identifiers = [*fetch_config(:renders, []), *preview.send(:fetch_config, :renders, [])]
  render_target_identifiers = preview.guess_render_targets if render_target_identifiers.empty?
  render_targets = render_target_identifiers.map do |render_target|
    RenderableEntity.new(render_target)
  rescue NameError
    Lookbook.logger.warn "#{render_target} was not found"
    nil
  end
  render_targets.compact.uniq(&:lookup_path)
end

def name

Returns:
  • (String) - The name
def name
  @_name ||= Utils.name(code_object.name)
end

def preview_path

Returns:
  • (String) - URL path
def preview_path
  lookbook_preview_path(lookup_path)
end

def render_target

Returns:
  • (RenderableEntity) - The render target

Other tags:
    Example: :ruby -
def render_target
  render_targets.first
end

def render_targets

Other tags:
    Api: - private
def render_targets
  @_render_targets ||= RenderTargetCollection.new(load_render_targets)
end

def scenarios

Other tags:
    Api: - private
def scenarios
  [self]
end

def search_terms

Other tags:
    Api: - private
def search_terms
  [parent.label, label]
end

def sort_handler(other_entity)

def sort_handler(other_entity)
  if Lookbook.config.preview_sort_scenarios
    label <=> other_entity.label
  else
    [priority, label] <=> [other_entity.priority, other_entity.label]
  end
end

def template_file_path(template_path)

def template_file_path(template_path)
  return full_template_path(template_path) if respond_to?(:full_template_path, true)
  search_dirs = [*Engine.preview_paths, *Engine.view_paths]
  template_path = "#{template_path.to_s.sub(/\..*$/, "")}.html.*"
  PathUtils.determine_full_path(template_path, search_dirs)
end

def template_lang(template_path)

Other tags:
    Api: - private
def template_lang(template_path)
  path = template_file_path(template_path)
  Lookbook::Lang.guess(path) || Lookbook::Lang.find(:html)
end

def template_source(template_path)

Other tags:
    Api: - private
def template_source(template_path)
  source_path = template_file_path(template_path)
  source_path ? File.read(source_path) : nil
end

def type

Returns:
  • (Symbol) - The entity type
def type
  :scenario
end