Loading lib/jsduck/parser.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/js/parser' require 'jsduck/js/ast' require 'jsduck/css/parser' require 'jsduck/css/sass_parser' require 'jsduck/doc/parser' require 'jsduck/doc/processor' require 'jsduck/doc/map' Loading Loading @@ -39,7 +39,7 @@ module JsDuck # Parses the file depending on filename as JS or CSS def parse_js_or_css(contents, filename, options) if filename =~ /\.s?css$/ docs = Css::Parser.new(contents, options).parse docs = Css::SassParser.new(contents, options).parse else docs = Js::Parser.new(contents, options).parse docs = Js::Ast.new(docs).detect_all! Loading spec/aggregator_css_spec.rb +5 −173 Original line number Diff line number Diff line Loading @@ -10,16 +10,11 @@ describe JsDuck::Aggregator do parse(string)["global"][:members][0] end it "yields no results when parsing CSS without doc-comments" do @docs = parse("div > p a:link {text-align: top;}") @docs.length.should == 0 end describe "CSS with @var in doc-comment" do before do @doc = parse_member(<<-EOCSS) /** * @var {length} $button-height Default height for buttons. * @var {number} $button-height Default height for buttons. */ EOCSS end Loading @@ -31,7 +26,7 @@ describe JsDuck::Aggregator do @doc[:name].should == "$button-height" end it "detects variable type" do @doc[:type].should == "length" @doc[:type].should == "number" end it "detects variable description" do @doc[:doc].should == "Default height for buttons." Loading @@ -42,7 +37,7 @@ describe JsDuck::Aggregator do before do @doc = parse(<<-EOCSS)["Ext.Button"][:members][0] /** * @var {length} $button-height Default height for buttons. * @var {number} $button-height Default height for buttons. * @member Ext.Button */ EOCSS Loading @@ -57,7 +52,7 @@ describe JsDuck::Aggregator do before do @doc = parse_member(<<-EOCSS) /** * @var {length} [$button-height=25px] * @var {number} [$button-height=25px] */ EOCSS end Loading @@ -84,145 +79,13 @@ describe JsDuck::Aggregator do @doc[:name].should == "$button-height" end it "detects variable type" do @doc[:type].should == "length" @doc[:type].should == "number" end it "detects variable default value" do @doc[:default].should == "25px" end end describe "$var-name: value followed by !default" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: 25px !default; EOCSS end it "detects variable" do @doc[:tagname].should == :css_var end it "detects variable type" do @doc[:type].should == "length" end it "detects variable default value" do @doc[:default].should == "25px" end end describe "$var-name: followed by multiple values" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: 25px 0 1em 0; EOCSS end it "detects variable type by first value" do @doc[:type].should == "length" end it "detects variable default value" do @doc[:default].should == "25px 0 1em 0" end end describe "$var-name: followed by comma-separated values" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: "Arial", "Verdana", sans-serif; EOCSS end it "detects variable type by first value" do @doc[:type].should == "string" end it "detects variable default value" do @doc[:default].should == '"Arial" , "Verdana" , sans-serif' end end describe "$var-name: followed by unknown function" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: myfunc(1, 2); EOCSS end it "doesn't detect variable type" do @doc[:type].should == "Object" end it "detects variable default value" do @doc[:default].should == 'myfunc ( 1 , 2 )' end end def detect_type(value) return parse_member(<<-EOCSS)[:type] /** */ $foo: #{value}; EOCSS end describe "auto-detection of CSS variable types" do it "detects integer" do detect_type("15").should == "number" end it "detects float" do detect_type("15.6").should == "number" end it "detects float begging with dot" do detect_type(".6").should == "number" end it "detects length" do detect_type("15em").should == "length" end it "detects percentage" do detect_type("99.9%").should == "percentage" end it "detects boolean true" do detect_type("true").should == "boolean" end it "detects boolean false" do detect_type("false").should == "boolean" end it "detects string" do detect_type('"Hello"').should == "string" end it "detects #000 color" do detect_type("#F0a").should == "color" end it "detects #000000 color" do detect_type("#FF00aa").should == "color" end it "detects rgb(...) color" do detect_type("rgb(255, 0, 0)").should == "color" end it "detects rgba(...) color" do detect_type("rgba(100%, 0%, 0%, 0.5)").should == "color" end it "detects hsl(...) color" do detect_type("hsl(255, 0, 0)").should == "color" end it "detects hsla(...) color" do detect_type("hsla(100%, 0%, 0%, 0.5)").should == "color" end # basic CSS color keywords "black silver gray white maroon red purple fuchsia green lime olive yellow navy blue teal aqua".split(/ /).each do |c| it "detects #{c} color keyword" do detect_type(c).should == "color" end end it "detects wide-supported orange color keyword" do detect_type("orange").should == "color" end it "detects transparent color keyword" do detect_type("transparent").should == "color" end end describe "CSS doc-comment followed by @mixin" do before do @doc = parse_member(<<-EOCSS) Loading Loading @@ -260,35 +123,4 @@ describe JsDuck::Aggregator do end end describe "CSS doc-comment followed by CSS selector" do before do @doc = parse_member(<<-EOCSS) /** * Some comment. */ .highlight { font-weight: bold; } EOCSS end it "gets detected as property" do @doc[:tagname].should == :property end end describe "CSS doc-comment followed by nothing" do before do @doc = parse_member(<<-EOCSS) /** * Some comment. */ EOCSS end it "gets detected as property" do @doc[:tagname].should == :property end end end Loading
lib/jsduck/parser.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/js/parser' require 'jsduck/js/ast' require 'jsduck/css/parser' require 'jsduck/css/sass_parser' require 'jsduck/doc/parser' require 'jsduck/doc/processor' require 'jsduck/doc/map' Loading Loading @@ -39,7 +39,7 @@ module JsDuck # Parses the file depending on filename as JS or CSS def parse_js_or_css(contents, filename, options) if filename =~ /\.s?css$/ docs = Css::Parser.new(contents, options).parse docs = Css::SassParser.new(contents, options).parse else docs = Js::Parser.new(contents, options).parse docs = Js::Ast.new(docs).detect_all! Loading
spec/aggregator_css_spec.rb +5 −173 Original line number Diff line number Diff line Loading @@ -10,16 +10,11 @@ describe JsDuck::Aggregator do parse(string)["global"][:members][0] end it "yields no results when parsing CSS without doc-comments" do @docs = parse("div > p a:link {text-align: top;}") @docs.length.should == 0 end describe "CSS with @var in doc-comment" do before do @doc = parse_member(<<-EOCSS) /** * @var {length} $button-height Default height for buttons. * @var {number} $button-height Default height for buttons. */ EOCSS end Loading @@ -31,7 +26,7 @@ describe JsDuck::Aggregator do @doc[:name].should == "$button-height" end it "detects variable type" do @doc[:type].should == "length" @doc[:type].should == "number" end it "detects variable description" do @doc[:doc].should == "Default height for buttons." Loading @@ -42,7 +37,7 @@ describe JsDuck::Aggregator do before do @doc = parse(<<-EOCSS)["Ext.Button"][:members][0] /** * @var {length} $button-height Default height for buttons. * @var {number} $button-height Default height for buttons. * @member Ext.Button */ EOCSS Loading @@ -57,7 +52,7 @@ describe JsDuck::Aggregator do before do @doc = parse_member(<<-EOCSS) /** * @var {length} [$button-height=25px] * @var {number} [$button-height=25px] */ EOCSS end Loading @@ -84,145 +79,13 @@ describe JsDuck::Aggregator do @doc[:name].should == "$button-height" end it "detects variable type" do @doc[:type].should == "length" @doc[:type].should == "number" end it "detects variable default value" do @doc[:default].should == "25px" end end describe "$var-name: value followed by !default" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: 25px !default; EOCSS end it "detects variable" do @doc[:tagname].should == :css_var end it "detects variable type" do @doc[:type].should == "length" end it "detects variable default value" do @doc[:default].should == "25px" end end describe "$var-name: followed by multiple values" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: 25px 0 1em 0; EOCSS end it "detects variable type by first value" do @doc[:type].should == "length" end it "detects variable default value" do @doc[:default].should == "25px 0 1em 0" end end describe "$var-name: followed by comma-separated values" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: "Arial", "Verdana", sans-serif; EOCSS end it "detects variable type by first value" do @doc[:type].should == "string" end it "detects variable default value" do @doc[:default].should == '"Arial" , "Verdana" , sans-serif' end end describe "$var-name: followed by unknown function" do before do @doc = parse_member(<<-EOCSS) /** */ $foo: myfunc(1, 2); EOCSS end it "doesn't detect variable type" do @doc[:type].should == "Object" end it "detects variable default value" do @doc[:default].should == 'myfunc ( 1 , 2 )' end end def detect_type(value) return parse_member(<<-EOCSS)[:type] /** */ $foo: #{value}; EOCSS end describe "auto-detection of CSS variable types" do it "detects integer" do detect_type("15").should == "number" end it "detects float" do detect_type("15.6").should == "number" end it "detects float begging with dot" do detect_type(".6").should == "number" end it "detects length" do detect_type("15em").should == "length" end it "detects percentage" do detect_type("99.9%").should == "percentage" end it "detects boolean true" do detect_type("true").should == "boolean" end it "detects boolean false" do detect_type("false").should == "boolean" end it "detects string" do detect_type('"Hello"').should == "string" end it "detects #000 color" do detect_type("#F0a").should == "color" end it "detects #000000 color" do detect_type("#FF00aa").should == "color" end it "detects rgb(...) color" do detect_type("rgb(255, 0, 0)").should == "color" end it "detects rgba(...) color" do detect_type("rgba(100%, 0%, 0%, 0.5)").should == "color" end it "detects hsl(...) color" do detect_type("hsl(255, 0, 0)").should == "color" end it "detects hsla(...) color" do detect_type("hsla(100%, 0%, 0%, 0.5)").should == "color" end # basic CSS color keywords "black silver gray white maroon red purple fuchsia green lime olive yellow navy blue teal aqua".split(/ /).each do |c| it "detects #{c} color keyword" do detect_type(c).should == "color" end end it "detects wide-supported orange color keyword" do detect_type("orange").should == "color" end it "detects transparent color keyword" do detect_type("transparent").should == "color" end end describe "CSS doc-comment followed by @mixin" do before do @doc = parse_member(<<-EOCSS) Loading Loading @@ -260,35 +123,4 @@ describe JsDuck::Aggregator do end end describe "CSS doc-comment followed by CSS selector" do before do @doc = parse_member(<<-EOCSS) /** * Some comment. */ .highlight { font-weight: bold; } EOCSS end it "gets detected as property" do @doc[:tagname].should == :property end end describe "CSS doc-comment followed by nothing" do before do @doc = parse_member(<<-EOCSS) /** * Some comment. */ EOCSS end it "gets detected as property" do @doc[:tagname].should == :property end end end