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.



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

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



103
104
105
# File 'lib/docs_kit/landing_config.rb', line 103

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon

Returns:

  • (Object)

    the current value of icon



103
104
105
# File 'lib/docs_kit/landing_config.rb', line 103

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



103
104
105
# File 'lib/docs_kit/landing_config.rb', line 103

def label
  @label
end

#styleObject (readonly)

Returns the value of attribute style

Returns:

  • (Object)

    the current value of style



103
104
105
# File 'lib/docs_kit/landing_config.rb', line 103

def style
  @style
end

Class Method Details

.from(cta) ⇒ Object



108
109
110
111
112
113
# File 'lib/docs_kit/landing_config.rb', line 108

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.



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

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)


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

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