module Lookbook::Preview
Public Class Methods
all()
click to toggle source
# File lib/lookbook/preview.rb, line 61 def all ViewComponent::Preview.all end
exists?(path)
click to toggle source
# File lib/lookbook/preview.rb, line 69 def exists?(path) !!find(path) end
find(path)
click to toggle source
# File lib/lookbook/preview.rb, line 65 def find(path) all.find { |p| p.lookbook_path == path } end
Public Instance Methods
lookbook_example(example_name)
click to toggle source
# File lib/lookbook/preview.rb, line 14 def lookbook_example(example_name) lookbook_examples.find { |m| m.name == example_name } end
Also aliased as: example
lookbook_examples()
click to toggle source
# File lib/lookbook/preview.rb, line 18 def lookbook_examples return @lookbook_examples if @lookbook_examples.present? public_methods = public_instance_methods(false) public_method_objects = code_object.meths.filter { |m| public_methods.include?(m.name) } examples = public_method_objects.map { |m| PreviewExample.new(m.name.to_s, self) } examples.reject!(&:hidden?) @lookbook_examples ||= Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples end
Also aliased as: get_examples
lookbook_full_path()
click to toggle source
Examples::FooBarComponentPreview -> “/Users/myname/myapp/test/components/previews/examples/foo_bar_component_preview.rb” Examples::FooBarComponent::Preview -> “/Users/myname/myapp/test/components/previews/examples/foo_bar/component_preview.rb”
# File lib/lookbook/preview.rb, line 41 def lookbook_full_path base_path = Array(preview_paths).detect do |preview_path| Dir["#{preview_path}/#{name.underscore}.rb"].first end Pathname.new(Dir["#{base_path}/#{name.underscore}.rb"].first) end
lookbook_hierarchy_depth()
click to toggle source
# File lib/lookbook/preview.rb, line 52 def lookbook_hierarchy_depth lookbook_path.split("/").size end
Also aliased as: hierarchy_depth
lookbook_id()
click to toggle source
# File lib/lookbook/preview.rb, line 56 def lookbook_id lookbook_path.tr("_", "-") end
lookbook_label()
click to toggle source
Examples::FooBarComponent::Preview -> “Foo Bar”
Calls superclass method
Lookbook::Taggable#lookbook_label
# File lib/lookbook/preview.rb, line 6 def lookbook_label super.presence || lookbook_path.split("/").last.titleize end
Also aliased as: label
lookbook_name()
click to toggle source
Examples::FooBarComponentPreview -> “Examples::FooBar” Examples::FooBarComponent::Preview -> “Examples::FooBar”
# File lib/lookbook/preview.rb, line 29 def lookbook_name name.chomp("ComponentPreview").chomp("Component::Preview").chomp("::") end
lookbook_parent_collections()
click to toggle source
# File lib/lookbook/preview.rb, line 48 def lookbook_parent_collections File.dirname(lookbook_path).split("/") end
lookbook_path()
click to toggle source
Examples::FooBarComponentPreview -> “examples/foo_bar” Examples::FooBarComponent::Preview -> “examples/foo_bar”
# File lib/lookbook/preview.rb, line 35 def lookbook_path lookbook_name.underscore end
lookbook_type()
click to toggle source
# File lib/lookbook/preview.rb, line 10 def lookbook_type :preview end
Also aliased as: type
Private Instance Methods
taggable_object_path()
click to toggle source
# File lib/lookbook/preview.rb, line 76 def taggable_object_path name end