Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple modules #1379

Merged
merged 14 commits into from
Mar 6, 2024
Prev Previous commit
Next Next commit
MM: Module-aware custom-categories
johnfairh committed Feb 28, 2024
commit 28ed09802b6c5c80d64fada74b3633fdd13d923f
22 changes: 15 additions & 7 deletions lib/jazzy/grouper.rb
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ module Grouper
extend Config::Mixin

# Group root-level docs by custom categories (if any) and type or module
def self.group_docs(docs)
custom_categories, docs = group_custom_categories(docs)
def self.group_docs(docs, doc_index)
custom_categories, docs = group_custom_categories(docs, doc_index)
unlisted_prefix = config.custom_categories_unlisted_prefix
type_category_prefix = custom_categories.any? ? unlisted_prefix : ''
all_categories =
@@ -47,15 +47,23 @@ def self.group_docs_by_module(docs, type_category_prefix)
guide_categories + module_categories
end

def self.group_custom_categories(docs)
def self.group_custom_categories(docs, doc_index)
group = config.custom_categories.map do |category|
children = category['children'].flat_map do |name|
docs_with_name, docs = docs.partition { _1.name == name }
if docs_with_name.empty?
children = category['children'].filter_map do |name|
unless doc = doc_index.lookup(name)
warn 'WARNING: No documented top-level declarations match ' \
"name \"#{name}\" specified in categories file"
next nil
end
docs_with_name

unless doc.parent_in_code.nil?
warn "WARNING: Declaration \"#{doc.fully_qualified_module_name}\" " \
'specified in categories file exists but is not top-level and ' \
'cannot be included here'
next nil
end

docs.delete(doc)
end
# Category config overrides alphabetization
children.each.with_index { |child, i| child.nav_order = i }
2 changes: 1 addition & 1 deletion lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
@@ -1076,7 +1076,7 @@ def self.parse(sourcekitten_output, options, inject_docs)

@doc_index = DocIndex.new(docs)

docs = Grouper.group_docs(docs)
docs = Grouper.group_docs(docs, @doc_index)

make_doc_urls(docs)
autolink(docs)