Sha256: 3c26deac3b3dd1cb09ff7d2ae3438b47fa54ef0bb9246fd0d788d78521b925f8

Contents?: true

Size: 1.89 KB

Versions: 22

Compression:

Stored size: 1.89 KB

Contents

require 'jsduck/meta_tag_renderer'

module JsDuck

  # Performs the rendering of member signatures.
  class SignatureRenderer
    # Initializes the renderer for rendering members of the given
    # class.
    def initialize(cls)
      @cls = cls
    end

    # Renders signature of the given member.
    def render(member)
      # Keep the code simpler by not passing around the member hash
      @m = member

      return [
        render_new,
        render_link,
        render_type,
        render_meta,
      ]
    end

    private

    def render_new
      constructor? ? "<strong class='new-keyword'>new</strong>" : ""
    end

    def render_link
      "<a href='#{render_url}' class='name #{render_expandable}'>#{render_name}</a>"
    end

    def render_url
      "#!/api/#{@m[:owner]}-#{@m[:id]}"
    end

    def render_expandable
      @m[:shortDoc] ? "expandable" : "not-expandable"
    end

    def render_name
      constructor? ? @cls[:name] : @m[:name]
    end

    def constructor?
      @m[:tagname] == :method && @m[:name] == "constructor"
    end

    def render_type
      if like_property?
        render_property_type
      else
        render_params + render_return
      end
    end

    def like_property?
      @m[:tagname] == :cfg || @m[:tagname] == :property || @m[:tagname] == :css_var
    end

    def render_property_type
      "<span> : #{@m[:html_type]}</span>"
    end

    def render_params
      ps = @m[:params].map {|p| render_single_param(p) }.join(", ")
      "( <span class='pre'>#{ps}</span> )"
    end

    def render_single_param(param)
      param[:optional] ? "["+param[:name]+"]" : param[:name]
    end

    def render_return
      method_with_return? ? (" : " + @m[:return][:html_type]) : ""
    end

    def method_with_return?
      @m[:tagname] == :method && @m[:return][:type] != "undefined"
    end

    def render_meta
      MetaTagRenderer.render_signature(@m)
    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
jsduck-4.10.4 lib/jsduck/signature_renderer.rb
jsduck-4.10.3 lib/jsduck/signature_renderer.rb
jsduck-4.10.2 lib/jsduck/signature_renderer.rb
jsduck-4.10.1 lib/jsduck/signature_renderer.rb
jsduck-4.10.0 lib/jsduck/signature_renderer.rb
jsduck-4.9.0 lib/jsduck/signature_renderer.rb
jsduck-4.8.0 lib/jsduck/signature_renderer.rb
jsduck-4.7.1 lib/jsduck/signature_renderer.rb
jsduck-4.7.0 lib/jsduck/signature_renderer.rb
jsduck-4.6.2 lib/jsduck/signature_renderer.rb
jsduck-4.6.1 lib/jsduck/signature_renderer.rb
jsduck-4.6.0 lib/jsduck/signature_renderer.rb
jsduck-4.5.1 lib/jsduck/signature_renderer.rb
jsduck-4.5.0 lib/jsduck/signature_renderer.rb
jsduck-4.4.1 lib/jsduck/signature_renderer.rb
jsduck-4.4.0 lib/jsduck/signature_renderer.rb
jsduck-4.3.2 lib/jsduck/signature_renderer.rb
jsduck-4.3.1 lib/jsduck/signature_renderer.rb
jsduck-4.3.0 lib/jsduck/signature_renderer.rb
jsduck-4.2.1 lib/jsduck/signature_renderer.rb