From 1b5ec2c46350d15994351cddb590ae12a309ad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20B=C3=B6rjesson?= Date: Wed, 7 Aug 2024 19:57:07 +0200 Subject: [PATCH 1/2] Don't reference nodoc types in generated html --- src/compiler/crystal/tools/doc/html/type.html | 10 +++++----- src/compiler/crystal/tools/doc/templates.cr | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/compiler/crystal/tools/doc/html/type.html b/src/compiler/crystal/tools/doc/html/type.html index 10c7e51fedd3..e9918c6fe429 100644 --- a/src/compiler/crystal/tools/doc/html/type.html +++ b/src/compiler/crystal/tools/doc/html/type.html @@ -45,10 +45,10 @@

<%= type.formatted_alias_definition %> <% end %> -<%= OtherTypesTemplate.new("Included Modules", type, type.included_modules) %> -<%= OtherTypesTemplate.new("Extended Modules", type, type.extended_modules) %> -<%= OtherTypesTemplate.new("Direct Known Subclasses", type, type.subclasses) %> -<%= OtherTypesTemplate.new("Direct including types", type, type.including_types) %> +<%= OtherTypesTemplate.new("Included Modules", type, included_modules_with_docs) %> +<%= OtherTypesTemplate.new("Extended Modules", type, extended_modules_with_docs) %> +<%= OtherTypesTemplate.new("Direct Known Subclasses", type, subclasses_with_docs) %> +<%= OtherTypesTemplate.new("Direct including types", type, including_types_with_docs) %> <% if locations = type.locations %>

@@ -99,7 +99,7 @@

<%= MethodSummaryTemplate.new("Instance Method Summary", type.instance_methods) %>
- <% type.ancestors.each do |ancestor| %> + <% ancestors_with_docs.each do |ancestor| %> <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.instance_methods, "Instance") %> <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.constructors, "Constructor") %> <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.class_methods, "Class") %> diff --git a/src/compiler/crystal/tools/doc/templates.cr b/src/compiler/crystal/tools/doc/templates.cr index 91ad32e1d0d1..f03db544873c 100644 --- a/src/compiler/crystal/tools/doc/templates.cr +++ b/src/compiler/crystal/tools/doc/templates.cr @@ -30,6 +30,12 @@ module Crystal::Doc end record TypeTemplate, type : Type, types : Array(Type), project_info : ProjectInfo do + {% for method in ["ancestors", "included_modules", "extended_modules", "subclasses", "including_types"] %} + def {{method.id}}_with_docs + type.{{method.id}}.select { |related_type| related_type.in?(types) } + end + {% end %} + ECR.def_to_s "#{__DIR__}/html/type.html" end From 704d93e628b12ac60d31be5a4419151f551b97f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20B=C3=B6rjesson?= Date: Wed, 7 Aug 2024 22:01:01 +0200 Subject: [PATCH 2/2] Simplify *_with_docs methods Co-authored-by: Sijawusz Pur Rahnama --- src/compiler/crystal/tools/doc/templates.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/crystal/tools/doc/templates.cr b/src/compiler/crystal/tools/doc/templates.cr index f03db544873c..4aaf5ac9029e 100644 --- a/src/compiler/crystal/tools/doc/templates.cr +++ b/src/compiler/crystal/tools/doc/templates.cr @@ -30,10 +30,10 @@ module Crystal::Doc end record TypeTemplate, type : Type, types : Array(Type), project_info : ProjectInfo do - {% for method in ["ancestors", "included_modules", "extended_modules", "subclasses", "including_types"] %} + {% for method in %w[ancestors included_modules extended_modules subclasses including_types] %} def {{method.id}}_with_docs - type.{{method.id}}.select { |related_type| related_type.in?(types) } - end + type.{{method.id}}.select!(&.in?(types)) + end {% end %} ECR.def_to_s "#{__DIR__}/html/type.html"