Class/Module Index [+]

Quicksearch

YARD::Templates::Helpers::BaseHelper

The base helper module included in all templates.

Attributes

object[RW]
owner[R]

@return [CodeObjects::Base] the object representing the current generated

page. Might not be the current {#object} when inside sub-templates.
serializer[RW]

Public Instance Methods

format_object_title(object) click to toggle source

@example

s = format_object_title ModuleObject.new(:root, :MyModuleName)
s # => "Module: MyModuleName"

@param [CodeObjects::Base] object the object to retrieve a title for @return [String] the page title name for a given object

# File lib/yard/templates/helpers/base_helper.rb, line 193
def format_object_title(object)
  case object
  when YARD::CodeObjects::RootObject
    "Top Level Namespace"
  else
    format_object_type(object) + ": " + object.path
  end
end
format_object_type(object) click to toggle source

@example Formatted type of an exception class

o = ClassObject.new(:root, :MyError)
o.superclass = P('RuntimeError')
format_object_type(o) # => "Exception"

@example Formatted type of a method

o = MethodObject.new(:root, :to_s)
format_object_type(o) # => "Method"

@param [CodeObjects::Base] object the object to retrieve the type for @return [String] the human-readable formatted {CodeObjects::Base#type type}

for the object
# File lib/yard/templates/helpers/base_helper.rb, line 179
def format_object_type(object)
  case object
  when YARD::CodeObjects::ClassObject
    object.is_exception? ? "Exception" : "Class"
  else
    object.type.to_s.capitalize
  end
end
format_source(value) click to toggle source

Indents and formats source code

@param [String] value the input source code @return [String] formatted source code

# File lib/yard/templates/helpers/base_helper.rb, line 206
def format_source(value)
  sp = value.split("\n").last[/^(\s+)/, 1]
  num = sp ? sp.size : 0
  value.gsub(/^\s{#{num}}/, '')
end
format_types(list, brackets = true) click to toggle source

Formats a list of return types for output and links each type.

@example Formatting types

format_types(['String', 'Array']) #=> "(String, Array)"

@example Formatting types without surrounding brackets

format_types(['String', 'Array'], false) #=> "String, Array"

@param [Array<String>] list a list of types @param [Boolean] brackets whether to surround the types in brackets @return [String] the formatted list of Ruby types

# File lib/yard/templates/helpers/base_helper.rb, line 165
def format_types(list, brackets = true)
  list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
end
globals() click to toggle source

An object that keeps track of global state throughout the entire template rendering process (including any sub-templates).

@return [OpenStruct] a struct object that stores state @since 0.6.0

# File lib/yard/templates/helpers/base_helper.rb, line 19
def globals; options.globals end
h(text) click to toggle source

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

# File lib/yard/templates/helpers/base_helper.rb, line 37
def h(text)
  text
end
linkify(*args) click to toggle source

Links objects or URLs. This method will delegate to the correct link_ method depending on the arguments passed in.

@example Linking a URL

linkify('http://example.com')

@example Including docstring contents of an object

linkify('include:YARD::Docstring')

@example Linking to an extra file

linkify('file:README')

@example Linking an object by path

linkify('YARD::Docstring')
# File lib/yard/templates/helpers/base_helper.rb, line 54
def linkify(*args)
  if args.first.is_a?(String)
    case args.first
    when %{://}, /^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
      if obj = YARD::Registry.resolve(object.namespace, path)
        link_include_object(obj)
      else
        log.warn "Cannot find object at `#{path}' for inclusion"
        ""
      end
    when /^render:(\S+)/
      path = $1
      if obj = YARD::Registry.resolve(object, path)
        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
run_verifier(list) click to toggle source

Runs a list of objects against the {Verifier} object passed into the template and returns the subset of verified objects.

@param [Array<CodeObjects::Base>] list a list of code objects @return [Array<CodeObjects::Base>] a list of code objects that match

the verifier. If no verifier is supplied, all objects are returned.
# File lib/yard/templates/helpers/base_helper.rb, line 29
def run_verifier(list)
  options.verifier ? options.verifier.run(list) : list
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.