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

Refactor away extroneous code from Doc::Ast.

Specific methods per each member type are no more needed - we can cover
it all with just a little bit of generic code.
parent 87856f21
Loading
Loading
Loading
Loading
+16 −80
Original line number Diff line number Diff line
@@ -14,80 +14,14 @@ module JsDuck
        @linenr = 0
      end

      # Given tagname and array of tags from DocParser, produces docs
      # Given tagname and map of tags from DocParser, produces docs
      # of the type determined by tagname.
      def detect(tagname, docs, doc_map)
        case tagname
        when :class
          create_class(docs, doc_map)
        when :event
          create_event(docs, doc_map)
        when :method
          create_method(docs, doc_map)
        when :cfg
          create_cfg(docs, doc_map)
        when :property
          create_property(docs, doc_map)
        when :css_var
          create_css_var(docs, doc_map)
        when :css_mixin
          create_css_mixin(docs, doc_map)
        end
      end

      private

      def create_class(docs, doc_map)
        return add_shared({
            :tagname => :class,
            :doc => detect_doc(:class, doc_map),
          }, doc_map)
      end

      def create_method(docs, doc_map)
        return add_shared({
            :tagname => :method,
            :doc => detect_doc(:method, doc_map),
          }, doc_map)
      end

      def create_event(docs, doc_map)
        return add_shared({
            :tagname => :event,
            :doc => detect_doc(:event, doc_map),
          }, doc_map)
      end

      def create_cfg(docs, doc_map)
        return add_shared({
            :tagname => :cfg,
            :doc => detect_doc(:cfg, doc_map),
          }, doc_map)
      end

      def create_property(docs, doc_map)
        return add_shared({
            :tagname => :property,
            :doc => detect_doc(:property, doc_map),
          }, doc_map)
      end

      def create_css_var(docs, doc_map)
        return add_shared({
            :tagname => :css_var,
            :doc => detect_doc(:css_var, doc_map),
          }, doc_map)
      end

      def create_css_mixin(docs, doc_map)
        return add_shared({
            :tagname => :css_mixin,
            :doc => detect_doc(:css_mixin, doc_map),
          }, doc_map)
      end
      def detect(tagname, doc_map)
        hash = {
          :tagname => tagname,
          :doc => detect_doc(tagname, doc_map),
        }

      # Detects properties common for each doc-object and adds them
      def add_shared(hash, doc_map)
        position = {:filename => @filename, :linenr => @linenr}

        doc_map.each_pair do |key, value|
@@ -99,14 +33,7 @@ module JsDuck
        return hash
      end

      def extract(doc_map, tagname, propname = nil)
        tag = doc_map[tagname] ? doc_map[tagname].first : nil
        if tag && propname
          tag[propname]
        else
          tag
        end
      end
      private

      # Returns documentation for class or member.
      def detect_doc(tagname, doc_map)
@@ -119,6 +46,15 @@ module JsDuck
        doc
      end

      def extract(doc_map, tagname, propname = nil)
        tag = doc_map[tagname] ? doc_map[tagname].first : nil
        if tag && propname
          tag[propname]
        else
          tag
        end
      end

    end

  end
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ module JsDuck
      # Merges comment and code parts of docset
      def merge(docset)
        @doc_ast.linenr = docset[:linenr]
        docset[:comment] = @doc_ast.detect(docset[:tagname], docset[:comment], docset[:doc_map])
        docset[:comment] = @doc_ast.detect(docset[:tagname], docset[:doc_map])
        docset.delete(:doc_map)

        @merger.merge(docset)