From 956863612a0a937dcb4e59e049abdb7cbd7bb4d3 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Wed, 2 Jan 2013 15:21:24 +0200 Subject: [PATCH] Turn @removed into Tag class. Also extract base class for @removed and @deprecated. --- lib/jsduck/builtins/deprecated.rb | 33 ++------------------- lib/jsduck/builtins/deprecated_tag.rb | 41 +++++++++++++++++++++++++++ lib/jsduck/builtins/removed.rb | 13 +++++++++ lib/jsduck/tag/removed.rb | 36 ----------------------- 4 files changed, 57 insertions(+), 66 deletions(-) create mode 100644 lib/jsduck/builtins/deprecated_tag.rb create mode 100644 lib/jsduck/builtins/removed.rb delete mode 100644 lib/jsduck/tag/removed.rb diff --git a/lib/jsduck/builtins/deprecated.rb b/lib/jsduck/builtins/deprecated.rb index 3dbe270a..adaaed40 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 00000000..d6444177 --- /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 00000000..618be181 --- /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 d32a780a..00000000 --- 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 - -- GitLab