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

Move injection of @new tag tooltip to Process::Versions.

This class is doing with the processing of @new and @since tags already,
so it might as well take care of this @new related task.

This gets rid of the special #options= method in Tag::New and
TagRegistry.
parent 17e7c380
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -152,7 +152,6 @@ module JsDuck
      validate

      @custom_tag_paths.each {|path| TagRegistry.load_from(path) }
      TagRegistry.options = self
    end

    def create_option_parser
+15 −0
Original line number Diff line number Diff line
require 'jsduck/process/importer'
require 'jsduck/tag_registry'

module JsDuck
  module Process
@@ -6,6 +7,8 @@ module JsDuck
    # Generates @since and @new tags by importing JSDuck exports of
    # older versions of the same project and looking in which version
    # a class or method first appeared.
    #
    # Additionally here the tooltip text for @new tag gets injected.
    class Versions
      def initialize(relations, opts={}, importer=nil)
        @relations = relations
@@ -16,6 +19,8 @@ module JsDuck

      # Loads in exported docs and generates @since and @new tags.
      def process_all!
        init_new_tag_tooltip!

        if @opts[:imports].length > 0
          generate_since_tags(@importer.import(@opts[:imports]))
        end
@@ -23,6 +28,16 @@ module JsDuck

      private

      # Initializes the tooltip text for the signature of @new tag.
      def init_new_tag_tooltip!
        signature = TagRegistry.get_by_key(:new).signature
        if @opts[:new_since]
          signature[:tooltip] = "New since #{@opts[:new_since]}"
        elsif @opts[:imports].length > 0
          signature[:tooltip] = "New since #{@opts[:imports].last[:version]}"
        end
      end

      # Using the imported versions data, adds @since tags to all
      # classes/members.
      def generate_since_tags(versions)
+3 −16
Original line number Diff line number Diff line
@@ -4,22 +4,9 @@ module JsDuck::Tag
  class New < BooleanTag
    def initialize
      @key = :new
      @signature = {:long => "&#9733;", :short => "&#9733;"} # unicode black star char
      # unicode black star char
      # A :tooltip field gets injected to this signature in Process::Versions
      @signature = {:long => "&#9733;", :short => "&#9733;"}
    end

    # Initializes the tooltip text.
    #
    # Gets passed the options object containing command line parameters.
    #
    # FIXME: This method is exclusively called only for this New tag
    # class.  Figure out some way to generalize this.
    def options=(opts)
      if opts.new_since
        @signature[:tooltip] = "New since #{opts.new_since}"
      elsif opts.imports.length > 0
        @signature[:tooltip] = "New since #{opts.imports.last[:version]}"
      end
    end

  end
end
+0 −5
Original line number Diff line number Diff line
@@ -113,11 +113,6 @@ module JsDuck
    def assets=(assets)
      @keys[:aside].assets = assets
    end

    # Passes command line options to @new tag
    def options=(opts)
      @keys[:new].options = opts
    end
  end

end
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ describe JsDuck::Process::Versions do
        {:name => "ExplicitNewClass", :new => true, :alternateClassNames => []},
      ].map {|cfg| JsDuck::Class.new(cfg) }

      JsDuck::Process::Versions.new(@relations, {:imports => [1,2,3]}, importer).process_all!
      JsDuck::Process::Versions.new(@relations, {:imports => @versions}, importer).process_all!

      # build className/member index for easy lookup in specs
      @stuff = {}
@@ -172,7 +172,7 @@ describe JsDuck::Process::Versions do
        {:name => "NewClass", :alternateClassNames => []},
      ].map {|cfg| JsDuck::Class.new(cfg) }

      JsDuck::Process::Versions.new(@relations, {:imports => [1,2,3], :new_since => "2.0"}, importer).process_all!
      JsDuck::Process::Versions.new(@relations, {:imports => @versions, :new_since => "2.0"}, importer).process_all!
    end

    # @since