Commit 71af47d7 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for CSS mixin parameters.

DocParser constructor now takes mode parameter that sets either
JavaScript identifier or CSS identifier pattern.
parent 5e476b62
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ module JsDuck
  class CssParser
    def initialize(input)
      @lex = Lexer.new(input)
      @doc_parser = DocParser.new
      @doc_parser = DocParser.new(:css)
      @docs = []
    end

+9 −4
Original line number Diff line number Diff line
@@ -21,6 +21,11 @@ module JsDuck
  # @see and {@link} are parsed separately in JsDuck::DocFormatter.
  #
  class DocParser
    # Pass in :css to be able to parse CSS doc-comments
    def initialize(mode = :js)
      @ident_pattern = (mode == :css) ? /\$[a-zA-Z0-9_-]*/ : /\w+/
    end

    def parse(input)
      @tags = []
      @input = StringScanner.new(purify(input))
@@ -186,7 +191,7 @@ module JsDuck
      match(/@var/)
      add_tag(:css_var)
      maybe_type
      maybe_name(/\$[a-zA-Z0-9_-]*/)
      maybe_name
      skip_white
    end

@@ -248,10 +253,10 @@ module JsDuck
    end

    # matches identifier name if possible and sets it on @current_tag
    def maybe_name(pattern = /\w+/)
    def maybe_name
      skip_horiz_white
      if look(pattern)
        @current_tag[:name] = @input.scan(pattern)
      if look(@ident_pattern)
        @current_tag[:name] = @input.scan(@ident_pattern)
      end
    end

+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ module JsDuck
        :name => detect_name(:css_mixin, doc_map, code),
        :member => detect_member(doc_map),
        :doc => detect_doc(docs),
        :params => detect_params(docs, code),
        :private => !!doc_map[:private],
        :static => !!doc_map[:static],
      }
+15 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ describe JsDuck::Aggregator do
      @doc = parse(<<-EOCSS)[0]
        /**
         * Creates an awesome button.
         *
         * @param {string} $ui-label The name of the UI being created.
         * @param {color} $color Base color for the UI.
         */
        @mixin my-button {
        }
@@ -57,6 +60,18 @@ describe JsDuck::Aggregator do
    it "detects mixin description" do
      @doc[:doc].should == "Creates an awesome button."
    end
    it "detects mixin parameters" do
      @doc[:params].length.should == 2
    end
    it "detects mixin param name" do
      @doc[:params][0][:name].should == "$ui-label"
    end
    it "detects mixin param type" do
      @doc[:params][0][:type].should == "string"
    end
    it "detects mixin param description" do
      @doc[:params][0][:doc].should == "The name of the UI being created."
    end
  end

end