<div id=“content”>

<% unless (description = context.description).empty? %>
  <div class="description">
    <%= description %>
  </div>
<% end %>

<% unless context.requires.empty? %>
  <!-- File only: requires -->
  <div class="sectiontitle">Required Files</div>
  <ul>
    <% context.requires.each do |req| %>
      <li><%= h req.name %></li>
    <% end %>
  </ul>
<% end %>

<% sections = context.sections.select { |s| s.title }.sort_by{ |s| s.title.to_s } %>
<% unless sections.empty? then %>
  <!-- Sections -->
  <div class="sectiontitle">Sections</div>
  <ul>
    <% sections.each do |section| %>
      <li><a href="#<%= section.aref %>"><%= h section.title %></a></li>
    <% end %>
  </ul>
<% end %>

<% unless context.classes_and_modules.empty? %>
  <!-- Namespace -->
  <div class="sectiontitle">Namespace</div>
  <ul>
    <% (context.modules.sort + context.classes.sort).each do |mod| %>
      <li>
        <span class="type"><%= mod.type.upcase %></span>
        <a href="<%= context.aref_to mod.path %>"><%= mod.full_name %></a>
      </li>
    <% end %>
  </ul>
<% end %>

<% unless context.method_list.empty? %>
  <!-- Method ref -->
  <div class="sectiontitle">Methods</div>
  <dl class="methods">
    <% each_letter_group(context.method_list) do |group| %>
      <dt><%= group[:name] %></dt>
      <dd>
        <ul>
          <% group[:methods].each_with_index do |method, i|  %>
            <%
              comma = group[:methods].size == i+1 ? '' : ','
            %>
            <li>
              <a href="#<%= method.aref %>"><%= h method.name %></a><%= comma %>
            </li>
          <% end %>
        </ul>
      </dd>
    <% end %>
  </dl>
<% end %>

<% unless context.includes.empty? %>
  <!-- Includes -->
  <div class="sectiontitle">Included Modules</div>
  <ul>
    <% context.includes.each do |inc| %>
      <li>
        <% unless String === inc.module %>
          <a href="<%= context.aref_to inc.module.path %>">
            <%= h inc.module.full_name %>
          </a>
        <% else %>
          <%= h inc.name %>
        <% end %>
      </li>
    <% end %>
  </ul>
<% end %>

<% context.each_section do |section, constants, attributes| %>

  <% if section.title then %>
    <div class="contenttitle" id="<%= h section.aref %>">
      <%= h section.title %>
    </div>
  <% end %>

  <% if section.comment then %>
    <div class="description">
      <%= section.description %>
    </div>
  <% end %>

  <% unless constants.empty? %>
    <!-- Section constants -->
    <div class="sectiontitle">Constants</div>
    <table border='0' cellpadding='5'>
      <% context.each_constant do |const| %>
        <tr valign='top'>
          <td class="attr-name"><%= h const.name %></td>
          <td>=</td>
          <td class="attr-value"><%= h const.value %></td>
        </tr>
        <% if const.comment %>
          <tr valign='top'>
            <td>&nbsp;</td>
            <td colspan="2" class="attr-desc"><%= const.description.strip %></td>
          </tr>
        <% end %>
      <% end %>
    </table>
  <% end %>

  <% unless attributes.empty? %>
    <!-- Section attributes -->
    <div class="sectiontitle">Attributes</div>
    <table border='0' cellpadding='5'>
      <% attributes.each do |attrib| %>
        <tr valign='top'>
          <td class='attr-rw'>
            [<%= attrib.rw %>]
          </td>
          <td class='attr-name'><%= h attrib.name %></td>
          <td class='attr-desc'><%= attrib.description.strip %></td>
        </tr>
      <% end %>
    </table>
  <% end %>

  <!-- Methods -->
  <%
    context.methods_by_type(section).each do |type, visibilities|
      next if visibilities.empty?

      visibilities.each do |visibility, methods|
        next if methods.empty?
  %>
    <div class="sectiontitle"><%= type.capitalize %> <%= visibility.to_s.capitalize %> methods</div>
    <% methods.each do |method| %>
      <div class="method">
        <div class="title method-title" id="<%= method.aref %>">
          <% if method.call_seq %>
            <b><%= method.call_seq.gsub(/->/, '&rarr;') %></b>
          <% else %>
            <b><%= h method.name %></b><%= h method.params %>
          <% end %>
          <a href="<%= "#{rel_prefix}/#{context.path}##{method.aref}"%>" name="<%= method.aref %>" class="permalink">Link</a>
        </div>

        <% if method.comment %>
          <div class="description">
            <%= method.description.strip %>
          </div>
        <% end %>

        <% unless method.aliases.empty? %>
          <div class="aka">
            Also aliased as: <%= method.aliases.map do |aka|
              if aka.parent then # HACK lib/rexml/encodings
                %{<a href="#{context.aref_to aka.path}">#{h aka.name}</a>}
              else
                h aka.name
              end
            end.join ", " %>
          </div>
        <% end %>

        <% if method.is_alias_for then %>
          <div class="aka">
            Alias for: <a href="<%= context.aref_to method.is_alias_for.path %>"><%= h method.is_alias_for.name %></a>
          </div>
        <% end %>

        <% if method.token_stream %>
          <% markup = method.sdoc_markup_code %>
          <div class="sourcecode">
            <%
              # generate github link
              github = if options.github
                if markup =~ /File\s(\S+), line (\d+)/
                  path = $1
                  line = $2.to_i
                end
                path && github_url(path)
              else
                false
              end
            %>
            <p class="source-link">
              Source: 
              <a href="javascript:toggleSource('<%= method.aref %>_source')" id="l_<%= method.aref %>_source">show</a>
              <% if github %>
                | <a href="<%= "#{github}#L#{line}" %>" target="_blank" class="github_url">on GitHub</a>
              <% end %>
            </p>
            <div id="<%= method.aref %>_source" class="dyn-source">
              <pre><%= markup %></pre>
            </div>
          </div>
          <% end %>
        </div>
      <% end #methods.each %>
    <% end #visibilities.each %>
  <% end #context.methods_by_type %>
<% end #context.each_section %>

</div>