class Lookbook::PreviewExample

def component

def component
  components.first
end

def components

def components
  @_components ||= ComponentCollection.new(load_components)
end

def display_options

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

def examples

def examples
  [self]
end

def format_source(source)

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

def id

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

def initialize(code_object, preview, position: nil)

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

def load_components

def load_components
  component_classes = [*fetch_config(:components, []), *preview.send(:fetch_config, :components, [])]
  component_classes = preview.guess_components if component_classes.empty?
  components = component_classes.map { |klass| Component.new(klass) }
  components.uniq(&:path)
end

def name

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

def preview_path

def preview_path
  lookbook_preview_path(path)
end

def search_terms

def search_terms
  [parent.label, label]
end

def sort_handler(other_entity)

def sort_handler(other_entity)
  if Lookbook.config.sort_examples
    label <=> other_entity.label
  else
    [position, label] <=> [other_entity.position, 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)
  template_path = template_path.to_s.sub(/\..*$/, "")
  base_path = Engine.preview_paths.detect do |p|
    Dir["#{p}/#{template_path}.html.*"].first
  end
  path = Dir["#{base_path}/#{template_path}.html.*"].first
  Pathname(path) if path
end

def template_lang(template_path)

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)

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

def type

def type
  :example
end

def url_path

def url_path
  lookbook_inspect_path(path)
end