Module: YARD::AppendixPlugin::AppendixLinker

Included in:
Templates::Helpers::HtmlHelper
Defined in:
lib/yard-appendix/templates/helpers/html_helper.rb

Instance Method Summary collapse

Instance Method Details



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/yard-appendix/templates/helpers/html_helper.rb', line 59

def link_appendix(in_title)
  appendix, title = nil, in_title.to_s.strip.to_sym
  ns = nil # used for reporting in case we couldn't locate it

  if object
    # try in the object scope
    ns = object
    appendix = YARD::Registry.at(".appendix.#{object.path}.#{title}")

    # try in the object's namespace scope
    if appendix.nil? && object.respond_to?(:namespace)
      ns = object.namespace
      appendix = YARD::Registry.at(".appendix.#{object.namespace.path}.#{title}")
    end
  # else
    # this shouldn't happen (use stub!(:object) in specs)
    # appendix = YARD::Registry.all(:appendix).select { |a| a.name == title }.first
  end

  unless appendix.nil?
    link = url_for(appendix, nil, true)
    link = link ? link_url(link, appendix.title, :title => h(appendix.title)) : appendix.title

    return "<span class='object_link'>#{link}</span>"
  end

  log.warn %Q[unable to locate referenced appendix '#{title}'#{ns ? " in namespace " + ns.name.to_s : ''}]
  nil
end

#linkify(link, *args) ⇒ Object

Note:

Appendix links will be resolved only within the namespace they’re defined in (class or module).

Handles reference links to Appendix objects in @see tags by printing out their readable titles in the anchor text and tooltip.

Delegates to YARD::Templates::Helpers::HtmlHelper#linkify if the @see tag syntax does not qualify as an appendix one.

Note that the syntax expected is ‘@see Appendix: APPENDIX_NAME` where only the `APPENDIX_NAME` is variable.

Examples:

Referencing appendix objects:


# Some method description.
# ...
# @see Appendix: Bananas
def some_method()
end


49
50
51
52
53
54
55
56
57
# File 'lib/yard-appendix/templates/helpers/html_helper.rb', line 49

def linkify(link, *args)
  if link == 'Appendix:' && !args.empty?
    if res = link_appendix(args.first)
      return res
    end
  end

  super(link, *args)
end