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.

Constant Summary

Constants inherited from Base

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)


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

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?

  background = ActiveMail.tokens.color!(class?(node, 'secondary') ? :secondary : :primary)
  classes = combine_classes(node, 'cta')
  anchor = %(<a href="#{escape_attr(node.attr('href'))}"#{target_attribute(node)} style="#{link_style(background)}">#{inner}</a>)
  [
    %(<table class="#{classes}" #{TABLE_RESET}><tbody><tr><td>),
    %(<table #{TABLE_RESET}><tbody><tr><td style="background:#{background};border-radius:4px;">),
    "#{anchor}</td></tr></tbody></table></td></tr></tbody></table>"
  ].join
end