module YARD::Templates::Helpers::BaseHelper

def format_object_title(object)

Returns:
  • (String) - the page title name for a given object

Parameters:
  • object (CodeObjects::Base) -- the object to retrieve a title for
def format_object_title(object)
  case object
  when YARD::CodeObjects::RootObject
    "Top Level Namespace"
  else
    format_object_type(object) + ": " + object.title
  end
end

def format_object_type(object)

Returns:
  • (String) - the human-readable formatted {CodeObjects::Base#type #type}

Parameters:
  • object (CodeObjects::Base) -- the object to retrieve the type for

Other tags:
    Example: Formatted type of a method -
    Example: Formatted type of an exception class -
def format_object_type(object)
  case object
  when YARD::CodeObjects::ClassObject
    object.is_exception? ? "Exception" : "Class"
  else
    object.type.to_s.capitalize
  end
end

def format_source(value)

Returns:
  • (String) - formatted source code

Parameters:
  • value (String) -- the input source code
def format_source(value)
  sp = value.split("\n").last[/^(\s+)/, 1]
  num = sp ? sp.size : 0
  value.gsub(/^\s{#{num}}/, '')
end

def format_types(list, brackets = true)

Returns:
  • (String) - the formatted list of Ruby types

Parameters:
  • brackets (Boolean) -- whether to surround the types in brackets
  • list (Array) -- a list of types

Other tags:
    Example: Formatting types without surrounding brackets -
    Example: Formatting types -
def format_types(list, brackets = true)
  list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
end

def globals; options.globals end

Other tags:
    Since: - 0.6.0

Returns:
  • (OpenStruct) - a struct object that stores state
def globals; options.globals end

def h(text)

be some helper to "clean up" text for whatever, this is it.
Escapes text. This is used a lot by the HtmlHelper and there should
def h(text)
  text
end

def link_file(filename, title = nil, anchor = nil) # rubocop:disable Lint/UnusedMethodArgument

Other tags:
    Since: - 0.5.5

Returns:
  • (String) - the link to the file

Parameters:
  • anchor (String) -- optional anchor
  • title (String) -- the title of the link
  • filename (String) -- the filename to link to
def link_file(filename, title = nil, anchor = nil) # rubocop:disable Lint/UnusedMethodArgument
  return filename.filename if CodeObjects::ExtraFileObject === filename
  filename
end

def link_include_file(file)

Returns:
  • (String) - the file's contents

Parameters:
  • file (String) -- the filename to include

Other tags:
    Since: - 0.7.0
def link_include_file(file)
  File.read(file)
end

def link_include_object(obj)

Returns:
  • (String) - the object's docstring (no tags)

Parameters:
  • obj (CodeObjects::Base) -- the object to include

Other tags:
    Since: - 0.6.0
def link_include_object(obj)
  obj.docstring
end

def link_object(obj, title = nil)

Returns:
  • (String) - the linked object

Parameters:
  • title (String) -- the title to use for the link
  • obj (CodeObjects::Base) -- the object to link to
def link_object(obj, title = nil)
  return title if title
  case obj
  when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy
    obj.title
  when String, Symbol
    P(obj).title
  else
    obj
  end
end

def link_url(url, title = nil, params = nil) # rubocop:disable Lint/UnusedMethodArgument

Returns:
  • (String) - the linked URL

Parameters:
  • params (Hash) -- optional parameters for the link
  • title (String) -- the optional title to display the link as
  • url (String) -- the URL to link to
def link_url(url, title = nil, params = nil) # rubocop:disable Lint/UnusedMethodArgument
  url
end

def linkify(*args)

Other tags:
    Example: Linking an object by path -
    Example: Linking to an extra file -
    Example: Including docstring contents of an object -
    Example: Linking a URL -
def linkify(*args)
  if args.first.is_a?(String)
    case args.first
    when %r{://}, /^mailto:/
      link_url(args[0], args[1], {:target => '_parent'}.merge(args[2] || {}))
    when /^include:file:(\S+)/
      file = $1
      relpath = File.relative_path(Dir.pwd, File.expand_path(file))
      if relpath =~ /^\.\./
        log.warn "Cannot include file from path `#{file}'"
        ""
      elsif File.file?(file)
        link_include_file(file)
      else
        log.warn "Cannot find file at `#{file}' for inclusion"
        ""
      end
    when /^include:(\S+)/
      path = $1
      obj = YARD::Registry.resolve(object.namespace, path)
      if obj
        link_include_object(obj)
      else
        log.warn "Cannot find object at `#{path}' for inclusion"
        ""
      end
    when /^render:(\S+)/
      path = $1
      obj = YARD::Registry.resolve(object, path)
      if obj
        opts = options.dup
        opts.delete(:serializer)
        obj.format(opts)
      else
        ''
      end
    when /^file:(\S+?)(?:#(\S+))?$/
      link_file($1, args[1] ? args[1] : nil, $2)
    else
      link_object(*args)
    end
  else
    link_object(*args)
  end
end

def owner; (defined?(@owner) && @owner) || object.namespace end

def owner; (defined?(@owner) && @owner) || object.namespace end

def run_verifier(list)

Returns:
  • (Array) - a list of code objects that match

Parameters:
  • list (Array) -- a list of code objects
def run_verifier(list)
  options.verifier ? options.verifier.run(list) : list
end