Class: ActiveMail::Components::Cta

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activemail/components/cta.rb

Overview

Colors read from tokens at transform time (runtime config), not load-time constants. Styles are inlined so the button survives clients that strip <style> (Gmail mobile…).

Constant Summary

Constants inherited from Base

Base::BUTTON_PADDING, Base::IGNORED_ON_PASSTHROUGH, Base::TABLE_RESET

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ActiveMail::Components::Base

Instance Method Details

#transform(node, inner) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/activemail/components/cta.rb', line 14

def transform(node, inner)
  # A CTA without a link is an authoring bug — surface it at render time.
  raise ArgumentError, '<cta> requires an href attribute' if node.attr('href').to_s.strip.empty?

  style = ActiveMail.tokens.button_style(class?(node, 'secondary') ? :secondary : :primary)
  anchor = %(<a href="#{escape_attr(node.attr('href'))}"#{target_attribute(node)} ) +
           %(style="#{link_style(style)}">#{inner}</a>)
  bulletproof_button_table(
    outer_classes: combine_classes(node, 'cta'),
    inner: anchor,
    cell_style: cell_style(style)
  )
end