class Lookbook::RenderableEntity
@api public
that is being rendered in a preview.
Represents the component or view template partial
def component?
-
(Boolean)
- True if component
def component? @identifier.first.upcase == @identifier.first && !@identifier.include?(".") && !@identifier.include?("/") end
def component_class
-
(Class)
- The component class
def component_class @identifier.constantize if component? end
def initialize(identifier)
- Api: - private
def initialize(identifier) @identifier = identifier @base_directories = Engine.component_paths @file_path = if component? PathUtils.determine_full_path("#{name}.rb", @base_directories).presence || begin locations = Where.is_class(identifier.constantize) dirs = @base_directories.sort_by { |d| d.size * -1 } lookup = locations.find do |loc| dirs.find { |d| loc[0].start_with?(d) } end lookup[0] if lookup end else PathUtils.determine_full_path(identifier, @base_directories) end unless @file_path && File.exist?(@file_path) raise Lookbook::Error, "The render target #{@identifier} was not found." end @lookup_path = PathUtils.to_lookup_path(relative_file_path) end
def inline?
-
(Boolean)
- True if no template is present
def inline? component? ? template_file_path.present? : false end
def name
-
(String)
-
def name component? ? component_class.name.underscore : @identifier end
def template?
-
(Boolean)
- True if component
def template? !component? end
def template_file_path
-
(Class)
- The component class
def template_file_path component? ? Dir.glob("#{directory_path}/#{file_name(true)}.*.erb").first : file_path end
def type
-
(Symbol)
- The entity type
def type component? ? :component : :template end