Commit 0fb5b018 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add docs word-count to stats module metrics.

parent 641b818d
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ module JsDuck
          :localMembers => cls.all_local_members.length,
          :fanIn => fan_in(cls),
          :fanOut => fan_out(cls),
          :wordCount => class_wc(cls),
        }
      end
    end
@@ -51,6 +52,29 @@ module JsDuck
      @fi_table
    end

    # Counts nr of words in class documentation
    def class_wc(cls)
      cnt = wc(cls[:doc])
      cls.all_local_members.each do |m|
        cnt += wc(m[:doc])
        (m[:params] || []).each {|p| cnt += property_wc(p) }
        (m[:properties] || []).each {|p| cnt += property_wc(p) }
        cnt += wc(m[:return][:doc]) if m[:return]
      end
      cnt
    end

    def property_wc(property)
      cnt = wc(property[:doc] || "")
      (property[:properties] || []).each {|p| cnt += property_wc(p) }
      cnt
    end

    # Strips HTML and counts words in text
    def wc(str)
      str.gsub(/<\/?[^>]*>/, "").scan(/\w+/).length
    end

  end

end
+2 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ Ext.define('Docs.model.Stats', {
        'members',
        'localMembers',
        'fanIn',
        'fanOut'
        'fanOut',
        'wordCount'
    ]
});
+6 −1
Original line number Diff line number Diff line
@@ -44,8 +44,13 @@ Ext.define('Docs.view.stats.Index', {
                },
                {
                    text: 'Fan-out',
                    flex: 1,
                    width: 70,
                    dataIndex: 'fanOut'
                },
                {
                    text: 'Words in docs',
                    flex: 1,
                    dataIndex: 'wordCount'
                }
            ]
        }];