Commit fc416b61 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Pass context directly to Tag#to_html method.

Instead of passing the value of current tag and then separately setting
the @context variable, we now just pass the context from which the
tag implementation needs to extract its value by itself.
parent 9df0797d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ module JsDuck::Builtins
      v
    end

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

    def to_html(contents, formatter)
    def to_html(context, formatter)
      <<-EOHTML
        <div class='signature-box preventable'>
        <p>This action following this event is <b>preventable</b>.
+6 −8
Original line number Diff line number Diff line
@@ -58,16 +58,14 @@ module JsDuck::Builtins
    # Implement #to_html to transform tag data to HTML to be included
    # into documentation.
    #
    # It gets passed the value returned by #process_doc method. 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(data, formatter)
    # 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)
    end

    attr_accessor :context

    # 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(contents, formatter)
    def to_html(context, formatter)
      <<-EOHTML
      <div class='signature-box template'>
      <p>This is a <a href="#!/guide/components">template method</a>.
+1 −2
Original line number Diff line number Diff line
@@ -104,8 +104,7 @@ module JsDuck
      result = {}
      BuiltinsRegistry.get_html_renderers.each do |tag|
        if context[tag.key]
          tag.context = context
          result[tag.key] = tag.to_html(context[tag.key], @formatter)
          result[tag.key] = tag.to_html(context, @formatter)
        end
      end
      result