Commit f3f07a79 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add --ext-namespace option.

Allows detecting Ext.define and Ext.extend when Ext is wrapped
inside another namespace and the code uses Foo.define instead.
parent 045659ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ module JsDuck
    def parallel_parse(filenames)
      @parallel.map(filenames) do |fname|
        Logger.instance.log("Parsing #{fname} ...")
        SourceFile.new(IO.read(fname), fname)
        SourceFile.new(IO.read(fname), fname, @opts)
      end
    end

+16 −6
Original line number Diff line number Diff line
@@ -6,10 +6,11 @@ require 'jsduck/js_literal_builder'
module JsDuck

  class JsParser < JsLiteralParser
    def initialize(input)
    def initialize(input, namespaces = nil)
      super(input)
      @doc_parser = DocParser.new
      @docs = []
      @ext_namespaces = namespaces || ["Ext"]
    end

    # Parses the whole JavaScript block and returns array where for
@@ -76,9 +77,9 @@ module JsDuck
        function
      elsif look("var")
        var_declaration
      elsif look("Ext", ".", "define", "(", :string)
      elsif ext_look(:ns, ".", "define", "(", :string)
        ext_define
      elsif look("Ext", ".", "ClassManager", ".", "create", "(", :string)
      elsif ext_look(:ns, ".", "ClassManager", ".", "create", "(", :string)
        ext_define
      elsif look(:ident, ":") || look(:string, ":")
        property_literal
@@ -159,7 +160,7 @@ module JsDuck
    def expression
      if look("function")
        function
      elsif look("Ext", ".", "extend")
      elsif ext_look(:ns, ".", "extend")
        ext_extend
      else
        my_literal
@@ -194,7 +195,7 @@ module JsDuck

    # <ext-extend> := "Ext" "." "extend" "(" <ident-chain> "," ...
    def ext_extend
      match("Ext", ".", "extend", "(")
      match(:ident, ".", "extend", "(")
      return {
        :type => :ext_extend,
        :extend => ident_chain,
@@ -203,7 +204,7 @@ module JsDuck

    # <ext-define> := "Ext" "." ["define" | "ClassManager" "." "create" ] "(" <string> "," <ext-define-cfg>
    def ext_define
      match("Ext", ".");
      match(:ident, ".");
      look("define") ? match("define") : match("ClassManager", ".", "create");
      name = match("(", :string)[:value]

@@ -338,6 +339,15 @@ module JsDuck
      }
    end

    # Like look() but tries to match as the first argument all the
    # names listed in @ext_namespaces
    def ext_look(placeholder, *args)
      @ext_namespaces.each do |ns|
        return true if look(ns, *args)
      end
      return false
    end

  end

end
+7 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ module JsDuck
    attr_accessor :template_links
    attr_accessor :extjs_path
    attr_accessor :local_storage_db
    attr_accessor :ext_namespaces

    def initialize
      @input_files = []
@@ -94,6 +95,7 @@ module JsDuck
      @template_links = false
      @extjs_path = "extjs/ext-all.js"
      @local_storage_db = "docs"
      @ext_namespaces = ["Ext"]
    end

    def parse!(argv)
@@ -259,6 +261,11 @@ module JsDuck
          @local_storage_db = name
        end

        opts.on('--ext-namespaces=Ext,Foo', Array,
          "Namespace(s) of ExtJS. Defaults to 'Ext'.", " ") do |ns|
          @ext_namespaces = ns
        end

        opts.on('-h', '--help', "Prints this help message", " ") do
          puts opts
          exit
+3 −2
Original line number Diff line number Diff line
@@ -15,9 +15,10 @@ module JsDuck
    attr_reader :docs
    attr_reader :html_filename

    def initialize(contents, filename="")
    def initialize(contents, filename="", options=nil)
      @contents = contents
      @filename = filename
      @options = options
      @html_filename = ""
      @links = {}

@@ -80,7 +81,7 @@ module JsDuck
      if @filename =~ /\.s?css$/
        CssParser.new(@contents).parse
      else
        JsParser.new(@contents).parse
        JsParser.new(@contents, @options && @options.ext_namespaces).parse
      end
    end