Commit 051d2f81 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Renamed DocLinks to DocFormatter.

It does now more than just links replacement.
parent ced226d7
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -2,10 +2,8 @@ require 'maruku'

module JsDuck

  # Detects {@link ...} tags in text and replaces them with HTML links
  # pointing to documentation.  In addition to the href attribute
  # links will also contain ext:cls and ext:member attributes.
  class DocLinks
  # Formats doc-comments
  class DocFormatter
    # Initializes instance to work in context of particular class, so
    # that when {@link #blah} is encountered it knows that
    # Context#blah is meant.
@@ -14,7 +12,9 @@ module JsDuck
    end

    # Replaces {@link Class#member link text} in given string with
    # HTML links.
    # HTML links pointing to documentation.  In addition to the href
    # attribute links will also contain ext:cls and ext:member
    # attributes.
    def replace(input)
      input.gsub(/\{@link +(\S*?)(?: +(.+?))?\}/) do
        target = $1
+4 −2
Original line number Diff line number Diff line
require "jsduck/doc_formatter"

module JsDuck

  # Renders method/event parameters list in long form
  # for use in documentation body.
  class LongParams
    def initialize(cls)
      @links = DocLinks.new(cls.full_name)
      @formatter = DocFormatter.new(cls.full_name)
    end

    def render(params)
@@ -16,7 +18,7 @@ module JsDuck
    end

    def render_single(param)
      doc = @links.format(param[:doc])
      doc = @formatter.format(param[:doc])
      return [
        "<li>",
        "<code>#{param[:name]}</code> : #{param[:type]}",
+3 −3
Original line number Diff line number Diff line
require 'jsduck/doc_links'
require 'jsduck/doc_formatter'
require 'jsduck/cfg_table'
require 'jsduck/property_table'
require 'jsduck/method_table'
@@ -10,7 +10,7 @@ module JsDuck
  class Page
    def initialize(cls)
      @cls = cls
      @links = DocLinks.new(cls.full_name)
      @formatter = DocFormatter.new(cls.full_name)
    end

    def to_html
@@ -48,7 +48,7 @@ module JsDuck
    end

    def description
      "<div class='description'>#{@links.format(@cls[:doc])}</div>"
      "<div class='description'>#{@formatter.format(@cls[:doc])}</div>"
    end
  end

+3 −3
Original line number Diff line number Diff line
require 'jsduck/doc_links'
require 'jsduck/doc_formatter'

module JsDuck

@@ -10,7 +10,7 @@ module JsDuck
  class Table
    def initialize(cls)
      @cls = cls
      @links = DocLinks.new(cls.full_name)
      @formatter = DocFormatter.new(cls.full_name)
    end

    def to_html
@@ -75,7 +75,7 @@ module JsDuck
    end

    def primary_doc(item)
      @links.format(item[:doc])
      @formatter.format(item[:doc])
    end

    # Override to append extra documentation to the doc found in item[:doc]
+9 −9
Original line number Diff line number Diff line
require "jsduck/doc_links"
require "jsduck/doc_formatter"

describe JsDuck::DocLinks, "#replace" do
describe JsDuck::DocFormatter, "#replace" do

  before do
    @links = JsDuck::DocLinks.new("Context")
    @formatter = JsDuck::DocFormatter.new("Context")
  end

  it "replaces {@link Ext.Msg} with link to class" do
    @links.replace("Look at {@link Ext.Msg}").should ==
    @formatter.replace("Look at {@link Ext.Msg}").should ==
      'Look at <a href="output/Ext.Msg.html" ext:cls="Ext.Msg">Ext.Msg</a>'
  end

  it "replaces {@link Foo#bar} with link to class member" do
    @links.replace("Look at {@link Foo#bar}").should ==
    @formatter.replace("Look at {@link Foo#bar}").should ==
      'Look at <a href="output/Foo.html#Foo-bar" ext:cls="Foo" ext:member="bar">Foo.bar</a>'
  end

  it "uses context to replace {@link #bar} with link to class member" do
    @links.replace("Look at {@link #bar}").should ==
    @formatter.replace("Look at {@link #bar}").should ==
      'Look at <a href="output/Context.html#Context-bar" ext:cls="Context" ext:member="bar">bar</a>'
  end

  it "allows use of custom link text" do
    @links.replace("Look at {@link Foo link text}").should ==
    @formatter.replace("Look at {@link Foo link text}").should ==
      'Look at <a href="output/Foo.html" ext:cls="Foo">link text</a>'
  end

  it "leaves text without {@link...} untouched" do
    @links.replace("Look at {@me here} too").should ==
    @formatter.replace("Look at {@me here} too").should ==
      'Look at {@me here} too'
  end

  it "ignores unfinished {@link tag" do
    @links.replace("unfinished {@link tag here").should ==
    @formatter.replace("unfinished {@link tag here").should ==
      'unfinished {@link tag here'
  end
end