Commit 95686361 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Turn @removed into Tag class.

Also extract base class for @removed and @deprecated.
parent 247ca564
Loading
Loading
Loading
Loading
+3 −30
Original line number Diff line number Diff line
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
        <div class='signature-box deprecated'>
        <p>This #{context[:tagname]} has been <strong>deprecated</strong> #{v}</p>
        #{format(depr[:text])}
        </div>
      EOHTML
    end

  end
end
+41 −0
Original line number Diff line number Diff line
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
        <div class='signature-box #{@key}'>
        <p>This #{context[:tagname]} has been <strong>#{@key}</strong> #{v}</p>
        #{format(depr[:text])}
        </div>
      EOHTML
    end

  end
end
+13 −0
Original line number Diff line number Diff line
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

lib/jsduck/tag/removed.rb

deleted100644 → 0
+0 −36
Original line number Diff line number Diff line
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
        <div class='signature-box removed'>
        <p>This #{@context[:tagname]} has been <strong>removed</strong> #{ver}</p>
        #{format(val[:text])}
        </div>
      EOHTML
    end
  end
end