Class: BootstrapEmail::Converter::PreviewText

Inherits:
Base
  • Object
show all
Defined in:
lib/bootstrap-email/converters/preview_text.rb

Instance Attribute Summary

Attributes inherited from Base

#doc

Instance Method Summary collapse

Methods inherited from Base

build, #initialize

Constructor Details

This class inherits a constructor from BootstrapEmail::Converter::Base

Instance Method Details

#buildObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bootstrap-email/converters/preview_text.rb', line 6

def build
  preview_node = doc.at_css('preview')
  return if preview_node.nil?

  # https://www.litmus.com/blog/the-little-known-preview-text-hack-you-may-want-to-use-in-every-email/
  # apply spacing after the text max of 278 characters so it doesn't show body text
  preview_node.inner_html += '͏ ‌   ' * [(278 - preview_node.content.length.to_i), 0].max
  node = template('div', classes: 'preview', contents: preview_node.content)
  preview_node.remove

  body = doc.at_css('body')
  body.prepend_child(node)
end