Class: Inkcite::Renderer::Lorem

Inherits:
Base
  • Object
show all
Defined in:
lib/inkcite/renderer/lorem.rb

Constant Summary

Constants inherited from Base

Base::BACKGROUND_COLOR, Base::BACKGROUND_GRADIENT, Base::BACKGROUND_IMAGE, Base::BACKGROUND_POSITION, Base::BACKGROUND_REPEAT, Base::BACKGROUND_SIZE, Base::BORDER_BOTTOM, Base::BORDER_COLLAPSE, Base::BORDER_LEFT, Base::BORDER_RADIUS, Base::BORDER_RIGHT, Base::BORDER_SPACING, Base::BORDER_TOP, Base::BOX_SHADOW, Base::DIMENSIONS, Base::DIRECTIONS, Base::FONT_FAMILY, Base::FONT_SIZE, Base::FONT_WEIGHT, Base::LETTER_SPACING, Base::LINE_HEIGHT, Base::LINK_COLOR, Base::MARGIN, Base::MARGIN_BOTTOM, Base::MARGIN_LEFT, Base::MARGIN_RIGHT, Base::MARGIN_TOP, Base::MAX_WIDTH, Base::NONE, Base::PADDING_X, Base::PADDING_Y, Base::POUND_SIGN, Base::TEXT_ALIGN, Base::TEXT_DECORATION, Base::TEXT_SHADOW, Base::TEXT_SHADOW_BLUR, Base::TEXT_SHADOW_OFFSET, Base::VERTICAL_ALIGN, Base::WEBKIT_ANIMATION, Base::WHITE_SPACE, Base::ZERO_WIDTH_NON_BREAKING_SPACE, Base::ZERO_WIDTH_SPACE

Instance Method Summary collapse

Instance Method Details

#render(tag, opt, ctx) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/inkcite/renderer/lorem.rb', line 5

def render tag, opt, ctx

  # Lazy load only if Lorem is used in the email.
  require 'faker'

  type = (opt[:type] || :sentences).to_sym

  # Get the limit (e.g. the number of sentences )
  limit = opt[:sentences] || opt[:size] || opt[:limit] || opt[:count]

  # Always warn the creator that there is Lorem Ipsum in the email because
  # we don't want it to ship accidentally.
  ctx.error 'Email contains Lorem Ipsum' unless opt[:force]

  html = if type == :headline
    words = (limit || 4).to_i
    Faker::Lorem.words(words).join(SPACE).titlecase

  elsif type == :words
    words = (limit || 7).to_i
    Faker::Lorem.words(words).join(SPACE)

  else
    sentences = (limit || 3).to_i
    Faker::Lorem.sentences(sentences).join(SPACE)

  end

  # Replace the last space in the generated text with a
  # non-breaking space so that the last two words always
  # wrap together - no dangling words in rapid design mode.
  if last_space = html.rindex(' ')
    html[last_space] = ' '
  end

  html
end