Loading lib/jsduck/aggregator.rb +1 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,7 @@ module JsDuck :method => [], :event => [], :var => [], :mixin => [], }) end add_member(orph) Loading lib/jsduck/css_parser.rb +40 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ module JsDuck @docs << { :comment => @doc_parser.parse(comment[:value]), :linenr => comment[:linenr], :code => {:type => :nop} :code => code_block } else @lex.next Loading @@ -28,6 +28,45 @@ module JsDuck @docs end # <code-block> := <mixin> | <nop> def code_block if look("@", "mixin") mixin else {:type => :nop} end end # <mixin> := "@mixin" <css-ident> def mixin match("@", "mixin") return { :type => :mixin, :name => look(:ident) ? css_ident : nil, } end # <css-ident> := <ident> [ "-" <ident> ]* def css_ident chain = [match(:ident)] while look("-", :ident) do chain << match("-", :ident) end return chain.join("-") end # Matches all arguments, returns the value of last match # When the whole sequence doesn't match, throws exception def match(*args) if look(*args) last = nil args.length.times { last = @lex.next } last else throw "Expected: " + args.join(", ") end end def look(*args) @lex.look(*args) end Loading lib/jsduck/merger.rb +17 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ module JsDuck create_property(docs, code) when :var create_var(docs, code) when :mixin create_mixin(docs, code) end end Loading @@ -43,6 +45,8 @@ module JsDuck :class elsif code[:type] == :function && class_name?(code[:name]) :class elsif code[:type] == :mixin :mixin elsif doc_map[:cfg] :cfg elsif code[:type] == :function Loading Loading @@ -186,13 +190,25 @@ module JsDuck } end def create_mixin(docs, code) doc_map = build_doc_map(docs) return { :tagname => :mixin, :name => detect_name(:mixin, doc_map, code), :member => detect_member(doc_map), :doc => detect_doc(docs), :private => !!doc_map[:private], :static => !!doc_map[:static], } end def detect_name(tagname, doc_map, code, name_type = :last_name) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:name] main_tag[:name] elsif doc_map[:constructor] "constructor" elsif code[:type] == :function elsif code[:type] == :function || code[:type] == :mixin code[:name] elsif code[:type] == :assignment name_type == :full_name ? code[:left].join(".") : code[:left].last Loading spec/aggregator_css_spec.rb +22 −0 Original line number Diff line number Diff line Loading @@ -37,5 +37,27 @@ describe JsDuck::Aggregator do end end describe "CSS doc-comment followed by @mixin" do before do @doc = parse(<<-EOCSS)[0] /** * Creates an awesome button. */ @mixin my-button { } EOCSS end it "detects mixin" do @doc[:tagname].should == :mixin end it "detects mixin name" do @doc[:name].should == "my-button" end it "detects mixin description" do @doc[:doc].should == "Creates an awesome button." end end end Loading
lib/jsduck/aggregator.rb +1 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,7 @@ module JsDuck :method => [], :event => [], :var => [], :mixin => [], }) end add_member(orph) Loading
lib/jsduck/css_parser.rb +40 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ module JsDuck @docs << { :comment => @doc_parser.parse(comment[:value]), :linenr => comment[:linenr], :code => {:type => :nop} :code => code_block } else @lex.next Loading @@ -28,6 +28,45 @@ module JsDuck @docs end # <code-block> := <mixin> | <nop> def code_block if look("@", "mixin") mixin else {:type => :nop} end end # <mixin> := "@mixin" <css-ident> def mixin match("@", "mixin") return { :type => :mixin, :name => look(:ident) ? css_ident : nil, } end # <css-ident> := <ident> [ "-" <ident> ]* def css_ident chain = [match(:ident)] while look("-", :ident) do chain << match("-", :ident) end return chain.join("-") end # Matches all arguments, returns the value of last match # When the whole sequence doesn't match, throws exception def match(*args) if look(*args) last = nil args.length.times { last = @lex.next } last else throw "Expected: " + args.join(", ") end end def look(*args) @lex.look(*args) end Loading
lib/jsduck/merger.rb +17 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ module JsDuck create_property(docs, code) when :var create_var(docs, code) when :mixin create_mixin(docs, code) end end Loading @@ -43,6 +45,8 @@ module JsDuck :class elsif code[:type] == :function && class_name?(code[:name]) :class elsif code[:type] == :mixin :mixin elsif doc_map[:cfg] :cfg elsif code[:type] == :function Loading Loading @@ -186,13 +190,25 @@ module JsDuck } end def create_mixin(docs, code) doc_map = build_doc_map(docs) return { :tagname => :mixin, :name => detect_name(:mixin, doc_map, code), :member => detect_member(doc_map), :doc => detect_doc(docs), :private => !!doc_map[:private], :static => !!doc_map[:static], } end def detect_name(tagname, doc_map, code, name_type = :last_name) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:name] main_tag[:name] elsif doc_map[:constructor] "constructor" elsif code[:type] == :function elsif code[:type] == :function || code[:type] == :mixin code[:name] elsif code[:type] == :assignment name_type == :full_name ? code[:left].join(".") : code[:left].last Loading
spec/aggregator_css_spec.rb +22 −0 Original line number Diff line number Diff line Loading @@ -37,5 +37,27 @@ describe JsDuck::Aggregator do end end describe "CSS doc-comment followed by @mixin" do before do @doc = parse(<<-EOCSS)[0] /** * Creates an awesome button. */ @mixin my-button { } EOCSS end it "detects mixin" do @doc[:tagname].should == :mixin end it "detects mixin name" do @doc[:name].should == "my-button" end it "detects mixin description" do @doc[:doc].should == "Creates an awesome button." end end end