module Lookbook::LocatableEntity

def base_directory

def base_directory
  return @_base_directory if @_base_directory
  directories = Array(base_directories).map(&:to_s).sort_by { |path| path.split("/").size }.reverse
  @_base_directory ||= directories.find { |dir| file_path.to_s.start_with?(dir) }
end

def directory_path

Returns:
  • (Pathname) - Directory path
def directory_path
  @_directory_path ||= Pathname(file_pathname.dirname)
end

def file_extension

Returns:
  • (String) - File extension
def file_extension
  @_file_extension ||= file_pathname.extname
end

def file_name(strip_ext = false)

Returns:
  • (String) - File name

Parameters:
  • strip_ext (Boolean) -- Whether or not to remove the file extension
def file_name(strip_ext = false)
  basename = file_pathname.basename
  (strip_ext ? basename.to_s.split(".").first : basename).to_s
end

def file_name_base

Other tags:
    Api: - private
def file_name_base
  @_file_name_slug ||= file_name(true)
end

def file_pathname

def file_pathname
  Pathname(file_path)
end

def last_modified

Returns:
  • (Time) - Time last modified
def last_modified
  @_last_modified ||= File.mtime(file_path)
end

def logical_path

Returns:
  • (String) - The logical path

Other tags:
    Api: - private
def logical_path
  return @_logical_path if @_logical_path
  logical_path_value = fetch_config(:logical_path)
  @_logical_path ||= if logical_path_value
    PathUtils.to_path(logical_path_value, lookup_path.split("/").last)
  else
    PathUtils.to_path(lookup_path)
  end
end

def relative_directory_path

Returns:
  • (Pathname) - Relative directory path
def relative_directory_path
  @_relative_directory_path ||= directory_path.relative_path_from(base_directory)
end

def relative_file_path

Returns:
  • (Pathname) - Relative file path
def relative_file_path
  @_relative_file_path ||= file_pathname.relative_path_from(base_directory)
end