Commit 05c47584 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement Tag#format method like in old meta tags.

This way the to_html only needs to take one parameter and the
formatter can be passed to tags only once, when starting the
HTML generation, instead of passing it every time when invoking
the #to_html method.
parent fc416b61
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ module JsDuck::Builtins
      v
    end

    def to_html(context, formatter)
    def to_html(context)
      v = context[:deprecated][:version] ? "since " + context[:deprecated][:version] : ""
      <<-EOHTML
        <div class='signature-box deprecated'>
        <p>This #{context[:tagname]} has been <strong>deprecated</strong> #{v}</p>
        #{formatter.format(depr[:text])}
        #{format(depr[:text])}
        </div>
      EOHTML
    end
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ module JsDuck::Builtins
      true
    end

    def to_html(context, formatter)
    def to_html(context)
      <<-EOHTML
        <div class='signature-box preventable'>
        <p>This action following this event is <b>preventable</b>.
+10 −4
Original line number Diff line number Diff line
@@ -60,12 +60,18 @@ module JsDuck::Builtins
    #
    # 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 of formatter, which is also passed in, to
    # easily support Markdown and {@link/img} tags inside the
    # contents.
    def to_html(context, formatter)
    # use the #format method to easily support Markdown and
    # {@link/img} tags inside the contents.
    def to_html(context)
    end

    # Helper method for use if #to_html for rendering markdown.
    def format(markdown)
      @formatter.format(markdown)
    end

    attr_accessor :formatter

    # Returns all descendants of JsDuck::Builtins::Tag class.
    def self.descendants
      result = []
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ module JsDuck::Builtins
      super
    end

    def to_html(context, formatter)
    def to_html(context)
      <<-EOHTML
      <div class='signature-box template'>
      <p>This is a <a href="#!/guide/components">template method</a>.
+10 −2
Original line number Diff line number Diff line
@@ -15,9 +15,17 @@ module JsDuck
    def initialize(relations, formatter)
      @relations = relations
      @formatter = formatter
      @include_types = true
      inject_formatter_to_tags
    end

    def inject_formatter_to_tags
      # inject formatter to all meta-tags
      MetaTagRegistry.instance.formatter = formatter
      @include_types = true
      # inject formatter to all html-producing tags
      BuiltinsRegistry.get_html_renderers.each do |tag|
        tag.formatter = @formatter
      end
    end

    # Runs the formatter on doc object of a class.
@@ -104,7 +112,7 @@ module JsDuck
      result = {}
      BuiltinsRegistry.get_html_renderers.each do |tag|
        if context[tag.key]
          result[tag.key] = tag.to_html(context, @formatter)
          result[tag.key] = tag.to_html(context)
        end
      end
      result