Class: DocsKit::LandingConfig::Cta

Inherits:
Data
  • Object
show all
Defined in:
lib/docs_kit/landing_config.rb

Overview

One hero call-to-action button. style maps to a daisyUI btn variant (:primary → btn-primary, anything else → btn-ghost). icon is an optional brand/lucide token rendered before the label (DocsUI::BrandMark resolves it).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, href:, style: :ghost, icon: nil) ⇒ Cta

Returns a new instance of Cta.



106
107
108
# File 'lib/docs_kit/landing_config.rb', line 106

def initialize(label:, href:, style: :ghost, icon: nil)
  super(label:, href:, style: style&.to_sym, icon: icon)
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href

Returns:

  • (Object)

    the current value of href



105
106
107
# File 'lib/docs_kit/landing_config.rb', line 105

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon

Returns:

  • (Object)

    the current value of icon



105
106
107
# File 'lib/docs_kit/landing_config.rb', line 105

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



105
106
107
# File 'lib/docs_kit/landing_config.rb', line 105

def label
  @label
end

#styleObject (readonly)

Returns the value of attribute style

Returns:

  • (Object)

    the current value of style



105
106
107
# File 'lib/docs_kit/landing_config.rb', line 105

def style
  @style
end

Class Method Details

.from(cta) ⇒ Object



110
111
112
113
114
115
# File 'lib/docs_kit/landing_config.rb', line 110

def self.from(cta)
  return cta if cta.is_a?(self)

  attrs = cta.to_h.transform_keys(&:to_sym)
  new(label: attrs[:label], href: attrs[:href], style: attrs[:style] || :ghost, icon: attrs[:icon])
end

Instance Method Details

#btn_classObject

The daisyUI button class for this CTA's style.



118
# File 'lib/docs_kit/landing_config.rb', line 118

def btn_class = style == :primary ? "btn btn-primary" : "btn btn-ghost"

#external?Boolean

Whether the href points off-site (absolute http/https) — the component adds target=_blank + rel=noopener only for external links.

Returns:

  • (Boolean)


122
# File 'lib/docs_kit/landing_config.rb', line 122

def external? = href.to_s.match?(%r{\Ahttps?://}i)