diff --git a/lib/jsduck/class_formatter.rb b/lib/jsduck/class_formatter.rb index 6b3d8cc55391290194a9f79e87ae894f6bb7e973..43c5e310f07ca900cb725173b15f803f2dc06b8e 100644 --- a/lib/jsduck/class_formatter.rb +++ b/lib/jsduck/class_formatter.rb @@ -48,6 +48,7 @@ module JsDuck m[:html_type] = (@include_types && !is_css_tag) ? format_type(m[:type]) : m[:type] if m[:type] m[:params] = m[:params].map {|p| format_item(p, is_css_tag) } if m[:params] m[:return] = format_item(m[:return], is_css_tag) if m[:return] + m[:throws] = m[:throws].map {|t| format_item(t, is_css_tag) } if m[:throws] m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties] m[:html_meta] = format_meta_data(m) m diff --git a/lib/jsduck/doc_parser.rb b/lib/jsduck/doc_parser.rb index 5a639ee1ce4b5124b725805801ea9da36c100f91..1e9c6e3805a9d417cc3fe0aa281af0d7f33b35c1 100644 --- a/lib/jsduck/doc_parser.rb +++ b/lib/jsduck/doc_parser.rb @@ -132,6 +132,8 @@ module JsDuck at_alias elsif look(/@var\b/) at_var + elsif look(/@throws\b/) + at_throws elsif look(/@inheritable\b/) boolean_at_tag(/@inheritable/, :inheritable) elsif look(/@accessor\b/) @@ -276,6 +278,14 @@ module JsDuck skip_white end + # matches @throws {type} ... + def at_throws + match(/@throws/) + add_tag(:throws) + maybe_type + skip_white + end + # matches @type {type} or @type type # # The presence of @type implies that we are dealing with property. diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index 999107ab1258ccb20670ca419ef91a723c3cc9e5..ac54bc2e85a4527ff8bf9d4d55de007efd2875cc 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -162,6 +162,7 @@ module JsDuck :doc => detect_doc(docs), :params => detect_params(:method, doc_map, code), :return => detect_return(doc_map, name == "constructor" ? "Object" : "undefined"), + :throws => detect_throws(doc_map), }, doc_map) end @@ -477,6 +478,17 @@ module JsDuck } end + def detect_throws(doc_map) + return unless doc_map[:throws] + + doc_map[:throws].map do |throws| + { + :type => throws[:type] || "Object", + :doc => throws[:doc] || "", + } + end + end + # Combines :doc-s of most tags # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) diff --git a/lib/jsduck/renderer.rb b/lib/jsduck/renderer.rb index f0ea108bc47e9dffbf206fbc34eeb033ccccc444..844d84a68bfdf1d7d1b543e8271c40ec34b6cff2 100644 --- a/lib/jsduck/renderer.rb +++ b/lib/jsduck/renderer.rb @@ -318,6 +318,10 @@ module JsDuck doc << render_return(ret) end + if item[:throws] + doc << render_throws(item[:throws]) + end + doc end @@ -351,6 +355,22 @@ module JsDuck "", ] end + + def render_throws(throws) + return [ + "

Throws

", + "", + ] + end end end diff --git a/lib/jsduck/tag/throws.rb b/lib/jsduck/tag/throws.rb deleted file mode 100644 index b3176bd94d205d6daf0647462d0b3157dc6610ac..0000000000000000000000000000000000000000 --- a/lib/jsduck/tag/throws.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "jsduck/meta_tag" -require "jsduck/logger" - -module JsDuck::Tag - class Throws < JsDuck::MetaTag - def initialize - @name = "throws" - @key = :throws - @signature = {:long => "throws", :short => "THR"} - @multiline = true - end - - def to_value(tags) - tags.map do | throws | - if throws =~ /\A\{([\w\.]+)\}\s+([^ ].*)\Z/m - {:type => $1, :doc => $2.strip} - else - {:type => "Object", :doc => throws} - end - end - end - - def to_html(values) - return if values.length == 0 - - html = values.map do | throws | - <<-EOHTML -
  • - #{throws[:type]} -
    -

    #{throws[:doc]}

    -
    -
  • - EOHTML - end.join - - return <<-EOHTML -

    Throws

    - - EOHTML - end - - end -end diff --git a/spec/aggregator_throws_spec.rb b/spec/aggregator_throws_spec.rb index 41988c96a73cc554363acef8a652ef3a8e28341e..e5749a968fd9bf13c520e39f74360eed89e2a2c2 100644 --- a/spec/aggregator_throws_spec.rb +++ b/spec/aggregator_throws_spec.rb @@ -21,15 +21,15 @@ describe JsDuck::Aggregator do end it "detects one throws tag" do - @doc[:meta][:throws].length.should == 1 + @doc[:throws].length.should == 1 end it "detects type of exception" do - @doc[:meta][:throws][0][:type].should == "Error" + @doc[:throws][0][:type].should == "Error" end it "detects description" do - @doc[:meta][:throws][0][:doc].should == "Some text\non multiple lines." + @doc[:throws][0][:doc].should == "Some text\non multiple lines." end end @@ -44,11 +44,11 @@ describe JsDuck::Aggregator do end it "detects type as Object" do - @doc[:meta][:throws][0][:type].should == "Object" + @doc[:throws][0][:type].should == "Object" end it "detects description" do - @doc[:meta][:throws][0][:doc].should == "Some description" + @doc[:throws][0][:doc].should == "Some description" end end @@ -64,7 +64,7 @@ describe JsDuck::Aggregator do end it "detects two throws tags" do - @doc[:meta][:throws].length.should == 2 + @doc[:throws].length.should == 2 end end