Class: Lookbook::PreviewExample

Inherits:
Entity
  • Object
show all
Includes:
Annotatable, Inspectable, Navigable
Defined in:
lib/lookbook/entities/preview_example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#<=>, #label, #lookup_path

Constructor Details

#initialize(code_object, preview, position: nil) ⇒ PreviewExample

Returns a new instance of PreviewExample.



11
12
13
14
15
16
# File 'lib/lookbook/entities/preview_example.rb', line 11

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

Instance Attribute Details

#previewObject (readonly) Also known as: parent

Returns the value of attribute preview.



9
10
11
# File 'lib/lookbook/entities/preview_example.rb', line 9

def preview
  @preview
end

Instance Method Details

#componentObject



34
35
36
# File 'lib/lookbook/entities/preview_example.rb', line 34

def component
  components.first
end

#componentsObject



30
31
32
# File 'lib/lookbook/entities/preview_example.rb', line 30

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

#display_optionsObject



26
27
28
# File 'lib/lookbook/entities/preview_example.rb', line 26

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

#examplesObject



38
39
40
# File 'lib/lookbook/entities/preview_example.rb', line 38

def examples
  [self]
end

#idObject



18
19
20
# File 'lib/lookbook/entities/preview_example.rb', line 18

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

#nameObject



22
23
24
# File 'lib/lookbook/entities/preview_example.rb', line 22

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

#preview_pathObject



60
61
62
# File 'lib/lookbook/entities/preview_example.rb', line 60

def preview_path
  lookbook_preview_path(path)
end

#search_termsObject



52
53
54
# File 'lib/lookbook/entities/preview_example.rb', line 52

def search_terms
  [parent.label, label]
end

#template_lang(template_path) ⇒ Object



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

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



42
43
44
45
# File 'lib/lookbook/entities/preview_example.rb', line 42

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

#typeObject



64
65
66
# File 'lib/lookbook/entities/preview_example.rb', line 64

def type
  :example
end

#url_pathObject



56
57
58
# File 'lib/lookbook/entities/preview_example.rb', line 56

def url_path
  lookbook_inspect_path(path)
end