Commit 981882c0 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Turn @since & @new to builtin Tag classes.

For now I'm leaving out the tooltip text implementation for
the @new tag - needs some further refactoring.
parent 1339d1ef
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -257,6 +257,8 @@ task :sdk => :sass do
    "--output", OUT_DIR,
    "--config", "#{SDK_DIR}/extjs/docs/config.json",
    "--examples-base-url", "extjs-build/examples/",
    # "--import", "4.1:../docs.sencha.com/exports/extjs-4.1.1",
    # "--import", "4.2",
    "--seo"
  )
  runner.add_debug
+23 −0
Original line number Diff line number Diff line
require "jsduck/meta_tag"
require "jsduck/logger"
require "jsduck/builtins/boolean_tag"

module JsDuck::Tag
  # Implementation of @new tag.
  class New < JsDuck::MetaTag
module JsDuck::Builtins
  class New < BooleanTag
    def initialize
      @name = "new"
      @key = :new
      @signature = {:long => "&#9733;", :short => "&#9733;"} # unicode black star char
      @boolean = true
    end

    # Initializes the tooltip text.
    #
    # HACK: This is a special method that's only called for the @new
    # tag. It doesn't fit well into the current meta-tags system.  But
    # until we rework the meta-tags system, this will have to do.
    # FIXME: Copy-pasted code from old Boolean tag class, doesn't
    # currently work as it's never called.
    def create_tooltip!(imports, new_since)
      if new_since
        @signature[:tooltip] = "New since #{new_since}"
@@ -24,10 +19,5 @@ module JsDuck::Tag
      end
    end

    def to_value(contents)
      true
    end

  end
end
+32 −0
Original line number Diff line number Diff line
require "jsduck/meta_tag"
require "jsduck/builtins/tag"
require "jsduck/logger"

module JsDuck::Tag
  # Implementation of @since tag.
  class Since < JsDuck::MetaTag
module JsDuck::Builtins
  class Since < Tag
    def initialize
      @name = "since"
      @pattern = "since"
      @key = :since
      @html_position = :bottom
    end

    def to_value(contents)
      if contents.length > 1
    def parse(p)
      p.add_tag(:since)
      p.skip_horiz_white
      p.current_tag[:version] = p.match(/.*$/).strip
    end

    def process_doc(tags)
      if tags.length > 1
        JsDuck::Logger.warn(nil, "Only one @since tag allowed per class/member.")
      end
      contents[0]
      tags[0][:version]
    end

    def to_html(version)
    def to_html(context)
      <<-EOHTML
        <p>Available since: <b>#{version}</b></p>
        <p>Available since: <b>#{context[:since]}</b></p>
      EOHTML
    end

  end
end
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ module JsDuck

    # Adds small star to new classes in the current version.
    def render_new_label(cls)
      if cls[:meta][:new]
      if cls[:new]
        "&nbsp;<span class='new-class' title='New class'>#{stars(1)}</span>"
      else
        n = new_members_count(cls)
@@ -53,7 +53,7 @@ module JsDuck

    # Returns number of new members the class has in the current version
    def new_members_count(cls)
      cls.find_members(:local => true).find_all {|m| m[:meta][:new] && !m[:private] }.length
      cls.find_members(:local => true).find_all {|m| m[:new] && !m[:private] }.length
    end

  end
+6 −6
Original line number Diff line number Diff line
@@ -64,14 +64,14 @@ module JsDuck
      new_versions = build_new_versions_map(versions, new_since)

      relations.each do |cls|
        v = cls[:meta][:since] || class_since(versions, cls)
        cls[:meta][:since] = v
        cls[:meta][:new] = true if new_versions[v]
        v = cls[:since] || class_since(versions, cls)
        cls[:since] = v
        cls[:new] = true if new_versions[v]

        cls.all_local_members.each do |m|
          v = m[:meta][:since] || member_since(versions, cls, m)
          m[:meta][:since] = v
          m[:meta][:new] = true if new_versions[v]
          v = m[:since] || member_since(versions, cls, m)
          m[:since] = v
          m[:new] = true if new_versions[v]
        end
      end
    end
Loading