Class: DocsKit::TopbarLink
- Inherits:
-
Data
- Object
- Data
- DocsKit::TopbarLink
- Defined in:
- lib/docs_kit/topbar_link.rb
Overview
A single external link rendered in the topbar next to the theme switcher — a repo link, a chat invite, a social profile. Sites declare these in config as plain Hashes; #topbar_links normalizes each into a TopbarLink so the Shell stays value-object-driven (like DocsKit::NavItem for the sidebar):
c. = [
{ href: "https://github.com/me/repo", label: "GitHub", icon: :github },
{ href: "https://discord.gg/abc", label: "Discord", icon: :discord },
]
The Shell renders each as an icon-only ghost button; #label is the accessible name (aria-label + title). #icon is a token DocsUI::BrandMark resolves — a shipped brand mark (:github, :discord, …) or, failing that, a lucide icon name (any string DocsUI::Icon knows). nil #icon renders the label as text.
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Class Method Summary collapse
-
.from(link) ⇒ Object
Build a TopbarLink from a Hash (symbol- OR string-keyed, so a YAML/JSON config loads cleanly) or pass an existing TopbarLink through unchanged.
Instance Method Summary collapse
-
#external? ⇒ Boolean
Whether the href points off-site (absolute http/https).
-
#initialize(href:, label:, icon: nil) ⇒ TopbarLink
constructor
A new instance of TopbarLink.
Constructor Details
#initialize(href:, label:, icon: nil) ⇒ TopbarLink
Returns a new instance of TopbarLink.
19 20 21 |
# File 'lib/docs_kit/topbar_link.rb', line 19 def initialize(href:, label:, icon: nil) super(href:, label:, icon: icon&.to_sym) end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href
18 19 20 |
# File 'lib/docs_kit/topbar_link.rb', line 18 def href @href end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon
18 19 20 |
# File 'lib/docs_kit/topbar_link.rb', line 18 def icon @icon end |
#label ⇒ Object (readonly)
Returns the value of attribute label
18 19 20 |
# File 'lib/docs_kit/topbar_link.rb', line 18 def label @label end |
Class Method Details
.from(link) ⇒ Object
Build a TopbarLink from a Hash (symbol- OR string-keyed, so a YAML/JSON config loads cleanly) or pass an existing TopbarLink through unchanged.
25 26 27 28 29 30 |
# File 'lib/docs_kit/topbar_link.rb', line 25 def self.from(link) return link if link.is_a?(self) attrs = link.to_h.transform_keys(&:to_sym) new(href: attrs[:href], label: attrs[:label], icon: attrs[:icon]) end |
Instance Method Details
#external? ⇒ Boolean
Whether the href points off-site (absolute http/https). The Shell adds target=_blank + rel=noopener only for external links; a site-relative link (e.g. "/changelog") opens in place like any nav link.
35 36 37 |
# File 'lib/docs_kit/topbar_link.rb', line 35 def external? href.to_s.match?(%r{\Ahttps?://}i) end |