Loading lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ module JsDuck result = aggregate(parsed_files) @relations = filter_classes(result) InheritDoc.new(@relations).resolve_all Importer.import(@opts.imports, @relations) Importer.import(@opts.imports, @relations, @opts.new_since) Lint.new(@relations).run # Initialize guides, videos, examples, ... Loading lib/jsduck/importer.rb +25 −6 Original line number Diff line number Diff line Loading @@ -10,9 +10,9 @@ module JsDuck module_function # Loads in exported docs and generates @since and @new tags based on that data. def import(imports, relations) def import(imports, relations, new_since=nil) if imports.length > 0 generate_since_tags(read_all(imports), relations) generate_since_tags(read_all(imports), relations, new_since) end end Loading Loading @@ -60,22 +60,41 @@ module JsDuck # Using the imported versions data, adds @since tags to all # classes/members. def generate_since_tags(versions, relations) last_version = versions.last[:version] def generate_since_tags(versions, relations, new_since=nil) new_versions = build_new_versions_map(versions, new_since) relations.each do |cls| v = cls[:meta][:since] || class_since(versions, cls) cls[:meta][:since] = v cls[:meta][:new] = true if v == last_version cls[:meta][:new] = true if new_versions[v] cls.all_local_members.each do |m| v = m[:meta][:since] || member_since(versions, cls, m) m[:meta][:since] = v m[:meta][:new] = true if v == last_version m[:meta][:new] = true if new_versions[v] end end end # Generates a lookup table of versions that we are going to label # with @new tags. By default we use the latest version, otherwise # use all versions since the latest. def build_new_versions_map(versions, new_since=nil) new_versions = {} if new_since versions.map {|v| v[:version] }.each do |v| if v == new_since || !new_versions.empty? new_versions[v] = true end end else new_versions[versions.last[:version]] = true end new_versions end def member_since(versions, cls, m) versions.each do |ver| c = ver[:classes][cls[:name]] Loading lib/jsduck/options.rb +8 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ module JsDuck attr_accessor :touch_examples_ui attr_accessor :ext_namespaces attr_accessor :imports attr_accessor :new_since def initialize @input_files = [] Loading Loading @@ -116,6 +117,7 @@ module JsDuck @touch_examples_ui = false @ext_namespaces = ["Ext"] @imports = [] @new_since = nil # enable all warnings except :link_auto Logger.instance.set_warning(:all, true) Loading Loading @@ -383,6 +385,12 @@ module JsDuck end end opts.on('--new-since=VERSION', "Defines since which version to label items with @new tag.", "Defaults to the last version listed by --import.", " ") do |v| @new_since = v end opts.on('--config=PATH', "Loads config options from JSON file.", " ") do |path| path = canonical(path) Loading spec/importer_spec.rb +43 −0 Original line number Diff line number Diff line Loading @@ -140,3 +140,46 @@ describe "JsDuck::Importer#generate_since_tags" do end end describe "JsDuck::Importer#generate_since_tags with explicit new_since" do before do @versions = [ { :version => "1.0", :classes => { "VeryOldClass" => {}, }, }, { :version => "2.0", :classes => { "OldClass" => {}, }, }, { :version => "3.0", :classes => JsDuck::Importer.current_version } ] @relations = [ {:name => "VeryOldClass", :meta => {}, :alternateClassNames => []}, {:name => "OldClass", :meta => {}, :alternateClassNames => []}, {:name => "NewClass", :meta => {}, :alternateClassNames => []}, ].map {|cfg| JsDuck::Class.new(cfg) } JsDuck::Importer.generate_since_tags(@versions, @relations, "2.0") end # @since it "gives no @new to VeryOldClass" do @relations[0][:meta][:new].should_not == true end it "gives @new to OldClass" do @relations[1][:meta][:new].should == true end it "gives no @new to NewClass" do @relations[2][:meta][:new].should == true end end Loading
lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ module JsDuck result = aggregate(parsed_files) @relations = filter_classes(result) InheritDoc.new(@relations).resolve_all Importer.import(@opts.imports, @relations) Importer.import(@opts.imports, @relations, @opts.new_since) Lint.new(@relations).run # Initialize guides, videos, examples, ... Loading
lib/jsduck/importer.rb +25 −6 Original line number Diff line number Diff line Loading @@ -10,9 +10,9 @@ module JsDuck module_function # Loads in exported docs and generates @since and @new tags based on that data. def import(imports, relations) def import(imports, relations, new_since=nil) if imports.length > 0 generate_since_tags(read_all(imports), relations) generate_since_tags(read_all(imports), relations, new_since) end end Loading Loading @@ -60,22 +60,41 @@ module JsDuck # Using the imported versions data, adds @since tags to all # classes/members. def generate_since_tags(versions, relations) last_version = versions.last[:version] def generate_since_tags(versions, relations, new_since=nil) new_versions = build_new_versions_map(versions, new_since) relations.each do |cls| v = cls[:meta][:since] || class_since(versions, cls) cls[:meta][:since] = v cls[:meta][:new] = true if v == last_version cls[:meta][:new] = true if new_versions[v] cls.all_local_members.each do |m| v = m[:meta][:since] || member_since(versions, cls, m) m[:meta][:since] = v m[:meta][:new] = true if v == last_version m[:meta][:new] = true if new_versions[v] end end end # Generates a lookup table of versions that we are going to label # with @new tags. By default we use the latest version, otherwise # use all versions since the latest. def build_new_versions_map(versions, new_since=nil) new_versions = {} if new_since versions.map {|v| v[:version] }.each do |v| if v == new_since || !new_versions.empty? new_versions[v] = true end end else new_versions[versions.last[:version]] = true end new_versions end def member_since(versions, cls, m) versions.each do |ver| c = ver[:classes][cls[:name]] Loading
lib/jsduck/options.rb +8 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ module JsDuck attr_accessor :touch_examples_ui attr_accessor :ext_namespaces attr_accessor :imports attr_accessor :new_since def initialize @input_files = [] Loading Loading @@ -116,6 +117,7 @@ module JsDuck @touch_examples_ui = false @ext_namespaces = ["Ext"] @imports = [] @new_since = nil # enable all warnings except :link_auto Logger.instance.set_warning(:all, true) Loading Loading @@ -383,6 +385,12 @@ module JsDuck end end opts.on('--new-since=VERSION', "Defines since which version to label items with @new tag.", "Defaults to the last version listed by --import.", " ") do |v| @new_since = v end opts.on('--config=PATH', "Loads config options from JSON file.", " ") do |path| path = canonical(path) Loading
spec/importer_spec.rb +43 −0 Original line number Diff line number Diff line Loading @@ -140,3 +140,46 @@ describe "JsDuck::Importer#generate_since_tags" do end end describe "JsDuck::Importer#generate_since_tags with explicit new_since" do before do @versions = [ { :version => "1.0", :classes => { "VeryOldClass" => {}, }, }, { :version => "2.0", :classes => { "OldClass" => {}, }, }, { :version => "3.0", :classes => JsDuck::Importer.current_version } ] @relations = [ {:name => "VeryOldClass", :meta => {}, :alternateClassNames => []}, {:name => "OldClass", :meta => {}, :alternateClassNames => []}, {:name => "NewClass", :meta => {}, :alternateClassNames => []}, ].map {|cfg| JsDuck::Class.new(cfg) } JsDuck::Importer.generate_since_tags(@versions, @relations, "2.0") end # @since it "gives no @new to VeryOldClass" do @relations[0][:meta][:new].should_not == true end it "gives @new to OldClass" do @relations[1][:meta][:new].should == true end it "gives no @new to NewClass" do @relations[2][:meta][:new].should == true end end