Commit 3f4b3620 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement @component tag (normally auto-detected).

Instead of checking for cls.inherits_from("Ext.Component") when
generating class icons, we can simply check if the class has the
component tag.

Process::Components takes care of auto-detecting components, so one
rarely needs to actually use @component tag.
parent 5beeace4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ require 'jsduck/process/inherit_doc'
require 'jsduck/process/versions'
require 'jsduck/process/return_values'
require 'jsduck/process/fires'
require 'jsduck/process/components'
require 'jsduck/process/lint'
require 'jsduck/process/no_doc'
require 'jsduck/process/circular_deps'
@@ -71,6 +72,7 @@ module JsDuck
      Process::Versions.new(relations, opts).process_all!
      Process::ReturnValues.new(relations).process_all!
      Process::Fires.new(relations).process_all!
      Process::Components.new(relations).process_all!
      Process::Lint.new(relations).process_all!
      Process::NoDoc.new(relations).process_all!
      relations
+19 −0
Original line number Diff line number Diff line
module JsDuck
  module Process

    # Auto-detects classes inheriting from Ext.Component, and marks
    # them as :component.
    class Components
      def initialize(relations)
        @relations = relations
      end

      def process_all!
        @relations.each do |cls|
          cls[:component] = true if cls.inherits_from?("Ext.Component")
        end
      end
    end

  end
end
+13 −0
Original line number Diff line number Diff line
require "jsduck/tag/boolean_tag"

module JsDuck::Tag
  # The @component tag should be rarely used explicitly as it gets
  # auto-detected by Process::Components for any component inheriting
  # from Ext.Component.
  class Component < BooleanTag
    def initialize
      @pattern = "component"
      super
    end
  end
end
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ module JsDuck
      def self.class_icon(cls)
        if cls[:singleton]
          "icon-singleton"
        elsif cls.inherits_from?("Ext.Component")
        elsif cls[:component]
          "icon-component"
        else
          "icon-class"
+68 −0
Original line number Diff line number Diff line
require "mini_parser"

describe JsDuck::Aggregator do
  def parse(string)
    Helper::MiniParser.parse(string, {:components => true})
  end

  describe "class without @component" do
    let(:cls) do
      parse(<<-EOS)["Foo"]
        /** */
        Ext.define("Foo", {
        });
      EOS
    end

    it "does not get the :component flag" do
      cls[:component].should_not == true
    end
  end

  describe "class with @component" do
    let(:cls) do
      parse(<<-EOS)["Foo"]
        /**
         * Some class
         * @component
         */
        Ext.define("Foo", {
        });
      EOS
    end

    it "gets the :component flag" do
      cls[:component].should == true
    end
  end

  describe "class inheriting from Ext.Component" do
    let(:cls) do
      parse(<<-EOS)["Foo"]
        /** */
        Ext.define("Foo", {
            extend: "Ext.Component"
        });
      EOS
    end

    it "gets the :component flag" do
      cls[:component].should == true
    end
  end

  describe "the Ext.Component class itself" do
    let(:cls) do
      parse(<<-EOS)["Ext.Component"]
        /** */
        Ext.define("Ext.Component", {
        });
      EOS
    end

    it "also gets the :component flag" do
      cls[:component].should == true
    end
  end

end
Loading