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

Switch to flat list of members in exported JSON.

Also changed Docs app client side to handle the flat members list.
Mostly things got simpler.

As this is a large change, some corners still need to be fixed,
like the --import of JSDuck exports.
parent 07465c2a
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -25,21 +25,12 @@ module JsDuck
      # removes extra data from export
      def compact(cls)
        cls.delete(:doc)
        cls[:members] = compact_members_group(cls[:members])
        cls[:statics] = compact_members_group(cls[:statics])
        cls[:members] = cls[:members].map {|m| compact_member(m) }
        cls[:files] = compact_files(cls[:files])
        cls[:meta] = combine_meta(cls)
        cls
      end

      def compact_members_group(group)
        c_group = {}
        group.each_pair do |type, members|
          c_group[type] = members.map {|m| compact_member(m) }
        end
        c_group
      end

      def compact_member(m)
        m_copy = {}
        [:name, :tagname, :owner, :id].each do |key|
+15 −8
Original line number Diff line number Diff line
@@ -16,12 +16,8 @@ module JsDuck
        # so our modifications on it will be safe.
        h = cls.internal_doc.clone

        h[:members] = {}
        h[:statics] = {}
        TagRegistry.member_type_names.each do |tagname|
          h[:members][tagname] = export_members(cls, {:tagname => tagname, :static => false})
          h[:statics][tagname] = export_members(cls, {:tagname => tagname, :static => true})
        end
        h[:members] = export_members(cls)

        h[:component] = cls.inherits_from?("Ext.Component")
        h[:superclasses] = cls.superclasses.collect {|c| c[:name] }
        h[:subclasses] = @relations.subclasses(cls).collect {|c| c[:name] }.sort
@@ -38,8 +34,19 @@ module JsDuck

      private

      # Looks up members, and sorts them so that constructor method is first
      def export_members(cls, cfg)
      # Generates flat list of all members
      def export_members(cls)
        groups = []
        TagRegistry.member_type_names.each do |tagname|
          groups << export_members_group(cls, {:tagname => tagname, :static => false})
          groups << export_members_group(cls, {:tagname => tagname, :static => true})
        end
        groups.flatten
      end

      # Looks up members of given type, and sorts them so that
      # constructor method is first
      def export_members_group(cls, cfg)
        ms = cls.find_members(cfg)
        ms.sort! {|a,b| a[:name] <=> b[:name] }
        cfg[:tagname] == :method ? constructor_first(ms) : ms
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ module JsDuck
      end

      def render_section(sec)
        members = @cls[:members][sec[:name]] + @cls[:statics][sec[:name]]
        members = @cls[:members].find_all {|m| m[:tagname] == sec[:name] }

        # Skip rendering empty sections
        return [] if members.length == 0
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ module JsDuck::Tag

    def to_html(cls)
      if cls[:enum][:doc_only]
        first = cls[:members][:property][0] || {:name => 'foo', :default => '"foo"'}
        first = cls[:members][0] || {:name => 'foo', :default => '"foo"'}
        [
          "<div class='rounded-box enum-box'>",
          "<p><strong>ENUM:</strong> ",
+7 −21
Original line number Diff line number Diff line
@@ -28,32 +28,18 @@ describe JsDuck::Exporter::Full do
      JsDuck::Exporter::Full.new(JsDuck::Relations.new([cls])).export(cls)
    end

    it "places configs into :members->:cfg" do
      result[:members][:cfg].length.should == 4
    end

    it "places instance methods into :members->:method" do
      result[:members][:method].length.should == 3
    end

    it "places static methods into :statics->:method" do
      result[:statics][:method].length.should == 1
    end

    it "places events into :members->:event" do
      result[:members][:event].length.should == 1
    end

    it "places nothing into :members->:property as there are no properties" do
      result[:members][:property].length.should == 0
    it "places all members inside :members field" do
      result[:members].length.should == 9
    end

    it "sorts configs alphabetically" do
      result[:members][:cfg].map {|m| m[:name] }.should == ["bar", "baz", "foo", "zap"]
      configs = result[:members].find_all {|m| m[:tagname] == :cfg }
      configs.map {|m| m[:name] }.should == ["bar", "baz", "foo", "zap"]
    end

    it "sorts constructor first when sorting methods" do
      result[:members][:method].map {|m| m[:name] }.should == ["constructor", "addBaz", "addFoo"]
    it "sorts constructor first when sorting methods and static methods last" do
      methods = result[:members].find_all {|m| m[:tagname] == :method }
      methods.map {|m| m[:name] }.should == ["constructor", "addBaz", "addFoo", "statGet"]
    end

  end
Loading