class Lookbook::PreviewExample

Attributes

name[R]

Public Class Methods

new(name, preview) click to toggle source
# File lib/lookbook/preview_example.rb, line 7
def initialize(name, preview)
  @name = name
  @preview = preview
end

Public Instance Methods

filter_match_string() click to toggle source
# File lib/lookbook/preview_example.rb, line 44
def filter_match_string
  [*@preview.lookbook_parent_collections, @preview.label, label].join("/").gsub(/\s/, "").downcase
end
hierarchy_depth() click to toggle source
# File lib/lookbook/preview_example.rb, line 48
def hierarchy_depth
  @preview.lookbook_hierarchy_depth + 1
end
id() click to toggle source
# File lib/lookbook/preview_example.rb, line 12
def id
  path.underscore.tr("_", "-")
end
label() click to toggle source
# File lib/lookbook/preview_example.rb, line 20
def label
  lookbook_label.presence || name.titleize
end
method_source() click to toggle source
# File lib/lookbook/preview_example.rb, line 24
def method_source
  code_object.source.split("\n")[1..-2].join("\n").strip_heredoc
end
path() click to toggle source
# File lib/lookbook/preview_example.rb, line 16
def path
  "#{@preview.lookbook_path}/#{name}"
end
source_lang() click to toggle source
# File lib/lookbook/preview_example.rb, line 28
def source_lang
  Lookbook::Lang.find(:ruby)
end
template_lang(template_path) click to toggle source
# File lib/lookbook/preview_example.rb, line 36
def template_lang(template_path)
  Lookbook::Lang.guess(full_template_path(template_path)) || Lookbook::Lang.find(:html)
end
template_source(template_path) click to toggle source
# File lib/lookbook/preview_example.rb, line 32
def template_source(template_path)
  File.read(full_template_path(template_path))
end
type() click to toggle source
# File lib/lookbook/preview_example.rb, line 40
def type
  :example
end

Private Instance Methods

full_template_path(template_path) click to toggle source
# File lib/lookbook/preview_example.rb, line 58
def full_template_path(template_path)
  base_path = Array(Lookbook.config.preview_paths).detect do |p|
    Dir["#{p}/#{template_path}.html.*"].first
  end
  Pathname.new(Dir["#{base_path}/#{template_path}.html.*"].first)
end
taggable_object_path() click to toggle source
# File lib/lookbook/preview_example.rb, line 54
def taggable_object_path
  "#{@preview.name}##{name}"
end