class JsDuck::Inline::AutoLink

Takes care of the auto-detection of links in text.

Attributes

class_context[RW]

Sets up instance to work in context of particular class, so it knows that blah is in context of SomeClass.

doc_context[RW]

Sets up instance to work in context of particular doc object. Used for error reporting.

Public Class Methods

new(link_renderer) click to toggle source
# File lib/jsduck/inline/auto_link.rb, line 16
def initialize(link_renderer)
  @class_context = ""
  @doc_context = {}
  @relations = link_renderer.relations
  @renderer = link_renderer
  @magic_link_re = magic_link_re
end

Public Instance Methods

replace(input) click to toggle source

Looks input text for patterns like:

My.ClassName
MyClass#method
#someProperty

and converts them to links, as if they were surrounded with {@link} tag. One notable exception is that Foo is not created to link, even when Foo class exists, but Foo.Bar is. This is to avoid turning normal words into links. For example:

Math involves a lot of numbers. Ext JS is a JavaScript framework.

In these sentences we don't want to link “Math” and “Ext” to the corresponding JS classes. And that's why we auto-link only class names containing a dot “.”

# File lib/jsduck/inline/auto_link.rb, line 41
def replace(input)
  input.gsub(@magic_link_re) do
    cls = $1 || $3
    member = $2 || $4
    replace_magic_link(cls, member)
  end
end

Private Instance Methods

split_to_cls_and_member(str) click to toggle source
# File lib/jsduck/inline/auto_link.rb, line 94
def split_to_cls_and_member(str)
  parts = str.split(/\./)
  return [parts.slice(0, parts.length-1).join("."), parts.last]
end