Module: YARD::Templates::Helpers::HtmlHelper
- Defined in:
- lib/yard-js/core_ext/yard/templates.rb
Instance Method Summary collapse
- #link_object(obj, otitle = nil, anchor = nil, relative = true) ⇒ Object
- #signature(meth, link = true, show_extras = true, full_attr_name = true) ⇒ Object
- #signature_types(meth, link = true) ⇒ Object
Instance Method Details
#link_object(obj, otitle = nil, anchor = nil, relative = true) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yard-js/core_ext/yard/templates.rb', line 5 def link_object(obj, otitle = nil, anchor = nil, relative = true) return otitle if obj.nil? obj = Registry.resolve(object, obj, true, true) if obj.is_a?(String) if !otitle && obj.root? title = "Top Level Namespace" elsif otitle title = otitle.to_s elsif object.is_a?(CodeObjects::Base) # Check if we're linking to a class method in the current # object. If we are, create a title in the format of # "CurrentClass.method_name" title = h(object.relative_path(obj)) if obj.is_a?(YARDJS::CodeObjects::PropertyObject) && obj.property_type == :function title += '()' elsif obj.title != obj.path title = h(obj.title) end else title = h(obj.to_s) end return title unless serializer return title if obj.is_a?(CodeObjects::Proxy) link = url_for(obj, anchor, relative) link = link ? link_url(link, title, :title => h("#{obj.title} (#{obj.type})")) : title "<span class='object_link'>" + link + "</span>" end |
#signature(meth, link = true, show_extras = true, full_attr_name = true) ⇒ Object
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/yard-js/core_ext/yard/templates.rb', line 62 def signature(meth, link = true, show_extras = true, full_attr_name = true) meth = convert_method_to_overload(meth) small_type = true type = signature_types(meth, link) args = '' name = meth.name.to_s if meth.constructor? type, name = 'new ', meth.namespace.path.gsub(/_\d+/, '') end if meth.property_type == :function if meth.parameters args = meth.parameters.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ") end args = "(#{args})" end if YARDJS::Tags::CallbackTag === meth small_type = false type = '' args += ' { ... }' end extras = [] extras_text = '' if show_extras extras << 'static' if meth.tag(:static) extras << 'readonly' if meth.tag(:readonly) extras << 'writeonly' if meth.tag(:writeonly) extras << 'readwrite' if !meth.tag(:readonly) && !meth.tag(:writeonly) && meth.property_type != :function extras << meth.visibility if meth.visibility != :public extras_text = ' <span class="extras">(' + extras.join(", ") + ')</span>' unless extras.empty? end if small_type title = "<small>%s</small><strong>%s</strong>%s" % [type, h(name), args] else title = "%s<strong>%s</strong>%s" % [type, h(name), args] end if link link_title = h(name) obj = meth.respond_to?(:object) ? meth.object : meth url = url_for(object, obj) link_url(url, title, :title => link_title) + extras_text else title + extras_text end end |
#signature_types(meth, link = true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yard-js/core_ext/yard/templates.rb', line 33 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 return unless meth type = .default_return || "" if meth.tag(:return) && meth.tag(:return).types types = meth.(:return).map {|t| t.types ? t.types : [] }.flatten.uniq first = link ? h(types.first) : format_types([types.first], false) if types.size == 2 && types.last == 'null' type = first + '<sup>?</sup>' elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/ type = first + '<sup>+</sup>' elsif types.size > 2 type = [first, '...'].join(', ') elsif types == ['void'] && .hide_void_return type = "" else type = link ? h(types.join(", ")) : format_types(types, false) end elsif !type.empty? type = link ? h(type) : format_types([type], false) end type = "(#{type}) " unless type.empty? type end |