class Lookbook::YardTag
def self.supports_options(value = true)
def self.supports_options(value = true) @supports_options = !!value end
def self.supports_options?
def self.supports_options? @supports_options.nil? ? false : @supports_options end
def host_class_instance
def host_class_instance host_class = lookup_host_class host_class&.new end
def host_file
def host_file location = object&.files&.first # [file, line_number] Pathname(location.first) if location end
def host_file_base_directory
def host_file_base_directory return unless host_file directories = Engine.preview_paths.map(&:to_s).sort_by(&:length).reverse directories.first { |dir| host_file.to_s.start_with?(dir) } end
def initialize(*args)
def initialize(*args) if args.size < 2 tag_name = self.class.name.demodulize.underscore.chomp("_tag") super(tag_name, args.first, nil, @name) else super end end
def lookup_host_class
def lookup_host_class host_code_object = if object.is_a?(YARD::CodeObjects::MethodObject) object.parent elsif object.is_a?(YARD::CodeObjects::ClassObject) object end host_code_object&.path&.constantize end
def options
def options tag_parts[:options] end
def parse_options(input, resolve: true)
def parse_options(input, resolve: true) if self.class.supports_options? TagOptionsParser.call(input, { file: host_file, base_dir: host_file&.dirname, eval_context: host_class_instance, resolve: resolve }) else [{}, @text] end end
def resolve_path(path)
def resolve_path(path) return unless host_file dir = path.start_with?(".") ? host_file.dirname : host_file_base_directory Pathname(File.expand_path(path, dir)) end
def tag_parts
def tag_parts if @tag_parts.nil? options, text = parse_options(@text) end @tag_parts ||= {options: options, text: text} end
def text
def text tag_parts[:text] end
def to_s
def to_s value.to_s end