Class: Inkcite::Renderer::Like

Inherits:
Base
  • Object
show all
Defined in:
lib/inkcite/renderer/like.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
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
# File 'lib/inkcite/renderer/like.rb', line 5

def render tag, opt, ctx

  # Handle the case where we're building the hosted version of the email and
  # JavaScript is used to trigger the Facebook like dialog.
  if ctx.browser?

    return '{/a}' if tag == '/like'

    page = opt[:page]
    if page.blank?
      ctx.error("Like tag missing 'page' attribute")

    else

      brand = opt[:brand] || 'Us'

      # Add an externally-hosted script to the context.
      ctx.scripts << URI.parse('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')

      # Add the java script to be embedded.
      ctx.scripts << URI.parse('file://facebook-like.js')

      # Add the Facebook like stylesheet.
      ctx.styles << URI.parse('file://facebook-like.css')

      ctx.footer << <<-eos
        <div id="dialog-wrap">
          <div id="dialog">
            <h2>Like #{brand} on Facebook</h2>
            <div id="dialog-content" class='loading'>
              <div class="fb-like" data-href="http://www.facebook.com/#{page}" data-send="true" data-height="100" data-width="450" data-show-faces="true"></div>
            </div>
            <div id="dialog-buttons">
              <a href=# onclick="return closeLike();"><span>Close</span></a>
            </div>
          </div>
        </div>

        <div id="fb-root"></div>
      eos

    end

    '{a href=# onclick="return openLike();"}'

  else

    url = ctx[Inkcite::Email::VIEW_IN_BROWSER_URL]
    unless url.blank?

      return '{/a}' if tag == '/like'

      # Otherwise, link to the hosted version of the email with the like hash tag
      # to trigger like automatically on arrival.
      href = Inkcite::Renderer.render(ctx[Inkcite::Email::VIEW_IN_BROWSER_URL] + '#like', ctx)

      id = opt[:id]

      "{a id=\"#{id}\" href=\"#{href}\"}"
    end

  end

end