diff --git a/lib/jsduck/class_formatter.rb b/lib/jsduck/class_formatter.rb index db1f3ef65d1a3aaeeceab0f20139197c20dd293f..694ac00851742276afc30a856522523adc2bd1df 100644 --- a/lib/jsduck/class_formatter.rb +++ b/lib/jsduck/class_formatter.rb @@ -16,14 +16,6 @@ module JsDuck @relations = relations @formatter = formatter @include_types = true - inject_formatter_to_tags - end - - def inject_formatter_to_tags - # inject formatter to all html-producing tags - TagRegistry.html_renderers.each do |tag| - tag.formatter = @formatter - end end # Runs the formatter on doc object of a class. @@ -35,7 +27,7 @@ module JsDuck cls[:doc] = @formatter.format(cls[:doc]) if cls[:doc] # format all members (except hidden ones) cls[:members] = cls[:members].map {|m| m[:hide] ? m : format_member(m) } - cls[:html_tags] = format_tags_data(cls) + format_tags_data(cls) cls end @@ -61,7 +53,7 @@ module JsDuck m[:return] = format_item(m[:return], is_css_tag) if m[:return] m[:throws] = m[:throws].map {|t| format_item(t, is_css_tag) } if m[:throws] m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties] - m[:html_tags] = format_tags_data(m) + format_tags_data(m) m end @@ -92,13 +84,11 @@ module JsDuck end def format_tags_data(context) - result = {} TagRegistry.html_renderers.each do |tag| if context[tag.key] - result[tag.key] = tag.to_html(context) + tag.format(context, @formatter) end end - result end end diff --git a/lib/jsduck/renderer.rb b/lib/jsduck/renderer.rb index a5c68fc0cbab99028858668f697608403d2481c5..f0b6b0b874d5a0fb1491f0ce69babca283e0c71c 100644 --- a/lib/jsduck/renderer.rb +++ b/lib/jsduck/renderer.rb @@ -19,11 +19,11 @@ module JsDuck "
", render_sidebar, "
", - render_tags(@cls[:html_tags], :top), + render_tags(@cls, :top), render_private_class_notice, @cls[:doc], render_enum_class_notice, - render_tags(@cls[:html_tags], :bottom), + render_tags(@cls, :bottom), "
", "
", render_all_sections, @@ -247,7 +247,7 @@ module JsDuck def render_long_doc(m) doc = [] - doc << render_tags(m[:html_tags], :top) + doc << render_tags(m, :top) doc << m[:doc] @@ -255,7 +255,7 @@ module JsDuck doc << "

Defaults to: " + Util::HTML.escape(m[:default]) + "

" end - doc << render_tags(m[:html_tags], :bottom) + doc << render_tags(m, :bottom) doc << render_params_and_return(m) diff --git a/lib/jsduck/tag/deprecated_tag.rb b/lib/jsduck/tag/deprecated_tag.rb index 4ac1adc5c4fd212e364ea33ef700cf6c2df79a54..156309c6e460449c82aa8a19aef905da9c741e8c 100644 --- a/lib/jsduck/tag/deprecated_tag.rb +++ b/lib/jsduck/tag/deprecated_tag.rb @@ -27,13 +27,17 @@ module JsDuck::Tag h[@key] = v end + def format(context, formatter) + context[@key][:text] = formatter.format(context[@key][:text]) + end + def to_html(context) depr = context[@key] v = depr[:version] ? "since " + depr[:version] : "" <<-EOHTML

This #{context[:tagname]} has been #{@key} #{v}

- #{format(depr[:text])} + #{depr[:text]}
EOHTML end diff --git a/lib/jsduck/tag/tag.rb b/lib/jsduck/tag/tag.rb index 6070c821792e8ee5aa35d5bbe03ab9232576a422..6eeed120ab8c0b8a0612334889a735fcafc6cffd 100644 --- a/lib/jsduck/tag/tag.rb +++ b/lib/jsduck/tag/tag.rb @@ -84,25 +84,24 @@ module JsDuck::Tag # Whether to render the tag before other content (:top) or after # it (:bottom). Must be defined together with #to_html method. + # Additionally the #format method can be defined to perform + # rendering of Markdown before #to_html is called. attr_accessor :html_position + # Called before #to_html to allow rendering of Markdown content. + # For this an instance of DocFormatter is passed in, on which one + # can call the #format method to turn Markdown into HTML. + def format(context, formatter) + end + # Implement #to_html to transform tag data to HTML to be included # into documentation. # # It gets passed the full class/member hash. It should return an - # HTML string to inject into document. For help in that it can - # use the #format method to easily support Markdown and - # {@link/img} tags inside the contents. + # HTML string to inject into document. def to_html(context) end - # Helper method for use in #to_html for rendering markdown. - def format(markdown) - @formatter.format(markdown) - end - - attr_accessor :formatter - # Returns all descendants of JsDuck::Tag::Tag class. def self.descendants result = [] diff --git a/lib/jsduck/tag_renderer.rb b/lib/jsduck/tag_renderer.rb index e59334877a81f370f26c01bc1234d030ae82d348..37891b4fdffcd8d16f09a868423fc0517ed99b94 100644 --- a/lib/jsduck/tag_renderer.rb +++ b/lib/jsduck/tag_renderer.rb @@ -2,16 +2,19 @@ require 'jsduck/tag_registry' module JsDuck - # Performs the rendering of builtin tags (for now just the signature data). + # Performs the rendering of tags. class TagRenderer # Renders tags of a particular section. # - # Returns array of rendered HTML or nil if no tag data. - def self.render(html_data, position) - return if html_data.size == 0 - + # Takes member or class hash and a position symbol. + # Returns array of rendered HTML. + def self.render(member, position) TagRegistry.html_renderers(position).map do |tag| - html_data[tag.key] + if member[tag.key] + tag.to_html(member) + else + nil + end end end