Commit 92f9f337 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add support for @template.

- This @tag only applies to methods.
- Rendered it in method signature just like @protected.
- Added small info-div explaining the purpose of template methods.
parent d9399b29
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ module JsDuck
    end

    def expandable?(m)
      m[:params] || (m[:properties] && m[:properties].length > 0) || m[:default] || m[:deprecated]
      m[:params] || (m[:properties] && m[:properties].length > 0) || m[:default] || m[:deprecated] || m[:template]
    end

    def format_item(it, is_css_tag)
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ module JsDuck
          boolean_at_tag(/@protected/, :protected)
        elsif look(/@accessor\b/)
          boolean_at_tag(/@accessor/, :accessor)
        elsif look(/@template\b/)
          boolean_at_tag(/@template/, :template)
        elsif look(/@markdown\b/)
          # this is detected just to be ignored
          boolean_at_tag(/@markdown/, :markdown)
+1 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ module JsDuck
        :doc => detect_doc(docs),
        :params => detect_params(docs, code),
        :return => detect_return(doc_map, name == "constructor" ? "Object" : "undefined"),
        :template => !!doc_map[:template],
      }, doc_map)
    end

+12 −0
Original line number Diff line number Diff line
@@ -228,6 +228,9 @@ module JsDuck
      if m[:tagname] == :cfg && !m[:optional]
        after += "<strong class='required-signature'>required</strong>"
      end
      if m[:template]
        after += "<strong class='template-signature'>template</strong>"
      end

      uri = "#!/api/#{m[:owner]}-#{m[:tagname]}-#{m[:name]}"

@@ -261,6 +264,15 @@ module JsDuck
        ]
      end

      if m[:template]
        doc << [
          "<div class='template'>",
          "<p>This is a template method. A hook into the functionality of this class.",
          "Feel free to override it in child classes.</p>",
          "</div>",
        ]
      end

      doc << render_params_and_return(m)

      doc
+16 −0
Original line number Diff line number Diff line
@@ -264,6 +264,22 @@ describe JsDuck::Aggregator do
    it_should_behave_like "has return"
  end

  describe "method with @template" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @method foo
         * Some function
         * @template
         */
      EOS
    end
    it_should_behave_like "method documentation"
    it "is a template method" do
      @doc[:template].should == true
    end
  end

  describe "method without doc-comment" do
    before do
      @docs = parse(<<-EOS)
Loading