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_params(params) ⇒ Object
- #render_return(ret) ⇒ 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jsduck/render/subproperties.rb', line 15 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
43 44 45 46 47 48 49 |
# File 'lib/jsduck/render/subproperties.rb', line 43 def render_list(params) return [ "<ul>", params.map {|p| render_single_param(p) }, "</ul>", ] end |
#render_params(params) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/jsduck/render/subproperties.rb', line 36 def render_params(params) return [ '<h3 class="pa">Parameters</h3>', render_list(params), ] end |
#render_return(ret) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jsduck/render/subproperties.rb', line 66 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_single_param(p) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jsduck/render/subproperties.rb', line 51 def render_single_param(p) return [ "<li>", "<span class='pre'>#{p[:name]}</span> : ", p[:html_type], p[:optional] ? " (optional)" : "", "<div class='sub-desc'>", p[:doc], p[:default] ? "<p>Defaults to: <code>#{Util::HTML.escape(p[:default])}</code></p>" : "", p[:properties] && p[:properties].length > 0 ? render(p) : "", "</div>", "</li>", ] end |
#render_throws(throws) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jsduck/render/subproperties.rb', line 81 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 |