From 051d2f81636f1db70f1fe692dd8f4018261e1af3 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 7 Dec 2010 21:41:17 +0200 Subject: [PATCH] Renamed DocLinks to DocFormatter. It does now more than just links replacement. --- lib/jsduck/{doc_links.rb => doc_formatter.rb} | 10 +++++----- lib/jsduck/long_params.rb | 6 ++++-- lib/jsduck/page.rb | 6 +++--- lib/jsduck/table.rb | 6 +++--- ...doc_links_spec.rb => doc_formatter_spec.rb} | 18 +++++++++--------- 5 files changed, 24 insertions(+), 22 deletions(-) rename lib/jsduck/{doc_links.rb => doc_formatter.rb} (88%) rename spec/{doc_links_spec.rb => doc_formatter_spec.rb} (61%) diff --git a/lib/jsduck/doc_links.rb b/lib/jsduck/doc_formatter.rb similarity index 88% rename from lib/jsduck/doc_links.rb rename to lib/jsduck/doc_formatter.rb index 075f97da..eae15997 100644 --- a/lib/jsduck/doc_links.rb +++ b/lib/jsduck/doc_formatter.rb @@ -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 diff --git a/lib/jsduck/long_params.rb b/lib/jsduck/long_params.rb index b8407dd1..4d7ca879 100644 --- a/lib/jsduck/long_params.rb +++ b/lib/jsduck/long_params.rb @@ -1,10 +1,12 @@ +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 [ "
  • ", "#{param[:name]} : #{param[:type]}", diff --git a/lib/jsduck/page.rb b/lib/jsduck/page.rb index 5a8f94a4..e3e7cc46 100644 --- a/lib/jsduck/page.rb +++ b/lib/jsduck/page.rb @@ -1,4 +1,4 @@ -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 - "
    #{@links.format(@cls[:doc])}
    " + "
    #{@formatter.format(@cls[:doc])}
    " end end diff --git a/lib/jsduck/table.rb b/lib/jsduck/table.rb index 375fe854..f1ff0d1c 100644 --- a/lib/jsduck/table.rb +++ b/lib/jsduck/table.rb @@ -1,4 +1,4 @@ -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] diff --git a/spec/doc_links_spec.rb b/spec/doc_formatter_spec.rb similarity index 61% rename from spec/doc_links_spec.rb rename to spec/doc_formatter_spec.rb index 1cd6a6c2..29155c9c 100644 --- a/spec/doc_links_spec.rb +++ b/spec/doc_formatter_spec.rb @@ -1,38 +1,38 @@ -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 Ext.Msg' 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 Foo.bar' 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 bar' 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 link text' 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 -- GitLab