Module: LinkHelpers
- Includes:
- YARDGo::CodeObjects
- Defined in:
- lib/yard-go/helpers.rb
Instance Method Summary collapse
- #anchor_for(obj) ⇒ Object
- #format_object_title(obj) ⇒ Object
- #html_syntax_highlight(source, type = nil) ⇒ Object
- #link_object(obj, title = nil, anchor = nil, relative = true) ⇒ Object
- #link_types(text) ⇒ Object
- #signature(obj, link = true, show_extras = true, full_attr_name = true) ⇒ Object
- #signature_types(meth, link = true) ⇒ Object
Instance Method Details
#anchor_for(obj) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/yard-go/helpers.rb', line 17 def anchor_for(obj) case obj when BareStructObject "type-#{obj.name}" else super(obj) end end |
#format_object_title(obj) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/yard-go/helpers.rb', line 84 def format_object_title(obj) case obj when YARD::CodeObjects::RootObject "Package: #{obj.full_path.split('/').last}" else super(obj) end end |
#html_syntax_highlight(source, type = nil) ⇒ Object
80 81 82 |
# File 'lib/yard-go/helpers.rb', line 80 def html_syntax_highlight(source, type = nil) super(source, type || :go) end |
#link_object(obj, title = nil, anchor = nil, relative = true) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/yard-go/helpers.rb', line 4 def link_object(obj, title = nil, anchor = nil, relative = true) case obj when BareStructObject origobj = object @object = object.namespace if BareStructObject === object link = super(obj.namespace, title || obj.name, anchor_for(obj), true) @object = origobj link else super(obj, title, anchor, relative) end end |
#link_types(text) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/yard-go/helpers.rb', line 70 def link_types(text) text.gsub(/\b(?:[a-z]\w*\.)?[A-Z]\w*:?/) do |m| if m[-1] == ":" m else link_object YARD::Registry.resolve(object, m), m end end end |
#signature(obj, link = true, show_extras = true, full_attr_name = true) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yard-go/helpers.rb', line 26 def signature(obj, link = true, show_extras = true, full_attr_name = true) case obj when FieldObject ret = obj.has_tag?(:return) ? obj.tag(:return).types.join(", ") : "" if link return linkify obj, "<strong>#{obj.name}</strong> #{ret}" else return "<strong>#{obj.name}</strong> #{link_types(ret)}" end when BareStructObject, StructObject, InterfaceObject if link return linkify obj, "<strong>#{obj.name}</strong>" else return "<strong>#{obj.name}</strong> struct" end when FuncObject src = obj.source.split(/\n/).first.sub(/\{\s*$/, '').sub(/(<a\s[^>]+>|\b)#{obj.name.to_s}(<\/a>)?\(/, "<strong>#{obj.name}</strong>(") src = link_types(src) unless link src if link return linkify obj, src else return src end end super(obj, link, show_extras, full_attr_name) end |
#signature_types(meth, link = true) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard-go/helpers.rb', line 56 def signature_types(meth, link = true) meth = convert_method_to_overload(meth) if meth.respond_to?(:object) && !meth.has_tag?(:return) meth = meth.object end val = "" if meth.tag(:return) && meth.tag(:return).types val = meth.tag(:return).types.join(", ") end link ? link_types(val) : val end |