Skip to content

Commit

Permalink
Expose inherited macros in generated API docs (crystal-lang#13810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Nov 8, 2023
1 parent 92edee4 commit c25640d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/compiler/crystal/tools/doc/html/_macros_inherited.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% macro_groups = macros.group_by { |m| m.name } %>
<% unless macro_groups.empty? %>
<h3>Macros inherited from <%= ancestor.kind %> <code><%= ancestor.link_from(type) %></code></h3>
<% i = 0 %>
<% macro_groups.each do |k, v| %>
<a href="<%= type.path_to(ancestor) %><%= v[0].anchor %>" class="tooltip">
<span><%= v.map { |m| m.name + m.args_to_html(:highlight) } .join("<br/>") %></span>
<%= k %></a><%= ", " if i != macro_groups.size - 1 %>
<% i += 1 %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions src/compiler/crystal/tools/doc/html/type.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ <h2>
<%= MethodsInheritedTemplate.new(type, ancestor, ancestor.instance_methods, "Instance") %>
<%= MethodsInheritedTemplate.new(type, ancestor, ancestor.constructors, "Constructor") %>
<%= MethodsInheritedTemplate.new(type, ancestor, ancestor.class_methods, "Class") %>
<%= MacrosInheritedTemplate.new(type, ancestor, ancestor.macros) %>
<% end %>
</div>

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/doc/templates.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ module Crystal::Doc
ECR.def_to_s "#{__DIR__}/html/_methods_inherited.html"
end

record MacrosInheritedTemplate, type : Type, ancestor : Type, macros : Array(Macro) do
ECR.def_to_s "#{__DIR__}/html/_macros_inherited.html"
end

record OtherTypesTemplate, title : String, type : Type, other_types : Array(Type) do
ECR.def_to_s "#{__DIR__}/html/_other_types.html"
end
Expand Down

0 comments on commit c25640d

Please sign in to comment.