Class: JsDuck::Render::Subproperties
- Inherits:
-
Object
- Object
- JsDuck::Render::Subproperties
- Includes:
- Util::Singleton
- Defined in:
- lib/jsduck/render/subproperties.rb
Overview
Renders params, return values and everything else that can have nested subproperties.
Instance Method Summary collapse
-
#render(item) ⇒ Object
Renders object properties, which could also be functions in which case they will be rendered with parameters and return value.
- #render_list(params) ⇒ Object
- #render_new ⇒ Object
- #render_params(params) ⇒ Object
- #render_return(ret) ⇒ Object
- #render_since(param) ⇒ Object
- #render_single_param(p) ⇒ Object
- #render_throws(throws) ⇒ Object
Methods included from Util::Singleton
Instance Method Details
#render(item) ⇒ Object
Renders object properties, which could also be functions in which case they will be rendered with parameters and return value.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jsduck/render/subproperties.rb', line 16 def render(item) doc = [] if item[:type] == "Function" params = item[:properties] # If the name of last property is "return" remove it from # properties list and format as a return value afterwards. if item[:properties].last[:name] == "return" ret = params.last params = params.slice(0, params.length-1) end doc << render_params(params) doc << render_return(ret) if ret else doc << render_list(item[:properties]) end doc end |
#render_list(params) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/jsduck/render/subproperties.rb', line 44 def render_list(params) return [ "<ul>", params.map {|p| render_single_param(p) }, "</ul>", ] end |
#render_new ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jsduck/render/subproperties.rb', line 69 def render_new signature = TagRegistry.get_by_name(:new).signature return [ "<span class='signature'>", "<span class='new' title='#{signature[:tooltip]}'>", signature[:long], "</span>", "</span>", ] end |
#render_params(params) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/jsduck/render/subproperties.rb', line 37 def render_params(params) return [ '<h3 class="pa">Parameters</h3>', render_list(params), ] end |
#render_return(ret) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jsduck/render/subproperties.rb', line 84 def render_return(ret) return [ "<h3 class='pa'>Returns</h3>", "<ul>", "<li>", "<span class='pre'>#{ret[:html_type]}</span>", "<div class='sub-desc'>", ret[:doc], ret[:properties] && ret[:properties].length > 0 ? render(ret) : "", "</div>", "</li>", "</ul>", ] end |
#render_since(param) ⇒ Object
80 81 82 |
# File 'lib/jsduck/render/subproperties.rb', line 80 def render_since(param) TagRegistry.get_by_name(:since).to_html(param) end |
#render_single_param(p) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jsduck/render/subproperties.rb', line 52 def render_single_param(p) return [ "<li>", "<span class='pre'>#{p[:name]}</span> : ", p[:html_type], p[:optional] ? " (optional)" : "", p[:new] ? render_new : "", "<div class='sub-desc'>", p[:doc], p[:default] ? "<p>Defaults to: <code>#{Util::HTML.escape(p[:default])}</code></p>" : "", p[:since] ? render_since(p) : "", p[:properties] && p[:properties].length > 0 ? render(p) : "", "</div>", "</li>", ] end |
#render_throws(throws) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/jsduck/render/subproperties.rb', line 99 def render_throws(throws) return [ "<h3 class='pa'>Throws</h3>", "<ul>", throws.map do |thr| [ "<li>", "<span class='pre'>#{thr[:html_type]}</span>", "<div class='sub-desc'>#{thr[:doc]}</div>", "</li>", ] end, "</ul>", ] end |