forked from rails/sdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_context.rhtml
189 lines (166 loc) · 5.7 KB
/
_context.rhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<div id="context">
<% unless (description = context.description).empty? %>
<div class="description">
<%= description %>
</div>
<% end %>
<%# File only: requires %>
<% unless context.requires.empty? %>
<div class="content__divider">Required Files</div>
<ul>
<% context.requires.each do |req| %>
<li><%= full_name req.name %></li>
<% end %>
</ul>
<% end %>
<%# Module only: ancestors %>
<% unless context.is_a?(RDoc::TopLevel) || (ancestors = module_ancestors(context)).empty? %>
<div class="content__divider">Inherits From</div>
<ul>
<% ancestors.each do |kind, ancestor| %>
<li>
<span class="kind"><%= kind %></span>
<%= ancestor.is_a?(String) ? full_name(ancestor) : link_to(ancestor) %>
</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="content__divider">Sections</div>
<ul>
<% sections.each do |section| %>
<li><%= link_to h(section.title), "##{section.aref}" %></li>
<% end %>
</ul>
<% end %>
<% unless context.method_list.empty? %>
<!-- Method ref -->
<div class="content__divider">Methods</div>
<dl class="methods">
<% group_by_first_letter(context.method_list).each do |letter, methods| %>
<dt><%= letter %></dt>
<dd>
<ul>
<% methods.each_with_index do |method, i| %>
<%
comma = methods.size == i+1 ? '' : ','
%>
<li><%= link_to short_name(method), method %><%= comma %></li>
<% end %>
</ul>
</dd>
<% end %>
</dl>
<% end %>
<% context.each_section do |section, constants, attributes| %>
<% if section.title then %>
<div class="content__section-title" 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 -->
<h2 class="content__divider">Constants</h2>
<table border='0' cellpadding='5'>
<% constants.each do |const| %>
<tr valign='top'>
<td class="attr-name"><%= short_name const %></td>
<td>=</td>
<td class="attr-value"><%= h const.value %></td>
</tr>
<% if const.comment %>
<tr valign='top'>
<td> </td>
<td colspan="2" class="attr-desc"><%= const.description.strip %></td>
</tr>
<% end %>
<% end %>
</table>
<% end %>
<% unless attributes.empty? %>
<!-- Section attributes -->
<h2 class="content__divider">Attributes</h2>
<table border='0' cellpadding='5'>
<% attributes.each do |attrib| %>
<tr valign='top'>
<td class='attr-rw'>
[<%= attrib.rw %>]
</td>
<td class='attr-name'><%= short_name attrib %></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?
%>
<h2 class="content__divider"><%= visibility.to_s.capitalize %> <%= type %> methods</h2>
<% methods.each do |method| %>
<div class="method" id="<%= method.aref %>">
<div class="method__signature">
<h3><%= method_signature method %></h3>
<%= link_to %(<img src="/i/link.svg" alt="Permalink">), method,
class: "method__permalink", title: "Permalink" %>
</div>
<% unless method.aliases.empty? %>
<p class="method__aka">
Also aliased as:
<%# Sometimes a parent cannot be determined. See ruby/rdoc@85ebfe13dc. %>
<%= method.aliases.map { |aka| link_to_if aka.parent, short_name(aka), aka }.join(", ") %>.
</p>
<% end %>
<% if alias_for = method.is_alias_for then %>
<p class="method__aka">
Alias for:
<%= link_to short_name(alias_for), alias_for %>.
</p>
<% end %>
<% if method.comment %>
<div class="description">
<%= method.description %>
</div>
<% end %>
<% source_code, source_url = method_source_code_and_url(method) %>
<% if source_code %>
<details class="method__source">
<summary>
<span class="label">Source code</span>
<% if source_url %>
<%= link_to_external "GitHub", source_url %>
<% end %>
</summary>
<pre><code class="ruby"><%= source_code %></code></pre>
</details>
<% elsif source_url %>
<p class="method__source"><%= link_to_external "GitHub", source_url %></p>
<% end %>
</div>
<% end %><%# methods.each %>
<% end %><%# visibilities.each %>
<% end %><%# context.methods_by_type %>
<% end %><%# context.each_section %>
<% unless context.classes_and_modules.empty? %>
<!-- Namespace -->
<div class="content__divider">Namespace</div>
<ul>
<% (context.modules.sort + context.classes.sort).each do |mod| %>
<li>
<span class="kind"><%= mod.type %></span>
<%= link_to mod %>
</li>
<% end %>
</ul>
<% end %>
</div>