diff --git a/lib/jsduck/builtins/deprecated.rb b/lib/jsduck/builtins/deprecated.rb index 3dbe270a9eac357cef9053638bff5e79b158f222..adaaed402ac794990c4e1c04c7e9818b52750593 100644 --- a/lib/jsduck/builtins/deprecated.rb +++ b/lib/jsduck/builtins/deprecated.rb @@ -1,37 +1,10 @@ -require "jsduck/builtins/tag" +require "jsduck/builtins/deprecated_tag" module JsDuck::Builtins - class Deprecated < Tag + class Deprecated < DeprecatedTag def initialize - @pattern = "deprecated" @key = :deprecated - @signature = {:long => "deprecated", :short => "DEP"} - @html_position = :bottom - @multiline = true + super end - - def parse(p) - p.add_tag(:deprecated) - p.skip_horiz_white - p.current_tag[:version] = p.match(/[0-9.]+/) if p.look(/[0-9]/) - end - - def process_doc(tags) - v = {:text => tags[0][:doc] || ""} - v[:version] = tags[0][:version] if tags[0][:version] - v - end - - def to_html(context) - depr = context[:deprecated] - v = depr[:version] ? "since " + depr[:version] : "" - <<-EOHTML -
-

This #{context[:tagname]} has been deprecated #{v}

- #{format(depr[:text])} -
- EOHTML - end - end end diff --git a/lib/jsduck/builtins/deprecated_tag.rb b/lib/jsduck/builtins/deprecated_tag.rb new file mode 100644 index 0000000000000000000000000000000000000000..d64441774d0a5d5f4cd221fde84078a6034ee547 --- /dev/null +++ b/lib/jsduck/builtins/deprecated_tag.rb @@ -0,0 +1,41 @@ +require "jsduck/builtins/tag" + +module JsDuck::Builtins + # Base class for both @deprecated and @removed. Child classes only + # need to define the @key attribute and call #super - all the + # correct behavior will the fall out automatically. + class DeprecatedTag < Tag + def initialize + if @key + @pattern = @key.to_s + @signature = {:long => @key.to_s, :short => @key.to_s[0..2].upcase} + @html_position = :bottom + @multiline = true + end + end + + def parse(p) + p.add_tag(@key) + p.skip_horiz_white + p.current_tag[:version] = p.match(/[0-9.]+/) if p.look(/[0-9]/) + end + + def process_doc(tags) + v = {:text => tags[0][:doc] || ""} + v[:version] = tags[0][:version] if tags[0][:version] + v + end + + def to_html(context) + depr = context[@key] + v = depr[:version] ? "since " + depr[:version] : "" + <<-EOHTML +
+

This #{context[:tagname]} has been #{@key} #{v}

+ #{format(depr[:text])} +
+ EOHTML + end + + end +end diff --git a/lib/jsduck/builtins/removed.rb b/lib/jsduck/builtins/removed.rb new file mode 100644 index 0000000000000000000000000000000000000000..618be181cdd311d3dfa6617fd898afd22197f53a --- /dev/null +++ b/lib/jsduck/builtins/removed.rb @@ -0,0 +1,13 @@ +require "jsduck/builtins/deprecated_tag" + +module JsDuck::Builtins + # To document members that were present in previous version but are + # completely gone now. Other than that it behaves exactly like + # @deprecated. + class Removed < DeprecatedTag + def initialize + @key = :removed + super + end + end +end diff --git a/lib/jsduck/tag/removed.rb b/lib/jsduck/tag/removed.rb deleted file mode 100644 index d32a780a3a28a6ebe3bf5fb1b3d450b2ef87a061..0000000000000000000000000000000000000000 --- a/lib/jsduck/tag/removed.rb +++ /dev/null @@ -1,36 +0,0 @@ -require "jsduck/meta_tag" - -module JsDuck::Tag - # Implementation of @removed tag. - # - # To document members that were present in previous version but are - # completely gone now. Other than that it behaves exactly like @deprecated. - class Removed < JsDuck::MetaTag - def initialize - @name = "removed" - @key = :removed - @signature = {:long => "removed", :short => "REM"} - @multiline = true - end - - def to_value(contents) - text = contents[0] - if text =~ /\A([0-9.]+)(.*)\Z/ - {:version => $1, :text => $2.strip} - else - {:text => text || ""} - end - end - - def to_html(val) - ver = val[:version] ? "since " + val[:version] : "" - <<-EOHTML -
-

This #{@context[:tagname]} has been removed #{ver}

- #{format(val[:text])} -
- EOHTML - end - end -end -