Commit 88ef0369 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Process @cfg tag fully inside Tag::Cfg.

Now we have completely removed the use of Doc::Subproperties from
Doc::Ast class.
parent 9b3b58ea
Loading
Loading
Loading
Loading
+0 −23
Original line number Diff line number Diff line
require 'jsduck/tag_registry'
require 'jsduck/doc/subproperties'
require 'jsduck/logger'

module JsDuck
  module Doc
@@ -63,11 +61,7 @@ module JsDuck
      def create_cfg(docs, doc_map)
        return add_shared({
            :tagname => :cfg,
            :name => detect_name(:cfg, doc_map),
            :type => detect_type(:cfg, doc_map),
            :doc => detect_doc(:cfg, doc_map),
            :default => detect_default(:cfg, doc_map),
            :properties => detect_subproperties(:cfg, docs),
          }, doc_map)
      end

@@ -105,8 +99,6 @@ module JsDuck
          end
        end

        hash[:required] = true if detect_required(doc_map)

        return hash
      end

@@ -131,21 +123,6 @@ module JsDuck
        extract(doc_map, tagname, :default)
      end

      def detect_required(doc_map)
        doc_map[:cfg] && doc_map[:cfg].first[:optional] == false
      end

      def detect_subproperties(tagname, docs)
        prop_docs = docs.find_all {|tag| tag[:tagname] == tagname}
        prop_docs.length > 0 ? nest_properties(prop_docs)[0][:properties] : []
      end

      def nest_properties(raw_items)
        items, warnings = Doc::Subproperties.nest(raw_items)
        warnings.each {|msg| Logger.warn(:subproperty, msg, @filename, @linenr) }
        items
      end

      # Returns documentation for class or member.
      def detect_doc(tagname, doc_map)
        doc = extract(doc_map, :doc, :doc) || ""
+17 −0
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/doc/subproperties"

module JsDuck::Tag
  class Cfg < Tag
    def initialize
      @pattern = "cfg"
      @key = :cfg
      @member_type = :cfg
    end

@@ -18,5 +20,20 @@ module JsDuck::Tag
    def parse_required(p)
      p.hw.match(/\(required\)/i)
    end

    def process_doc(h, tags, pos)
      p = tags[0]
      h[:name] = p[:name]
      h[:type] = p[:type]
      h[:default] = p[:default]
      h[:properties] = nest_properties(tags, pos)
      h[:required] = true if p[:optional] == false
    end

    def nest_properties(tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      items[0][:properties]
    end
  end
end