Sha256: ec931b6c4b7967f96a250954b9b1213b9d06a893e9eeb3d107f2e75a7b5803cf

Contents?: true

Size: 1.5 KB

Versions: 11

Compression:

Stored size: 1.5 KB

Contents

require 'uri'

module MailSpy
  module EmailHelper

    # Support for link clicks.
    def track_link(*args, &block)
      @_track_count ||= 0
      if block_given?
        options = args.first || {}
        html_options = args.second
        track_link(capture(&block), options, html_options)
      else
        @_track_count += 1
        name = args[0]
        options = args[1] || {}
        html_options = args[2]

        html_options = convert_options_to_data_attributes(options, html_options)
        url = url_for(options)

        href = html_options['href']
        tag_options = tag_options(html_options)

        # Inject our tracking url, and pass in the redirect_url

        hash = {
          :controller => "mail_spy/tracking",
          :action => :link,
          :url => url,
          :only_path => false,
          :host => MailSpy.tracker_host,
          :n => @_track_count,
          :eid => @_email.id
        }

        url = url_for(hash)

        href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
        "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
      end
    end


    # Support for open tracking, client support, etc
    def tracking_bug
      url = url_for(
        :controller => "mail_spy/tracking",
        :action => :bug,
        :eid => @_email.id,
        :only_path => false,
        :host => MailSpy.tracker_host
      )
      "<img src='#{url}' style='display:none' width='1' height='1' border='0' />".html_safe
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mail_spy-0.1.1 app/helpers/mail_spy/email_helper.rb
mail_spy-0.1.0 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.18 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.17 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.16 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.15 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.14 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.13 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.12 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.11 app/helpers/mail_spy/email_helper.rb
mail_spy-0.0.10 app/helpers/mail_spy/email_helper.rb