Skip to content

feat(shell): two homes — masthead follows brand_href, opt-in app_link topbar link - #63

Merged
mhenrixon merged 1 commit into
mainfrom
issue-62-app-link-docs-home
Aug 3, 2026
Merged

feat(shell): two homes — masthead follows brand_href, opt-in app_link topbar link#63
mhenrixon merged 1 commit into
mainfrom
issue-62-app-link-docs-home

Conversation

@mhenrixon

@mhenrixon mhenrixon commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Closes #62

Summary

DocsUI::Page's masthead "← Home" link hardcoded the host app's root_path route helper — the gem's only call site for it. On a docs site embedded in a bigger application, root_path resolves to the application root (often an authenticated dashboard, not the docs landing), so readers clicking Home were bounced off the docs entirely, and a site's only recourse was overriding the route helper in its own view layer.

This PR gives the chrome two config-driven homes:

  • Docs home — the masthead link now follows the existing config.brand_href (default "/"), the same knob the topbar and sidebar brand links already use, and is relabeled "← Docs home". A site that already sets c.brand_href = "/docs" gets the fix on upgrade with zero config change.
  • App home — a new opt-in c.app_link = { href:, label: } (default nil → nothing renders). When set, the topbar renders a labeled link back to the hosting app once, right after the brand. Normalized through the existing DocsKit::TopbarLink value object (symbol- or string-keyed Hash, or a TopbarLink); external hrefs open in a new tab with rel=noopener, mirroring DocsUI::TopbarLinks.

Wired into the install path: the generated initializer documents the commented c.app_link example (docs-kit new runs the same generator). README documents both homes.

Backwards compatibility

  • app_link unset → the topbar markup is byte-identical to before.
  • brand_href default "/" → the masthead points exactly where root_path resolved on standalone sites; only the label changes ("← Home" → "← Docs home"), deliberately.
  • Only literal, already-emitted daisyUI class strings — no CSS rebuild or @source change needed.
  • Phlex::Rails::Helpers::Routes stays included in Page — consuming sites call route helpers in #content.
  • Sites that worked around this by overriding root_path in their view layer can delete the override and, if they want the way back, set c.app_link.

Test plan

  • spec/docs_kit/configuration_spec.rbapp_link defaults to nil; Hash (symbol/string keys) normalizes to DocsKit::TopbarLink; an existing TopbarLink passes through.
  • spec/docs_ui/shell_spec.rb — unset → no App Home link; set → labeled anchor after the brand anchor; external href → target="_blank" + noopener; relative href → neither.
  • spec/docs_ui/page_spec.rb#home_href defaults to "/" and follows c.brand_href (child-process harness; Page can't load in the Rails-free suite).
  • spec/generators/install_generator_spec.rb — the generated initializer contains the commented # c.app_link = example.
  • bundle exec rspec: 795 examples, 0 failures, 94.87% line coverage. bundle exec rubocop: clean.

Deviations & judgment calls

  • Judgment call: bundle exec rubocop flagged Metrics/ClassLength on app/components/docs_ui/shell.rb (105/100) after adding the ~10-line #app_home_link method — Shell was already at the limit. Exempted shell.rb in .rubocop.yml alongside landing.rb, whose documented rationale (composite renderer of several sections, each a small focused method) applies verbatim. Alternatives rejected: compressing the method to dodge the metric (hurts readability), extracting a one-link component (over-engineering).

@mhenrixon mhenrixon self-assigned this Aug 2, 2026
@mhenrixon mhenrixon added the enhancement New feature or request label Aug 2, 2026
… topbar link

## Summary
DocsUI::Page's masthead "← Home" hardcoded the host's `root_path` helper — on
a docs site embedded in a bigger app that's the application root (often an
authenticated dashboard), so readers were bounced off the docs, and sites had
to override the route helper to cope. The masthead now follows
`config.brand_href` (the DOCS home, same as the topbar/sidebar brand links),
relabeled "← Docs home". A new opt-in `c.app_link = { href:, label: }`
(default nil → absent) renders the way BACK to the hosting app once, in the
topbar right after the brand; external hrefs open in a new tab with
rel=noopener, mirroring TopbarLinks.

## Test Coverage
- configuration_spec: app_link defaults nil; Hash (symbol/string keys)
  normalizes to DocsKit::TopbarLink; TopbarLink passes through
- shell_spec: unset → topbar unchanged; set → labeled anchor after the brand;
  external → target=_blank + noopener; relative → neither
- page_spec: #home_href defaults "/" and follows c.brand_href (child-process
  harness — Page can't load in the Rails-free suite)
- install_generator_spec: the generated initializer documents the commented
  c.app_link example

## Verification
- [x] bundle exec rubocop passes
- [x] bundle exec rspec passes (795 examples, 94.87% line coverage)

Refs #62
@mhenrixon
mhenrixon force-pushed the issue-62-app-link-docs-home branch from 7eeb15c to 7173abe Compare August 2, 2026 18:37
@mhenrixon
mhenrixon merged commit 0fff22a into main Aug 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two homes: config-driven "← Docs home" masthead link + opt-in App Home topbar link

1 participant