diff --git a/lib/jsduck/app.rb b/lib/jsduck/app.rb index 778e60063ecba56b42d7048efcf26df2d6cda0c7..1477f3184e1fc9389ea8ce4ea4d39acf8af1a53b 100644 --- a/lib/jsduck/app.rb +++ b/lib/jsduck/app.rb @@ -165,7 +165,8 @@ module JsDuck # Formats each class def format_classes - doc_formatter = DocFormatter.new(@relations, @opts) + doc_formatter = DocFormatter.new(@opts) + doc_formatter.relations = @relations doc_formatter.img_path = "images" class_formatter = ClassFormatter.new(@relations, doc_formatter) # Don't format types when exporting diff --git a/lib/jsduck/assets.rb b/lib/jsduck/assets.rb index f4c4bf13a31cb43e8094bf9c0efa53898e9786d5..51497b4d0a4b033b25c4369e7169c4dbf7e3db54 100644 --- a/lib/jsduck/assets.rb +++ b/lib/jsduck/assets.rb @@ -26,12 +26,15 @@ module JsDuck @relations = relations @opts = opts + doc_formatter = DocFormatter.new(@opts) + doc_formatter.relations = @relations + @images = Images.new(@opts.images) @welcome = Welcome.create(@opts.welcome) - @guides = Guides.create(@opts.guides, DocFormatter.new(@relations, @opts), @opts) + @guides = Guides.create(@opts.guides, doc_formatter, @opts) @videos = Videos.create(@opts.videos) @examples = Examples.create(@opts.examples, @opts) - @categories = Categories.create(@opts.categories_path, DocFormatter.new(@relations, @opts), @relations) + @categories = Categories.create(@opts.categories_path, doc_formatter, @relations) end # Writes out the assets that can be written out separately: diff --git a/lib/jsduck/doc_formatter.rb b/lib/jsduck/doc_formatter.rb index bf8e77b7fc413ebe0e9dfba98d1bb6b9e1bedaec..240b986aa5d876adb07ea73b96f37bd941a3c3f1 100644 --- a/lib/jsduck/doc_formatter.rb +++ b/lib/jsduck/doc_formatter.rb @@ -11,11 +11,11 @@ module JsDuck # Formats doc-comments class DocFormatter - def initialize(relations={}, opts={}) - @images = [] - + # Creates a formatter configured with options originating from + # command line. For the actual effect of the options see + # Inline::* classes. + def initialize(opts={}) @inline_link = Inline::Link.new(opts) - @inline_link.relations = relations @inline_img = Inline::Img.new(opts) @inline_video = Inline::Video.new(opts) @inline_example = Inline::Example.new(opts) @@ -59,6 +59,24 @@ module JsDuck @inline_link.relations = relations end + # Formats doc-comment for placement into HTML. + # Renders it with Markdown-formatter and replaces @link-s. + def format(input) + # In ExtJS source "
" is often at the end of paragraph, not + # on its own line. But in that case RDiscount doesn't recognize + # it as the beginning of-block and goes on parsing it as + # normal Markdown, which often causes nested-blocks. + # + # To prevent this, we always add extra newline before. + input.gsub!(/([^\n])/, "\\1\n") + + # But we remove trailing newline afterto prevent + # code-blocks beginning with empty line. + input.gsub!(/()?\n?/, "
\\1") + + replace(RDiscount.new(input).to_html) + end + # Replaces {@link} and {@img} tags, auto-generates links for # recognized classnames. # @@ -111,6 +129,7 @@ module JsDuck out += open_a_tags > 0 ? text : @inline_link.create_magic_links(text) end end + out end @@ -119,24 +138,6 @@ module JsDuck @inline_link.link(cls, member, anchor_text, type, static) end - # Formats doc-comment for placement into HTML. - # Renders it with Markdown-formatter and replaces @link-s. - def format(input) - # In ExtJS source "" is often at the end of paragraph, not - # on its own line. But in that case RDiscount doesn't recognize - # it as the beginning of-block and goes on parsing it as - # normal Markdown, which often causes nested-blocks. - # - # To prevent this, we always add extra newline before. - input.gsub!(/([^\n])/, "\\1\n") - - # But we remove trailing newline afterto prevent - # code-blocks beginning with empty line. - input.gsub!(/()?\n?/, "
\\1") - - replace(RDiscount.new(input).to_html) - end - end end diff --git a/spec/type_parser_spec.rb b/spec/type_parser_spec.rb index 782e08d8171e8a00b6e99492240d6b9bf963d2c9..fd814e8d9dac6fa71a098e653bc59ff27e2d59db 100644 --- a/spec/type_parser_spec.rb +++ b/spec/type_parser_spec.rb @@ -321,7 +321,8 @@ describe JsDuck::TypeParser do it "links primitive types to classes" do relations = JsDuck::Relations.new([JsDuck::Class.new({:name => "String"})]) - doc_formatter = JsDuck::DocFormatter.new(relations) + doc_formatter = JsDuck::DocFormatter.new + doc_formatter.relations = relations p = JsDuck::TypeParser.new(relations, doc_formatter) p.parse("string") p.out.should == 'string' @@ -355,4 +356,3 @@ describe JsDuck::TypeParser do end end -