Commit 9c9155cf authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Turn @template into builtin Tag class.

As the @template generates custom HTML, the Tag classes can now have
a #to_html method and @html_position attribute.
parent 394fe946
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -47,6 +47,21 @@ module JsDuck::Builtins
    def parse_ext_define(cls, ast)
    end

    # Whether to render the tag before other content (:top) or after
    # it (:bottom).  Must be defined together with #to_html method.
    attr_accessor :html_position

    # 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)
    end

    # Returns all descendants of JsDuck::Builtins::Tag class.
    def self.descendants
      result = []
+6 −8
Original line number Diff line number Diff line
require "jsduck/meta_tag"
require "jsduck/builtins/boolean_tag"

module JsDuck::Tag
  # Implementation of @template tag
  class Template < JsDuck::MetaTag
module JsDuck::Builtins
  class Template < BooleanTag
    def initialize
      @name = "template"
      @key = :template
      @signature = {:long => "template", :short => "TMP"}
      @boolean = true
      @html_position = :bottom
      super
    end

    def to_html(contents)
    def to_html(contents, formatter)
      <<-EOHTML
      <div class='signature-box template'>
      <p>This is a <a href="#!/guide/components">template method</a>.
@@ -21,4 +20,3 @@ module JsDuck::Tag
    end
  end
end
+15 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ module JsDuck
      @ext_define_defaults = {}
      @keys = {}
      @signatures = []
      @html_renderers = {:top => [], :bottom => []}
      load_tag_classes(File.dirname(__FILE__) + "/builtins")
      instantiate_tags
    end
@@ -42,6 +43,9 @@ module JsDuck
          tag.signature[:key] = tag.key
          @signatures << tag.signature
        end
        if tag.html_position
          @html_renderers[tag.html_position] << tag
        end
      end
    end

@@ -64,6 +68,17 @@ module JsDuck
      @keys[key]
    end

    # Returns tags for rendering HTML.  One can ask for tags for
    # rendering either :top or :bottom section.  By default renderers
    # for both sections are returned.
    def get_html_renderers(position = :all)
      if position == :all
        @html_renderers[:top] + @html_renderers[:bottom]
      else
        @html_renderers[position]
      end
    end

    # Array of attributes to be shown in member signatures
    # (and in order they should be shown in).
    attr_reader :signatures
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,16 @@ module JsDuck

  # Performs the rendering of builtin tags (for now just the signature data).
  class BuiltinsRenderer
    # Renders tags of a particular section.
    #
    # Returns array of rendered HTML or nil if no meta data.
    def self.render(html_data, position)
      return if html_data.size == 0

      BuiltinsRegistry.get_html_renderers(position).map do |tag|
        html_data[tag.key]
      end
    end

    # Renders the signatures for a class member.
    # Returns a string.
+12 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ module JsDuck
      # format all members (except hidden ones)
      cls[:members] = cls[:members].map {|m| m[:hide] ? m : format_member(m)  }
      cls[:html_meta] = format_meta_data(cls)
      cls[:html_builtins] = format_builtins_data(cls)
      cls
    end

@@ -56,6 +57,7 @@ module JsDuck
      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_meta] = format_meta_data(m)
      m[:html_builtins] = format_builtins_data(m)
      m
    end

@@ -98,6 +100,16 @@ module JsDuck
      result
    end

    def format_builtins_data(context)
      result = {}
      BuiltinsRegistry.get_html_renderers.each do |tag|
        if context[tag.key]
          result[tag.key] = tag.to_html(context[tag.key], @formatter)
        end
      end
      result
    end

  end

end
Loading