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

Add --meta-tags command line option.

Render meta-data section at the bottom of class documentation.

Treat @author and @docauthor as meta-tags.
For these tags strip e-mail addresses from content.
For now this ability is not supported for user-defined tags.
Probably some formatting will be useful for custom tags too - I'd
just like to gather some real-world usage info on this, so marking
this option currently as experimantal.
parent f3f07a79
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ module JsDuck
    # Writes JSON export or JsonP file for each class
    def write_classes
      exporter = Exporter.new(@relations)
      renderer = Renderer.new
      renderer = Renderer.new(@opts)
      @parallel.each(@relations.classes) do |cls|
        filename = @opts.output_dir+"/output/" + cls[:name] + (@opts.export ? ".json" : ".js")
        Logger.instance.log("Writing to #{filename} ...")
+2 −2
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ require 'jsduck/doc_parser'
module JsDuck

  class CssParser
    def initialize(input)
    def initialize(input, options = {})
      @lex = Lexer.new(input)
      @doc_parser = DocParser.new(:css)
      @doc_parser = DocParser.new(:css, options[:meta_tags])
      @docs = []
    end

+16 −24
Original line number Diff line number Diff line
@@ -24,9 +24,14 @@ module JsDuck
  #
  class DocParser
    # Pass in :css to be able to parse CSS doc-comments
    def initialize(mode = :js)
    def initialize(mode = :js, meta_tags = nil)
      @ident_pattern = (mode == :css) ? /\$?[\w-]+/ : /[$\w]\w*/
      @ident_chain_pattern = (mode == :css) ? /\$?[\w-]+(\.[\w-]+)*/ : /[$\w]\w*(\.\w+)*/

      @meta_tags_map = {}
      (meta_tags || []).each do |tag|
        @meta_tags_map[tag[:name]] = true
      end
    end

    def parse(input)
@@ -106,10 +111,6 @@ module JsDuck
          at_member
        elsif look(/@alias\b/)
          at_alias
        elsif look(/@author\b/)
          at_author
        elsif look(/@docauthor\b/)
          at_docauthor
        elsif look(/@deprecated\b/)
          at_deprecated
        elsif look(/@var\b/)
@@ -129,7 +130,16 @@ module JsDuck
          # this is detected just to be ignored
          boolean_at_tag(/@abstract/, :abstract)
        elsif look(/@/)
          @current_tag[:doc] += @input.scan(/@/)
          @input.scan(/@/)
          if @meta_tags_map[look(/\w+/)]
            add_tag(:meta)
            @current_tag[:name] = match(/\w+/)
            skip_horiz_white
            @current_tag[:content] = @input.scan(/.*$/)
            skip_white
          else
            @current_tag[:doc] += "@"
          end
        elsif look(/[^@]/)
          @current_tag[:doc] += @input.scan(/[^@]+/)
        end
@@ -303,24 +313,6 @@ module JsDuck
      skip_white
    end

    # matches @author some name ... newline
    def at_author
      match(/@author/)
      add_tag(:author)
      skip_horiz_white
      @current_tag[:name] = @input.scan(/.*$/)
      skip_white
    end

    # matches @docauthor some name ... newline
    def at_docauthor
      match(/@docauthor/)
      add_tag(:docauthor)
      skip_horiz_white
      @current_tag[:name] = @input.scan(/.*$/)
      skip_white
    end

    # matches @deprecated <version> some text ... newline
    def at_deprecated
      match(/@deprecated/)
+3 −3
Original line number Diff line number Diff line
@@ -6,11 +6,11 @@ require 'jsduck/js_literal_builder'
module JsDuck

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

    # Parses the whole JavaScript block and returns array where for
+3 −8
Original line number Diff line number Diff line
@@ -113,8 +113,7 @@ module JsDuck
        :mixins => detect_list(:mixins, doc_map, code),
        :alternateClassNames => detect_list(:alternateClassNames, doc_map, code),
        :xtypes => detect_xtypes(doc_map, code),
        :author => detect_author(doc_map),
        :docauthor => detect_docauthor(doc_map),
        :meta => detect_meta(doc_map),
        :singleton => detect_singleton(doc_map, code),
        :requires => detect_list(:requires, doc_map, code),
        :uses => detect_list(:uses, doc_map, code),
@@ -317,12 +316,8 @@ module JsDuck
      end
    end

    def detect_author(doc_map)
      doc_map[:author] ? doc_map[:author].first[:name] : nil
    end

    def detect_docauthor(doc_map)
      doc_map[:docauthor] ? doc_map[:docauthor].first[:name] : nil
    def detect_meta(doc_map)
      doc_map[:meta] ? doc_map[:meta].map {|tag| {:name => tag[:name], :content => tag[:content]} } : []
    end

    def detect_deprecated(doc_map)
Loading