Skip to content

Commit

Permalink
Fix realm#1400: Group global constants and functions by file name
Browse files Browse the repository at this point in the history
  • Loading branch information
thePsguy committed Sep 19, 2024
1 parent fd0b539 commit 668eba7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/jazzy/doc_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def lookup_path(parts)
[self] +
(children[parts.first]&.lookup_path(parts[1...]) || [])
end

include Enumerable

def each(&block)
return to_enum(:each) unless block_given?

block.call(decl) if decl

children.each do |index_name, scope|
scope.each(&block) unless index_name.include?('...')
end
end
end

attr_reader :root_scope
Expand All @@ -77,6 +89,12 @@ def initialize(all_decls)
@root_scope = Scope.new_root(all_decls.group_by(&:module_name))
end

include Enumerable

def each(&block)
root_scope.each(&block)
end

# Look up a name and return the matching SourceDeclaration or nil.
#
# `context` is an optional SourceDeclaration indicating where the text
Expand Down
34 changes: 33 additions & 1 deletion lib/jazzy/grouper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,39 @@ def self.group_custom_categories(docs, doc_index)
children.each.with_index { |child, i| child.nav_order = i }
make_group(children, category['name'], '')
end
[group.compact, docs]

globals_grouped_by_file = self.group_globals_by_file(docs, doc_index)
[group.compact, docs + globals_grouped_by_file]
end

def self.group_globals_by_file(docs, doc_index)
types_to_files_to_symbols = {}
doc_index.each do |index_item|
if index_item.parent_in_code.nil? && (index_item.type.name == "Constant" || index_item.type.name == "Function")
file_name = File.basename(index_item.file, ".*")
types_to_files_to_symbols[index_item.type.plural_name] ||= {}
types_to_files_to_symbols[index_item.type.plural_name][file_name] ||= []

types_to_files_to_symbols[index_item.type.plural_name][file_name] << docs.delete(index_item)

end
end

types_to_file_groups = {}
types_to_files_to_symbols.each do |type_name, files|
types_to_file_groups[type_name] ||= []
files.each do |file, declarations|
file_group = make_group(declarations, file, 'Globally available these types, are.')
file_group.url_name = "#{file}+#{type_name}"
types_to_file_groups[type_name] << file_group
end
end

type_groups = types_to_file_groups.map do |type_name, files_level_declarations|
make_group(files_level_declarations, type_name, 'These types are available globally.')
end.compact

type_groups
end

def self.group_guides(docs, prefix)
Expand Down

0 comments on commit 668eba7

Please sign in to comment.