Loading lib/jsduck/app.rb +2 −20 Original line number Diff line number Diff line Loading @@ -121,31 +121,13 @@ module JsDuck Relations.new(classes, @opts.external_classes) end # Given all classes, generates namespace tree and writes it # in JSON form into a file. # Writes classes tree, icons map, and guides tree to tree.js def write_tree tree = Tree.new.create(@relations.classes) icons = TreeIcons.new.extract_icons(tree) guides = Tree.new.create(@relations.classes) js = "Docs.classData = " + JSON.generate( tree ) + ";" js += "Docs.icons = " + JSON.generate( icons ) + ";" if @guides.length > 0 pkg = { :text => 'Guides', :children => [] } @guides.each {|g| pkg[:children] << { :text => g[:title], :url => "/guide/"+g[:name], :iconCls => "icon-guide", :leaf => true } } end js += "Docs.guideData = " + JSON.generate( pkg ) + ";" js += "Docs.guideData = " + JSON.generate( @guides.to_tree ) + ";" File.open(@opts.output_dir+"/output/tree.js", 'w') {|f| f.write(js) } end Loading lib/jsduck/guides.rb +17 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,23 @@ module JsDuck EOHTML end # Creates tree-structure containing all guides def to_tree return {} if @guides.length == 0 return { :text => 'Guides', :children => @guides.map do |g| { :text => g[:title], :url => "/guide/"+g[:name], :iconCls => "icon-guide", :leaf => true } end } end # Iterates over each guide def each(&block) @guides.each &block Loading lib/jsduck/tree.rb +1 −21 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ 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, guides=[]) def create(docs) docs.each {|cls| add_class(cls) } sort_tree(@root) add_guides(guides) @root end Loading Loading @@ -65,15 +64,6 @@ 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 { Loading Loading @@ -102,16 +92,6 @@ 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 spec/tree_spec.rb +0 −30 Original line number Diff line number Diff line Loading @@ -162,33 +162,3 @@ describe JsDuck::Tree do end end describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create( [JsDuck::Class.new({:tagname => :class, :name => "Foo"})], [{:name => "g1", :title => "Guide 1"}, {:name => "g2", :title => "Guide 2"}] ) end it "places guides last" do @tree[:children][1][:text].should == 'guides' @tree[:children][1][:children].length.should == 2 end end describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create( [JsDuck::Class.new({:tagname => :class, :name => "Foo"})] ) end it "doesn't add guides if there aren't any" do @tree[:children].length.should == 1 end end Loading
lib/jsduck/app.rb +2 −20 Original line number Diff line number Diff line Loading @@ -121,31 +121,13 @@ module JsDuck Relations.new(classes, @opts.external_classes) end # Given all classes, generates namespace tree and writes it # in JSON form into a file. # Writes classes tree, icons map, and guides tree to tree.js def write_tree tree = Tree.new.create(@relations.classes) icons = TreeIcons.new.extract_icons(tree) guides = Tree.new.create(@relations.classes) js = "Docs.classData = " + JSON.generate( tree ) + ";" js += "Docs.icons = " + JSON.generate( icons ) + ";" if @guides.length > 0 pkg = { :text => 'Guides', :children => [] } @guides.each {|g| pkg[:children] << { :text => g[:title], :url => "/guide/"+g[:name], :iconCls => "icon-guide", :leaf => true } } end js += "Docs.guideData = " + JSON.generate( pkg ) + ";" js += "Docs.guideData = " + JSON.generate( @guides.to_tree ) + ";" File.open(@opts.output_dir+"/output/tree.js", 'w') {|f| f.write(js) } end Loading
lib/jsduck/guides.rb +17 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,23 @@ module JsDuck EOHTML end # Creates tree-structure containing all guides def to_tree return {} if @guides.length == 0 return { :text => 'Guides', :children => @guides.map do |g| { :text => g[:title], :url => "/guide/"+g[:name], :iconCls => "icon-guide", :leaf => true } end } end # Iterates over each guide def each(&block) @guides.each &block Loading
lib/jsduck/tree.rb +1 −21 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ 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, guides=[]) def create(docs) docs.each {|cls| add_class(cls) } sort_tree(@root) add_guides(guides) @root end Loading Loading @@ -65,15 +64,6 @@ 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 { Loading Loading @@ -102,16 +92,6 @@ 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
spec/tree_spec.rb +0 −30 Original line number Diff line number Diff line Loading @@ -162,33 +162,3 @@ describe JsDuck::Tree do end end describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create( [JsDuck::Class.new({:tagname => :class, :name => "Foo"})], [{:name => "g1", :title => "Guide 1"}, {:name => "g2", :title => "Guide 2"}] ) end it "places guides last" do @tree[:children][1][:text].should == 'guides' @tree[:children][1][:children].length.should == 2 end end describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create( [JsDuck::Class.new({:tagname => :class, :name => "Foo"})] ) end it "doesn't add guides if there aren't any" do @tree[:children].length.should == 1 end end