Class: Lookbook::PreviewExample

Inherits:
Object
  • Object
show all
Includes:
Taggable
Defined in:
lib/lookbook/preview_example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Taggable

#code_object, #lookbook_display_params, #lookbook_group, #lookbook_hidden?, #lookbook_label, #lookbook_notes

Constructor Details

#initialize(name, preview) ⇒ PreviewExample

Returns a new instance of PreviewExample.



7
8
9
10
# File 'lib/lookbook/preview_example.rb', line 7

def initialize(name, preview)
  @name = name
  @preview = preview
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/lookbook/preview_example.rb', line 5

def name
  @name
end

Instance Method Details

#display_paramsObject



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

def display_params
  @preview.display_params.merge(lookbook_display_params)
end

#hierarchy_depthObject



58
59
60
# File 'lib/lookbook/preview_example.rb', line 58

def hierarchy_depth
  @preview.lookbook_hierarchy_depth + 1
end

#idObject



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

def id
  path.underscore.tr("/", "-").tr("_", "-")
end

#labelObject



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

def label
  lookbook_label.presence || name.titleize
end

#matchersObject



54
55
56
# File 'lib/lookbook/preview_example.rb', line 54

def matchers
  [@preview.label, label].map { |m| m.gsub(/\s/, "").downcase }
end

#method_sourceObject



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

def method_source
  code_object.source.split("\n")[1..-2].join("\n").strip_heredoc
end

#paramsObject



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

def params
  @params || code_object&.tags("param")&.map do |param|
    Lookbook::Params.build_param(param, parameter_defaults[param.name])
  end
end

#pathObject



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

def path
  "#{@preview.lookbook_path}/#{name}"
end

#source_langObject



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

def source_lang
  Lookbook::Lang.find(:ruby)
end

#template_lang(template_path) ⇒ Object



46
47
48
# File 'lib/lookbook/preview_example.rb', line 46

def template_lang(template_path)
  Lookbook::Lang.guess(full_template_path(template_path)) || Lookbook::Lang.find(:html)
end

#template_source(template_path) ⇒ Object



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

def template_source(template_path)
  File.read(full_template_path(template_path))
end

#typeObject



50
51
52
# File 'lib/lookbook/preview_example.rb', line 50

def type
  :example
end