kit-doc edge

Sidebar module
Kit::Doc::Services::Sidebar
View Source

Data transformation logic for the documentation Sidebar content.


Link to this section Summary ⚠️ Private APIs are currently hidden.


Link to this section Class methods 3

Link to this method

.find_element_groups(element_name:, groups:)

View Source

Check if an element (module / extra) should be part of a group, based on its name, given groups conditions.

An element be in multiple groups if it matches inclusion conditions.

Also generate the display name && css classes.

If no group is specified, we default to the empty group (first to be displayed) rather than hidding the element.

Link to this method

.get_ordered_groups_container(groups:)

View Source

Generate the group container needed in sidebar_items.

This maintain the group order defined in the initial config.

Link to this method

.transform_matchers(group_data:, group_name:)

View Source

Transform the group matcher input format to allow Callables & Regexps.

The following is valid input:

groups_for_modules: {
  # List of regexps
  'My group' => [
    # Regexp
    %r{^ClassA$},
    # Callable
    ->(name) { name.start_with?('ModuleB'),
    # Hash with the following keys:
    {
      # Inclusion needs to be either a Regexp or a Callable
      inclusion:   %r{^ModuleB.*},
      # A callable that returns an array of css classes
      css_classes: ->(name) do
        ['text-left', name.start_with?('Module') ? 'module' : 'class'],
      end,
      # A callable that return the name that will be displayed in the sidebar
      display_title: ->(name) { name.split('::')[-1] },
    },
  ],
}