require 'jsduck/util/html' require 'jsduck/util/singleton' module JsDuck module Render # Renders params, return values and everything else that can have # nested subproperties. class Subproperties include Util::Singleton # Renders object properties, which could also be functions in # which case they will be rendered with parameters and return # value. 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 def render_params(params) return [ '

Parameters

', render_list(params), ] end def render_list(params) return [ "", ] end def render_single_param(p) return [ "
  • ", "#{p[:name]} : ", p[:html_type], p[:optional] ? " (optional)" : "", "
    ", p[:doc], p[:default] ? "

    Defaults to: #{Util::HTML.escape(p[:default])}

    " : "", p[:properties] && p[:properties].length > 0 ? render(p) : "", "
    ", "
  • ", ] end def render_return(ret) return [ "

    Returns

    ", "", ] end def render_throws(throws) return [ "

    Throws

    ", "", ] end end end end