-
Notifications
You must be signed in to change notification settings - Fork 413
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
[WIP] Allow nested categories with recursive navigation. #982
Open
galli-leo
wants to merge
13
commits into
realm:master
Choose a base branch
from
galli-leo:feature-nested-categories
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
55d469f
Initial addition of nested categories
galli-leo 0c899ac
Moved subsections back to the children property.
galli-leo 14b567b
Moved categories to their own class and fixed up the css.
galli-leo c9c597e
Updated config file to include hint about nested categories. Also add…
galli-leo d8b2f27
Fixed rubocop errors, made subcategory urls go to subdirectories, tid…
galli-leo baf5989
Forgot one instance of Type.overview.
galli-leo ab9b537
Moved level to a computed property.
galli-leo 6cbe723
Changed styles to be like the original categories.
galli-leo 7c400eb
Updated Readme to include info about custom categories.
galli-leo e263604
Updated Changelog
galli-leo 4c6c76c
Make rubocop happy again.
galli-leo bee9a9d
Remove unecessary level accessor
galli-leo 75e4721
Fixed Changelog
galli-leo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'jazzy/source_declaration' | ||
require 'jazzy/config' | ||
require 'jazzy/source_mark' | ||
require 'jazzy/jazzy_markdown' | ||
|
||
module Jazzy | ||
# Category (group, contents) pages generated by jazzy | ||
class SourceCategory < SourceDeclaration | ||
extend Config::Mixin | ||
|
||
def initialize(group, name, abstract, url_name, level = 1) | ||
super() | ||
self.type = SourceDeclaration::Type.overview | ||
self.name = name | ||
self.url_name = url_name | ||
self.abstract = Markdown.render(abstract) | ||
self.children = group | ||
self.parameters = [] | ||
self.level = level | ||
end | ||
|
||
# Group root-level docs into custom categories or by type | ||
def self.group_docs(docs) | ||
custom_categories, docs = | ||
group_custom_categories(docs, config.custom_categories) | ||
type_categories, uncategorized = group_type_categories( | ||
docs, custom_categories.any? ? 'Other ' : '' | ||
) | ||
custom_categories + type_categories + uncategorized | ||
end | ||
|
||
def self.group_custom_categories(docs, categories, level = 1) | ||
group = categories.map do |category| | ||
children = category['children'].flat_map do |child| | ||
if child.is_a?(Hash) | ||
# Nested category, recurse | ||
children, docs = group_custom_categories(docs, [child], level + 1) | ||
else | ||
# Doc name, find it | ||
children, docs = docs.partition { |doc| doc.name == child } | ||
if children.empty? | ||
STDERR.puts( | ||
'WARNING: No documented top-level declarations match ' \ | ||
"name \"#{child}\" specified in categories file", | ||
) | ||
end | ||
end | ||
children | ||
end | ||
# Category config overrides alphabetization | ||
children.each.with_index { |child, i| child.nav_order = i } | ||
make_group(children, category['name'], '', nil, level) | ||
end | ||
[group.compact, docs] | ||
end | ||
|
||
def self.group_type_categories(docs, type_category_prefix) | ||
group = SourceDeclaration::Type.all.map do |type| | ||
children, docs = docs.partition { |doc| doc.type == type } | ||
make_group( | ||
children, | ||
type_category_prefix + type.plural_name, | ||
"The following #{type.plural_name.downcase} are available globally.", | ||
type_category_prefix + type.plural_url_name, | ||
) | ||
end | ||
[group.compact, docs] | ||
end | ||
|
||
def self.make_group(group, name, abstract, url_name = nil, level = 1) | ||
group.reject! { |doc| doc.name.empty? } | ||
unless group.empty? | ||
SourceCategory.new(group, name, abstract, url_name, level) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnfairh I renamed docs_with_name to children to a) make rubocop happy and b) make it's purpose clearer.
Is that ok?