Loading lib/jsduck/categories.rb +15 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,21 @@ module JsDuck # Parses categories in JSON file def parse(path) @categories = JsonDuck.read(path)["categories"] # Perform expansion on all class names containing * wildcard @categories.each do |cat| cat["groups"].each do |group| group["classes"] = group["classes"].map do |name| expand(name) # name =~ /\*/ ? expand(name) : name end.flatten end end end # Expands class name like 'Foo.*' into multiple class names. def expand(name) re = Regexp.new("^" + name.split(/\*/, -1).map {|part| Regexp.escape(part) }.join('.*') + "$") @relations.to_a.find_all {|cls| re =~ cls[:name] && !cls[:private] }.map {|cls| cls[:name] }.sort end # Prints warnings for missing classes in categories file Loading lib/jsduck/relations.rb +6 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,12 @@ module JsDuck @classes.each(&block) end # Returns list of all classes. This method allows us to treat # Relations as array and therefore easily mock it def to_a @classes end def reg_subclasses(cls) if !cls.parent # do nothing Loading spec/categories_spec.rb +28 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,32 @@ describe JsDuck::Categories do end end describe "#expand" do before do classes = [ {:name => "Foo.Ahem"}, {:name => "Foo.Ahum"}, {:name => "Foo.Blah"}, {:name => "Bar.Ahhh"}, ] @categories = JsDuck::Categories.new({}, classes) end it "expands class without * in name into the same class" do @categories.expand("Foo.Ahem").should == ["Foo.Ahem"] end it "expands Foo.* into all classes in Foo namespace" do @categories.expand("Foo.*").should == ["Foo.Ahem", "Foo.Ahum", "Foo.Blah"] end it "expands Foo.A* into all classes in Foo namespace beginning with A" do @categories.expand("Foo.A*").should == ["Foo.Ahem", "Foo.Ahum"] end it "expands to empty array if no classes match the pattern" do @categories.expand("Bazz*").should == [] end end end Loading
lib/jsduck/categories.rb +15 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,21 @@ module JsDuck # Parses categories in JSON file def parse(path) @categories = JsonDuck.read(path)["categories"] # Perform expansion on all class names containing * wildcard @categories.each do |cat| cat["groups"].each do |group| group["classes"] = group["classes"].map do |name| expand(name) # name =~ /\*/ ? expand(name) : name end.flatten end end end # Expands class name like 'Foo.*' into multiple class names. def expand(name) re = Regexp.new("^" + name.split(/\*/, -1).map {|part| Regexp.escape(part) }.join('.*') + "$") @relations.to_a.find_all {|cls| re =~ cls[:name] && !cls[:private] }.map {|cls| cls[:name] }.sort end # Prints warnings for missing classes in categories file Loading
lib/jsduck/relations.rb +6 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,12 @@ module JsDuck @classes.each(&block) end # Returns list of all classes. This method allows us to treat # Relations as array and therefore easily mock it def to_a @classes end def reg_subclasses(cls) if !cls.parent # do nothing Loading
spec/categories_spec.rb +28 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,32 @@ describe JsDuck::Categories do end end describe "#expand" do before do classes = [ {:name => "Foo.Ahem"}, {:name => "Foo.Ahum"}, {:name => "Foo.Blah"}, {:name => "Bar.Ahhh"}, ] @categories = JsDuck::Categories.new({}, classes) end it "expands class without * in name into the same class" do @categories.expand("Foo.Ahem").should == ["Foo.Ahem"] end it "expands Foo.* into all classes in Foo namespace" do @categories.expand("Foo.*").should == ["Foo.Ahem", "Foo.Ahum", "Foo.Blah"] end it "expands Foo.A* into all classes in Foo namespace beginning with A" do @categories.expand("Foo.A*").should == ["Foo.Ahem", "Foo.Ahum"] end it "expands to empty array if no classes match the pattern" do @categories.expand("Bazz*").should == [] end end end