Class: Inkcite::Renderer::LitmusAnalytics

Inherits:
Base
  • Object
show all
Defined in:
lib/inkcite/renderer/litmus_analytics.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



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/inkcite/renderer/litmus_analytics.rb', line 7

def render tag, opt, ctx

  # Litmus tracking is enabled only for production emails.
  return nil unless ctx.production? && ctx.email?

  # Deprecated code/id parameters.  They shouldn't be passed anymore.
  report_id = opt[:code] || opt[:id]
  merge_tag = opt[MERGE_TAG] || ctx[MERGE_TAG]

  # Initialize the Litmus API.
  config = ctx.config[:litmus]
  Litmus::Base.new(config[:subdomain], config[:username], config[:password], true)

  # Will hold the Litmus Report object from which we'll retrieve the
  # bug HTML to inject into the email.
  report = nil

  # If no code has been provided by the designer, check to see
  # if one has been previously recorded for this version.  If
  # so, use it - otherwise, require one from litmus automatically.
  if report_id.blank?

    # Check to see if a campaign has been previously created for this
    # version so the ID can be reused.
    report_id = ctx.meta(:litmus_report_id)
    if report_id.blank?

      # Create a new report object using the title of the email specified
      # in the helpers file.
      report = Litmus::Report.create(ctx.title)

      # Retrieve the unique ID assigned by Litmus and then stuff it
      # into the meta data so we don't create a new one on future
      # builds.
      report_id = report['id']
      ctx.set_meta :litmus_report_id, report_id

    end

  end

  if report.nil?

    report = Litmus::Report.show(report_id)
    if report.nil?
      ctx.error 'Invalid Litmus Analytics code or id', :code => report_id
      return nil
    end

  end

  # Grab the HTML from Litmus that needs to be injected into the source
  # of the email.
  bug_html = report[BUG_HTML]

  # Replace the merge tag, if one was provided.
  bug_html.gsub!('[UNIQUE]', merge_tag) unless merge_tag.nil?

  # Inject HTML into the footer of the email where it won't be subject
  # to inline'n or compression.
  ctx.footer << bug_html

  nil
end