Loading lib/jsduck/ast.rb +5 −4 Original line number Diff line number Diff line Loading @@ -197,8 +197,9 @@ module JsDuck cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype } members = [] members += make_configs(cfg["config"]) members += make_configs(cfg["cachedConfig"]) members += make_configs(cfg["config"], {:accessor => true}) members += make_configs(cfg["cachedConfig"], {:accessor => true}) members += make_configs(cfg["eventedConfig"], {:accessor => true, :evented => true}) cls[:members] = members.length > 0 ? members : nil end end Loading Loading @@ -235,14 +236,14 @@ module JsDuck cfg_value && to_value(cfg_value) == true end def make_configs(ast) def make_configs(ast, defaults={}) return [] unless ast && ast["type"] == "ObjectExpression" configs = [] ast["properties"].each do |p| cfg = make_property(key_value(p["key"]), p["value"], :cfg) cfg[:accessor] = true cfg.merge!(defaults) # When config has a comment, update the related docset, # otherwise add it as new config to current class. docset = find_docset(p) Loading spec/aggregator_cfg_spec.rb +60 −43 Original line number Diff line number Diff line Loading @@ -9,8 +9,7 @@ describe JsDuck::Aggregator do agr.result end shared_examples_for "config" do let(:cfg) do def parse_config_code(propertyName) parse(<<-EOS)[0][:members][:cfg] /** * Some documentation. Loading @@ -25,6 +24,7 @@ describe JsDuck::Aggregator do EOS end shared_examples_for "config" do # Generic tests it "finds configs" do Loading @@ -35,63 +35,80 @@ describe JsDuck::Aggregator do cfg.length.should == 2 end # auto-detected config it "sets :inheritdoc flag on config" do describe "auto-detected config" do it "with :inheritdoc flag" do cfg[0][:inheritdoc].should == {} end it "sets :accessor flag on config" do it "with :accessor flag" do cfg[0][:accessor].should == true end it "sets :autodetected flag on config" do it "with :autodetected flag" do cfg[0][:autodetected].should == true end end # config with plain doc-comment it "detects the config with docs" do describe "documented config" do it "with docs" do cfg[1][:doc].should == "Docs for bar" end it "detects owner of the config" do it "with owner" do cfg[1][:owner].should == "MyClass" end it "detects the config as public" do it "as public" do cfg[1][:private].should_not == true end it "detects the config accessor" do it "with :accessor flag" do cfg[1][:accessor].should == true end end end describe "detecting Ext.define() with config:" do let(:propertyName) { "config" } let(:cfg) { parse_config_code("config") } it_should_behave_like "config" end describe "detecting Ext.define() with cachedConfig:" do let(:propertyName) { "cachedConfig" } let(:cfg) { parse_config_code("cachedConfig") } it_should_behave_like "config" end describe "detecting Ext.define() with eventedConfig:" do let(:cfg) { parse_config_code("eventedConfig") } it_should_behave_like "config" it "auto-detected config with :evented flag" do cfg[0][:evented].should == true end describe "detecting Ext.define() with both config and cachedConfig" do it "documented config with :evented flag" do cfg[1][:evented].should == true end end describe "detecting Ext.define() with all kind of configs" do let(:cfg) do parse(<<-EOS)[0][:members][:cfg] /** * Some documentation. */ Ext.define("MyClass", { config: { blah: 7 }, cachedConfig: { foo: 42, bar: "hello" }, config: { eventedConfig: { baz: /fafa/ } }); Loading @@ -99,7 +116,7 @@ describe JsDuck::Aggregator do end it "merges all configs together" do cfg.length.should == 3 cfg.length.should == 4 end end Loading Loading
lib/jsduck/ast.rb +5 −4 Original line number Diff line number Diff line Loading @@ -197,8 +197,9 @@ module JsDuck cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype } members = [] members += make_configs(cfg["config"]) members += make_configs(cfg["cachedConfig"]) members += make_configs(cfg["config"], {:accessor => true}) members += make_configs(cfg["cachedConfig"], {:accessor => true}) members += make_configs(cfg["eventedConfig"], {:accessor => true, :evented => true}) cls[:members] = members.length > 0 ? members : nil end end Loading Loading @@ -235,14 +236,14 @@ module JsDuck cfg_value && to_value(cfg_value) == true end def make_configs(ast) def make_configs(ast, defaults={}) return [] unless ast && ast["type"] == "ObjectExpression" configs = [] ast["properties"].each do |p| cfg = make_property(key_value(p["key"]), p["value"], :cfg) cfg[:accessor] = true cfg.merge!(defaults) # When config has a comment, update the related docset, # otherwise add it as new config to current class. docset = find_docset(p) Loading
spec/aggregator_cfg_spec.rb +60 −43 Original line number Diff line number Diff line Loading @@ -9,8 +9,7 @@ describe JsDuck::Aggregator do agr.result end shared_examples_for "config" do let(:cfg) do def parse_config_code(propertyName) parse(<<-EOS)[0][:members][:cfg] /** * Some documentation. Loading @@ -25,6 +24,7 @@ describe JsDuck::Aggregator do EOS end shared_examples_for "config" do # Generic tests it "finds configs" do Loading @@ -35,63 +35,80 @@ describe JsDuck::Aggregator do cfg.length.should == 2 end # auto-detected config it "sets :inheritdoc flag on config" do describe "auto-detected config" do it "with :inheritdoc flag" do cfg[0][:inheritdoc].should == {} end it "sets :accessor flag on config" do it "with :accessor flag" do cfg[0][:accessor].should == true end it "sets :autodetected flag on config" do it "with :autodetected flag" do cfg[0][:autodetected].should == true end end # config with plain doc-comment it "detects the config with docs" do describe "documented config" do it "with docs" do cfg[1][:doc].should == "Docs for bar" end it "detects owner of the config" do it "with owner" do cfg[1][:owner].should == "MyClass" end it "detects the config as public" do it "as public" do cfg[1][:private].should_not == true end it "detects the config accessor" do it "with :accessor flag" do cfg[1][:accessor].should == true end end end describe "detecting Ext.define() with config:" do let(:propertyName) { "config" } let(:cfg) { parse_config_code("config") } it_should_behave_like "config" end describe "detecting Ext.define() with cachedConfig:" do let(:propertyName) { "cachedConfig" } let(:cfg) { parse_config_code("cachedConfig") } it_should_behave_like "config" end describe "detecting Ext.define() with eventedConfig:" do let(:cfg) { parse_config_code("eventedConfig") } it_should_behave_like "config" it "auto-detected config with :evented flag" do cfg[0][:evented].should == true end describe "detecting Ext.define() with both config and cachedConfig" do it "documented config with :evented flag" do cfg[1][:evented].should == true end end describe "detecting Ext.define() with all kind of configs" do let(:cfg) do parse(<<-EOS)[0][:members][:cfg] /** * Some documentation. */ Ext.define("MyClass", { config: { blah: 7 }, cachedConfig: { foo: 42, bar: "hello" }, config: { eventedConfig: { baz: /fafa/ } }); Loading @@ -99,7 +116,7 @@ describe JsDuck::Aggregator do end it "merges all configs together" do cfg.length.should == 3 cfg.length.should == 4 end end Loading