Class: JsDuck::Inline::AutoLink

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/inline/auto_link.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link_renderer) ⇒ AutoLink

Returns a new instance of AutoLink.



16
17
18
19
20
21
22
# 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

Instance Attribute Details

#class_contextObject

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



10
11
12
# File 'lib/jsduck/inline/auto_link.rb', line 10

def class_context
  @class_context
end

#doc_contextObject

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



14
15
16
# File 'lib/jsduck/inline/auto_link.rb', line 14

def doc_context
  @doc_context
end

Instance Method Details

#replace(input) ⇒ Object

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 “.”



41
42
43
44
45
46
47
# 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