Class: ActiveMail::Core
Constant Summary collapse
- INTERIM_TH_TAG =
Nokogiri cannot parse a bare <th> outside a <tr>; components that emit <th> use this placeholder, swapped back at the end.
'activemail-interim-th'- INTERIM_TH_TAG_REGEX =
T.let(%r{(?<=<|</)#{Regexp.escape(INTERIM_TH_TAG)}}, Regexp)
- DEFAULT_COMPONENTS =
T.let( { 'button' => ActiveMail::Components::Button, 'row' => ActiveMail::Components::Row, 'columns' => ActiveMail::Components::Columns, 'container' => ActiveMail::Components::Container, 'inky' => ActiveMail::Components::Inky, 'block-grid' => ActiveMail::Components::BlockGrid, 'menu' => ActiveMail::Components::Menu, 'item' => ActiveMail::Components::MenuItem, 'center' => ActiveMail::Components::Center, 'callout' => ActiveMail::Components::Callout, 'spacer' => ActiveMail::Components::Spacer, 'h-line' => ActiveMail::Components::HLine, 'wrapper' => ActiveMail::Components::Wrapper }.freeze, ActiveMail::ComponentMap )
Instance Attribute Summary collapse
-
#column_count ⇒ Object
readonly
Returns the value of attribute column_count.
-
#container_width ⇒ Object
readonly
Returns the value of attribute container_width.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Core
constructor
A new instance of Core.
- #release_the_kraken(html_string) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Core
Returns a new instance of Core.
65 66 67 68 69 70 |
# File 'lib/activemail.rb', line 65 def initialize( = {}) config = ::ActiveMail.configuration @component_instances = T.let(build_components(config, [:components]), T::Hash[String, ActiveMail::Components::Base]) @column_count = T.let(ActiveMail.assert_positive_dimension!(:column_count, [:column_count] || config.column_count), Integer) @container_width = T.let(ActiveMail.assert_positive_dimension!(:container_width, [:container_width] || config.container_width), Integer) end |
Instance Attribute Details
#column_count ⇒ Object (readonly)
Returns the value of attribute column_count.
59 60 61 |
# File 'lib/activemail.rb', line 59 def column_count @column_count end |
#container_width ⇒ Object (readonly)
Returns the value of attribute container_width.
59 60 61 |
# File 'lib/activemail.rb', line 59 def container_width @container_width end |
Instance Method Details
#release_the_kraken(html_string) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/activemail.rb', line 74 def release_the_kraken(html_string) raws, str = extract_raws(normalize_input(html_string)) parse_cmd = ::ActiveMail.full_document?(str) ? :parse : :fragment html = Nokogiri::HTML.public_send(parse_cmd, str) ParseErrorReporter.new(component_instances.keys).call(html.errors) transform_doc(html) string = html.to_html string = string.gsub(INTERIM_TH_TAG_REGEX, 'th') # Needle is a literal U+00A0 (Nokogiri decodes the nbsp entity to one); re-encode # it to the entity for email clients that mishandle raw NBSP bytes. string = string.gsub(' ', ' ') re_inject_raws(string, raws) end |