Loading lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -215,7 +215,7 @@ module JsDuck # Given all classes, generates namespace tree and writes it # in JSON form into a file. def write_tree(filename, relations) tree = Tree.new.create(relations.classes) tree = Tree.new.create(relations.classes, @guides) icons = TreeIcons.new.extract_icons(tree) js = "Docs.classData = " + JSON.generate( tree ) + ";" js += "Docs.icons = " + JSON.generate( icons ) + ";" Loading lib/jsduck/guides.rb +10 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,16 @@ module JsDuck EOHTML end # Iterates over each guide def each(&block) @guides.each &block end # Returns number of guides def length @guides.length end end end lib/jsduck/tree.rb +24 −5 Original line number Diff line number Diff line Loading @@ -20,9 +20,10 @@ module JsDuck # Given list of class documentation objects returns a # tree-structure that can be turned into JSON that's needed by # documentation browser interface. def create(docs) def create(docs, guides=[]) docs.each {|cls| add_class(cls) } sort_tree(@root) add_guides(guides) @root end Loading @@ -34,10 +35,10 @@ module JsDuck # Comparson method that sorts package nodes before class nodes. def compare(a, b) if a[:isClass] == b[:isClass] if a[:leaf] == b[:leaf] a[:text].casecmp(b[:text]) else a[:isClass] ? 1 : -1 a[:leaf] ? 1 : -1 end end Loading @@ -64,12 +65,20 @@ module JsDuck package end # When guides list not empty, add guides to tree def add_guides(guides) if guides.length > 0 pkg = package_node("guides") guides.each {|g| pkg[:children] << guide_node(g) } @root[:children] << pkg end end # Given full doc object for class creates class node def class_node(cls) return { :text => cls.short_name, :clsName => cls.full_name, :isClass => true, :url => "/api/"+cls.full_name, :iconCls => class_icon(cls), :leaf => true } Loading @@ -93,6 +102,16 @@ module JsDuck :children => [] } end # Given full guide object creates guide node def guide_node(guide) return { :text => guide[:title], :url => "/guide/"+guide[:name], :iconCls => "icon-guide", :leaf => true } end end end lib/jsduck/tree_icons.rb +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ module JsDuck icons.merge!(extract_icons(child)) end else icons[node[:clsName]] = node[:iconCls] icons[node[:url]] = node[:iconCls] end icons end Loading spec/tree_icons_spec.rb +7 −21 Original line number Diff line number Diff line Loading @@ -4,50 +4,36 @@ describe JsDuck::TreeIcons do before do @icons = JsDuck::TreeIcons.new.extract_icons({ :clsName => "apidocs", :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [ { :clsName => "pkg-SamplePackage", :text => "SamplePackage", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.Component.html", :text => "Component", :clsName => "SamplePackage.Component", :isClass => true, :url => "/api/SamplePackage.Component", :iconCls => "icon-cmp", :cls => "cls", :leaf => true }, { :href => "output/SamplePackage.Singleton.html", :text => "Singleton", :clsName => "SamplePackage.Singleton", :isClass => true, :url => "/api/SamplePackage.Singleton", :iconCls => "icon-static", :cls => "cls", :leaf => true }, { :clsName => "pkg-SamplePackage", :text => "sub", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.sub.Foo.html", :text => "Foo", :clsName => "SamplePackage.sub.Foo", :isClass => true, :url => "/api/SamplePackage.sub.Foo", :iconCls => "icon-cls", :cls => "cls", :leaf => true }, ] Loading @@ -63,12 +49,12 @@ describe JsDuck::TreeIcons do end it "extracts icons inside a package" do @icons["SamplePackage.Component"].should == "icon-cmp" @icons["SamplePackage.Singleton"].should == "icon-static" @icons["/api/SamplePackage.Component"].should == "icon-cmp" @icons["/api/SamplePackage.Singleton"].should == "icon-static" end it "extracts icons inside all subpackages too" do @icons["SamplePackage.sub.Foo"].should == "icon-cls" @icons["/api/SamplePackage.sub.Foo"].should == "icon-cls" end end Loading Loading
lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -215,7 +215,7 @@ module JsDuck # Given all classes, generates namespace tree and writes it # in JSON form into a file. def write_tree(filename, relations) tree = Tree.new.create(relations.classes) tree = Tree.new.create(relations.classes, @guides) icons = TreeIcons.new.extract_icons(tree) js = "Docs.classData = " + JSON.generate( tree ) + ";" js += "Docs.icons = " + JSON.generate( icons ) + ";" Loading
lib/jsduck/guides.rb +10 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,16 @@ module JsDuck EOHTML end # Iterates over each guide def each(&block) @guides.each &block end # Returns number of guides def length @guides.length end end end
lib/jsduck/tree.rb +24 −5 Original line number Diff line number Diff line Loading @@ -20,9 +20,10 @@ module JsDuck # Given list of class documentation objects returns a # tree-structure that can be turned into JSON that's needed by # documentation browser interface. def create(docs) def create(docs, guides=[]) docs.each {|cls| add_class(cls) } sort_tree(@root) add_guides(guides) @root end Loading @@ -34,10 +35,10 @@ module JsDuck # Comparson method that sorts package nodes before class nodes. def compare(a, b) if a[:isClass] == b[:isClass] if a[:leaf] == b[:leaf] a[:text].casecmp(b[:text]) else a[:isClass] ? 1 : -1 a[:leaf] ? 1 : -1 end end Loading @@ -64,12 +65,20 @@ module JsDuck package end # When guides list not empty, add guides to tree def add_guides(guides) if guides.length > 0 pkg = package_node("guides") guides.each {|g| pkg[:children] << guide_node(g) } @root[:children] << pkg end end # Given full doc object for class creates class node def class_node(cls) return { :text => cls.short_name, :clsName => cls.full_name, :isClass => true, :url => "/api/"+cls.full_name, :iconCls => class_icon(cls), :leaf => true } Loading @@ -93,6 +102,16 @@ module JsDuck :children => [] } end # Given full guide object creates guide node def guide_node(guide) return { :text => guide[:title], :url => "/guide/"+guide[:name], :iconCls => "icon-guide", :leaf => true } end end end
lib/jsduck/tree_icons.rb +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ module JsDuck icons.merge!(extract_icons(child)) end else icons[node[:clsName]] = node[:iconCls] icons[node[:url]] = node[:iconCls] end icons end Loading
spec/tree_icons_spec.rb +7 −21 Original line number Diff line number Diff line Loading @@ -4,50 +4,36 @@ describe JsDuck::TreeIcons do before do @icons = JsDuck::TreeIcons.new.extract_icons({ :clsName => "apidocs", :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [ { :clsName => "pkg-SamplePackage", :text => "SamplePackage", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.Component.html", :text => "Component", :clsName => "SamplePackage.Component", :isClass => true, :url => "/api/SamplePackage.Component", :iconCls => "icon-cmp", :cls => "cls", :leaf => true }, { :href => "output/SamplePackage.Singleton.html", :text => "Singleton", :clsName => "SamplePackage.Singleton", :isClass => true, :url => "/api/SamplePackage.Singleton", :iconCls => "icon-static", :cls => "cls", :leaf => true }, { :clsName => "pkg-SamplePackage", :text => "sub", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.sub.Foo.html", :text => "Foo", :clsName => "SamplePackage.sub.Foo", :isClass => true, :url => "/api/SamplePackage.sub.Foo", :iconCls => "icon-cls", :cls => "cls", :leaf => true }, ] Loading @@ -63,12 +49,12 @@ describe JsDuck::TreeIcons do end it "extracts icons inside a package" do @icons["SamplePackage.Component"].should == "icon-cmp" @icons["SamplePackage.Singleton"].should == "icon-static" @icons["/api/SamplePackage.Component"].should == "icon-cmp" @icons["/api/SamplePackage.Singleton"].should == "icon-static" end it "extracts icons inside all subpackages too" do @icons["SamplePackage.sub.Foo"].should == "icon-cls" @icons["/api/SamplePackage.sub.Foo"].should == "icon-cls" end end Loading