Class: Lookbook::PreviewGroup

Inherits:
Entity
  • Object
show all
Defined in:
lib/lookbook/preview_group.rb

Constant Summary

Constants included from Utils

Utils::FRONTMATTER_REGEX, Utils::POSITION_PREFIX_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#id, #path

Constructor Details

#initialize(name, preview, examples) ⇒ PreviewGroup

Returns a new instance of PreviewGroup.



5
6
7
8
9
10
# File 'lib/lookbook/preview_group.rb', line 5

def initialize(name, preview, examples)
  @name = name
  @preview = preview
  @examples = examples
  super("#{@preview.path}/#{name}")
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



3
4
5
# File 'lib/lookbook/preview_group.rb', line 3

def examples
  @examples
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/lookbook/preview_group.rb', line 3

def name
  @name
end

#previewObject (readonly)

Returns the value of attribute preview.



3
4
5
# File 'lib/lookbook/preview_group.rb', line 3

def preview
  @preview
end

Instance Method Details

#display_paramsObject



28
29
30
31
32
33
34
# File 'lib/lookbook/preview_group.rb', line 28

def display_params
  merged = {}
  examples.reverse.map do |example|
    merged.merge! example.display_params
  end
  merged
end

#hidden?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/lookbook/preview_group.rb', line 36

def hidden?
  false
end

#hierarchy_depthObject



48
49
50
# File 'lib/lookbook/preview_group.rb', line 48

def hierarchy_depth
  @preview.hierarchy_depth + 1
end

#labelObject



16
17
18
# File 'lib/lookbook/preview_group.rb', line 16

def label
  name.titleize
end

#matchersObject



44
45
46
# File 'lib/lookbook/preview_group.rb', line 44

def matchers
  normalize_matchers(@preview.label, label)
end

#paramsObject



24
25
26
# File 'lib/lookbook/preview_group.rb', line 24

def params
  examples.map(&:params).flatten.uniq { |param| param[:name] }
end

#positionObject



40
41
42
# File 'lib/lookbook/preview_group.rb', line 40

def position
  10000
end

#tag(name = nil) ⇒ Object



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

def tag(name = nil)
  tags(name).first
end

#tags(name = nil) ⇒ Object



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

def tags(name = nil)
  examples.map { |example| example.tags(name) }.flatten
end

#typeObject



20
21
22
# File 'lib/lookbook/preview_group.rb', line 20

def type
  :group
end

#url_pathObject



12
13
14
# File 'lib/lookbook/preview_group.rb', line 12

def url_path
  lookbook_inspect_path lookup_path
end