diff --git a/lib/jsduck.rb b/lib/jsduck.rb index e6c7b22e87fa03d6b7491482fe0ec302250532bb..81b3ba6e3345e3a7d52c18749a0fef79f9da6bdd 100755 --- a/lib/jsduck.rb +++ b/lib/jsduck.rb @@ -10,6 +10,7 @@ require 'jsduck/doc_links' require 'jsduck/table' require 'jsduck/cfg_table' require 'jsduck/property_table' +require 'jsduck/param_list' require 'jsduck/method_table' require 'jsduck/event_table' require 'jsduck/page' diff --git a/lib/jsduck/event_table.rb b/lib/jsduck/event_table.rb index 1864e1a74c9f393946043c2566f6415de17446c5..16b9f85a475ab29a9cec404be490de15364615bc 100644 --- a/lib/jsduck/event_table.rb +++ b/lib/jsduck/event_table.rb @@ -8,10 +8,11 @@ module JsDuck @title = "Public Events" @column_title = "Event" @row_class = "method-row" + @param_list = ParamList.new end def signature_suffix(item) - " : " + short_param_list(item) + " : " + @param_list.short(item[:params]) end end diff --git a/lib/jsduck/method_table.rb b/lib/jsduck/method_table.rb index cf63caefc224dea37463bcd2d63f9bb8ca2774b1..feef3ff6d4bcca8a289967ccf0cbc667d332a184 100644 --- a/lib/jsduck/method_table.rb +++ b/lib/jsduck/method_table.rb @@ -8,10 +8,15 @@ module JsDuck @title = "Public Methods" @column_title = "Method" @row_class = "method-row" + @param_list = ParamList.new end def signature_suffix(item) - short_param_list(item) + " : " + (item[:return] ? (item[:return][:type] || "void") : "void") + @param_list.short(item[:params]) + " : " + return_type(item) + end + + def return_type(item) + item[:return] ? (item[:return][:type] || "void") : "void" end end diff --git a/lib/jsduck/param_list.rb b/lib/jsduck/param_list.rb new file mode 100644 index 0000000000000000000000000000000000000000..486dc2fcf80c66a475b4d889858a7e0e54d3e2b5 --- /dev/null +++ b/lib/jsduck/param_list.rb @@ -0,0 +1,30 @@ +module JsDuck + + # Renders method/event parameter lists + class ParamList + # Creates short parameters list used in signatures. + def short(params) + if params.length > 0 + "( " + params.collect {|p| format_short(p) }.join(", ") + " )" + else + "()" + end + end + + def format_short(param) + type = param[:type] || "Object" + name = param[:name] || "" + str = "#{type} #{name}" + if optional?(param) + "[" + str + "]" + else + str + end + end + + def optional?(param) + return param[:doc] =~ /\(optional\)/ + end + end + +end diff --git a/lib/jsduck/table.rb b/lib/jsduck/table.rb index 1af2119ecea8da34e7edc735cdfa96f8d361d78d..f4b3fca7dd35665202fd8261ce8803061a70ec67 100644 --- a/lib/jsduck/table.rb +++ b/lib/jsduck/table.rb @@ -45,26 +45,6 @@ module JsDuck return "#{item[:name]}" + signature_suffix(item) end - # Creates parameter list used in method and event signature. - def short_param_list(item) - if item[:params].length == 0 - return "()" - end - - params = item[:params].collect do |p| - type = p[:type] || "Object" - name = p[:name] || "" - str = "#{type} #{name}" - if p[:doc] =~ /\(optional\)/ - "[" + str + "]" - else - str - end - end - - return "( " + params.join(", ") + " )" - end - # 116 chars is also where ext-doc makes its cut, but unlike # ext-doc we only make the cut when there's more than 120 chars. #