Loading lib/jsduck/tree.rb +3 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ module JsDuck :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [] } @packages = {"" => @root} Loading @@ -30,15 +29,15 @@ module JsDuck # Sorts all child nodes, and recursively all child packages. def sort_tree(node) node[:children].sort! {|a,b| compare(a, b) } node[:children].find_all {|c| c[:cls] == "package" }.each {|c| sort_tree(c) } node[:children].find_all {|c| c[:children] }.each {|c| sort_tree(c) } end # Comparson method that sorts package nodes before class nodes. def compare(a, b) if a[:cls] == b[:cls] if a[:isClass] == b[:isClass] a[:text].casecmp(b[:text]) else a[:cls] == "package" ? -1 : 1 a[:isClass] ? 1 : -1 end end Loading Loading @@ -73,7 +72,6 @@ module JsDuck :id => cls.full_name, :isClass => true, :iconCls => class_icon(cls), :cls => "cls", :leaf => true } end Loading @@ -94,8 +92,6 @@ module JsDuck :id => "pkg-#{name}", :text => Class.short_name(name), :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [] } end Loading spec/tree_spec.rb +5 −17 Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ describe JsDuck::Tree do @tree[:iconCls].should == "icon-docs" end it "with singleClickExpand = true" do @tree[:singleClickExpand].should == true end it "with as many children as there are root packages" do @tree[:children].length.should == 1 end Loading @@ -45,14 +41,6 @@ describe JsDuck::Tree do @package[:iconCls].should == "icon-pkg" end it "with cls = 'package'" do @package[:cls].should == "package" end it "with singleClickExpand = true" do @package[:singleClickExpand].should == true end it "with as many children as there are classes inside this packages" do @package[:children].length.should == 2 end Loading Loading @@ -129,15 +117,15 @@ describe JsDuck::Tree, "lowercase package name" do end it "gets root package node" do @root[:cls].should == 'package' @root[:isClass].should_not == true end it "gets middle package node" do @middle[:cls].should == 'package' @middle[:isClass].should_not == true end it "gets leaf class node" do @leaf[:cls].should == 'cls' @leaf[:isClass].should == true end end Loading @@ -153,11 +141,11 @@ describe JsDuck::Tree, "uppercase package name" do end it "gets root package node" do @root[:cls].should == 'package' @root[:isClass].should_not == true end it "gets middle class node" do @middle[:cls].should == 'cls' @middle[:isClass].should == true end it "gets class name containing package name" do Loading Loading
lib/jsduck/tree.rb +3 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ module JsDuck :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [] } @packages = {"" => @root} Loading @@ -30,15 +29,15 @@ module JsDuck # Sorts all child nodes, and recursively all child packages. def sort_tree(node) node[:children].sort! {|a,b| compare(a, b) } node[:children].find_all {|c| c[:cls] == "package" }.each {|c| sort_tree(c) } node[:children].find_all {|c| c[:children] }.each {|c| sort_tree(c) } end # Comparson method that sorts package nodes before class nodes. def compare(a, b) if a[:cls] == b[:cls] if a[:isClass] == b[:isClass] a[:text].casecmp(b[:text]) else a[:cls] == "package" ? -1 : 1 a[:isClass] ? 1 : -1 end end Loading Loading @@ -73,7 +72,6 @@ module JsDuck :id => cls.full_name, :isClass => true, :iconCls => class_icon(cls), :cls => "cls", :leaf => true } end Loading @@ -94,8 +92,6 @@ module JsDuck :id => "pkg-#{name}", :text => Class.short_name(name), :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [] } end Loading
spec/tree_spec.rb +5 −17 Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ describe JsDuck::Tree do @tree[:iconCls].should == "icon-docs" end it "with singleClickExpand = true" do @tree[:singleClickExpand].should == true end it "with as many children as there are root packages" do @tree[:children].length.should == 1 end Loading @@ -45,14 +41,6 @@ describe JsDuck::Tree do @package[:iconCls].should == "icon-pkg" end it "with cls = 'package'" do @package[:cls].should == "package" end it "with singleClickExpand = true" do @package[:singleClickExpand].should == true end it "with as many children as there are classes inside this packages" do @package[:children].length.should == 2 end Loading Loading @@ -129,15 +117,15 @@ describe JsDuck::Tree, "lowercase package name" do end it "gets root package node" do @root[:cls].should == 'package' @root[:isClass].should_not == true end it "gets middle package node" do @middle[:cls].should == 'package' @middle[:isClass].should_not == true end it "gets leaf class node" do @leaf[:cls].should == 'cls' @leaf[:isClass].should == true end end Loading @@ -153,11 +141,11 @@ describe JsDuck::Tree, "uppercase package name" do end it "gets root package node" do @root[:cls].should == 'package' @root[:isClass].should_not == true end it "gets middle class node" do @middle[:cls].should == 'cls' @middle[:isClass].should == true end it "gets class name containing package name" do Loading