Skip to content

Commit

Permalink
MM: File layout
Browse files Browse the repository at this point in the history
Each module into its own directory.
  Each module that has extensions in its own subdir
  No need to separate classes/enums etc even in ObjC
  • Loading branch information
johnfairh committed Mar 6, 2024
1 parent c0657c0 commit 201ef8d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
11 changes: 9 additions & 2 deletions lib/jazzy/source_declaration/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ def objc_unexposed?
kind == 'sourcekitten.source.lang.objc.decl.unexposed'
end

OVERVIEW_KIND = 'Overview'

def self.overview
Type.new('Overview')
Type.new(OVERVIEW_KIND)
end

def overview?
kind == OVERVIEW_KIND
end

MARKDOWN_KIND = 'document.markdown'
Expand Down Expand Up @@ -194,7 +200,8 @@ def ==(other)
dash: 'Guide',
}.freeze,

'Overview' => {
# Group/Overview
OVERVIEW_KIND => {
jazzy: nil,
dash: 'Section',
}.freeze,
Expand Down
46 changes: 37 additions & 9 deletions lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def self.sanitize_filename(doc)
end

# rubocop:disable Metrics/MethodLength
# Generate doc URL by prepending its parents URLs
# Generate doc URL by prepending its parents' URLs
# @return [Hash] input docs with URLs
def self.make_doc_urls(docs)
docs.each do |doc|
Expand Down Expand Up @@ -229,18 +229,46 @@ def self.make_doc_urls(docs)
# Guides in the root for back-compatibility.
# Declarations under outer namespace type (Structures, Classes, etc.)
def self.subdir_for_doc(doc)
return [] if doc.type.markdown?

top_level_decl = doc.namespace_path.first
if top_level_decl.type.name
[top_level_decl.type.plural_url_name] +
doc.namespace_ancestors.map(&:name)
if Config.instance.multiple_modules?
subdir_for_doc_multi_module(doc)
else
# Category - in the root
[]
# Back-compatibility layout version
subdir_for_doc_single_module(doc)
end
end

# Pre-multi-module site layout, does not allow for
# types with the same name.
def self.subdir_for_doc_single_module(doc)
# Guides + Groups in the root
return [] if doc.type.markdown? || doc.type.overview?

[doc.namespace_path.first.type.plural_url_name] +
doc.namespace_ancestors.map(&:name)
end

# Multi-module site layout, separate each module that
# is being documented.
def self.subdir_for_doc_multi_module(doc)
# Guides + Groups in the root
return [] if doc.type.markdown? || doc.type.overview?

root_decl = doc.namespace_path.first

# Extensions need an extra dir to allow for extending
# ExternalModule1.TypeName and ExternalModule2.TypeName
namespace_subdir =
if root_decl.type.swift_extension?
['Extensions', root_decl.module_name]
else
['Types']
end

[root_decl.doc_module_name] +
namespace_subdir +
doc.namespace_ancestors.map(&:name)
end

# returns all subdirectories of specified path
def self.rec_path(path)
path.children.collect do |child|
Expand Down

0 comments on commit 201ef8d

Please sign in to comment.