Module: AlchemyCrm::MailingsHelper
- Includes:
- Alchemy::PagesHelper
- Defined in:
- app/helpers/alchemy_crm/mailings_helper.rb
Instance Method Summary collapse
- #current_host ⇒ Object
- #current_language ⇒ Object
- #current_server ⇒ Object
-
#image_from_server_tag(image, html_options = {}) ⇒ Object
Use this helper to render an image from your server.
-
#link_to_unsubscribe_page(html_options = {}) ⇒ Object
Renders a link to the unsubscribe page.
-
#read_in_browser_notice(html_options = {}) ⇒ Object
Renders a notice to open the mailing inside a browser, if it does not displays correctly.
-
#render_newsletter_layout(options = {}) ⇒ Object
Renders the newsletter layout for @mailing.page.
-
#render_tracking_image ⇒ Object
Renders the tracking image that records the receivement of the mailing inside the mail client.
-
#tracked_link_tag(*args) ⇒ Object
Renders a link that tracks the reaction of a recipient.
-
#tracked_url_for(redirect_url) ⇒ Object
Returns the url for tracking a link that’s clicked inside a mailing.
-
#url_for_unsubscribe_page ⇒ Object
Returns the url for the unsubscribe page.
Instance Method Details
#current_host ⇒ Object
158 159 160 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 158 def current_host (defined?(request)).nil? || request.nil? ? @options[:host] : request.host end |
#current_language ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 180 def current_language return @language if @language if @options && @options[:language_id] @language = Alchemy::Language.find(@options[:language_id]) else @language = Alchemy::Language.get_default end end |
#current_server ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 162 def current_server if (defined?(request)).nil? || request.nil? protocol = @options.nil? || @options[:protocol].blank? ? 'http://' : @options[:protocol] else protocol = request.protocol end if (defined?(request)).nil? || request.nil? if @options port = @options[:port] && @options[:port] != 80 ? @options[:port] : nil else port = nil end else port = request.port != 80 ? request.port : nil end [protocol, current_host, port ? ":#{port}" : nil].compact.join end |
#image_from_server_tag(image, html_options = {}) ⇒ Object
Use this helper to render an image from your server.
The notice and the link inside are translated via I18n.
Example:
<%= image_from_server_tag('logo.png', :alt => 'Logo', :width => 230, :height => 116, :style => 'outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;') %>
=> <img src="http://example.com/assets/logo.png"
Options:
[Hash] # Passed to the image_tag helper.
125 126 127 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 125 def image_from_server_tag(image, ={}) image_tag([current_server, Rails.application.config.assets.prefix, image].join('/'), ) end |
#link_to_unsubscribe_page(html_options = {}) ⇒ Object
Renders a link to the unsubscribe page.
Please notice that you have to create a page with a newsletter_signout
page layout and this page has to be public.
The text inside the link is translated.
Example translation:
de:
alchemy_crm:
unsubscribe: 'abmelden'
Options:
[Hash] # Passed to the link. Useful for styling the link with inline css.
You can pass an optional block thats gets passed to link_to
52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 52 def link_to_unsubscribe_page(={}) text = ::I18n.t(:unsubscribe, :scope => :alchemy_crm) if block_given? link_to(url_for_unsubscribe_page, ) do yield end else link_to(text, url_for_unsubscribe_page, ) end end |
#read_in_browser_notice(html_options = {}) ⇒ Object
Renders a notice to open the mailing inside a browser, if it does not displays correctly.
The notice and the link inside are translated via I18n.
Example translation:
de:
alchemy_crm:
here: 'hier'
read_in_browser_notice: "Falls der Newsletter nicht richtig dargestellt wird, klicken Sie bitte %{link}."
Options:
[Hash] # Passed to the link. Useful for styling the link with inline css.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 94 def read_in_browser_notice( = {}) return "" if @recipient.nil? ::I18n.t( :read_in_browser_notice, :link => link_to( ::I18n.t(:here, :scope => :alchemy_crm), alchemy_crm.show_mailing_url( :m => @mailing.sha1, :r => @recipient.sha1, :host => current_host ), , :host => current_host ), :scope => :alchemy_crm ).html_safe end |
#render_newsletter_layout(options = {}) ⇒ Object
Renders the newsletter layout for @mailing.page
The @mailing.page.page_layout must have a newsletter_layout
prefix. The partial itself is named without the newsletter_layout
prefix. The partial resists in /app/views/newsletter_layouts/
Example:
Given a mailing page with a standard
layout has partials named _standard.html.erb
and _standard.text.erb
But the page page_layout attribute is newsletter_layout_standard
17 18 19 20 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 17 def (={}) = {:format => 'html'}.update() render "alchemy/newsletter_layouts/#{@page.page_layout.downcase.gsub(Regexp.new(Mailing::MAILING_PAGE_LAYOUT_PREFIX), '')}.#{[:format]}.erb" end |
#render_tracking_image ⇒ Object
Renders the tracking image that records the receivement of the mailing inside the mail client.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 23 def render_tracking_image return "" if @preview_mode || @recipient.nil? image_tag( alchemy_crm.recipient_reads_url(:h => @recipient.sha1, :host => current_host), :style => "width: 0; height: 0; display: none", :width => 0, :height => 0, :alt => '' ) end |
#tracked_link_tag(*args) ⇒ Object
Renders a link that tracks the reaction of a recipient.
After getting tracked the controller redirects to the url passed in.
It has the same arguments that the Rails link_to
helper has.
Example:
<%= tracked_link_tag('read more', :r => 'http://example.com/my-article', :style => 'color: black') %>
=> <a href="http://example.com/recipient/s3cr3tSh41/reacts?r=http%3A%2F%2Fexample.com%2Fmy-article" style="color: black">
NOTE: You can even pass a block like you could for link_to
helper from Rails.
142 143 144 145 146 147 148 149 150 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 142 def tracked_link_tag(*args) if block_given? link_to(tracked_url_for(args.first), args.last) do yield end else link_to(args.first, tracked_url_for(args[1]), args.last) end end |
#tracked_url_for(redirect_url) ⇒ Object
Returns the url for tracking a link that’s clicked inside a mailing. Used by tracked_link_tag
helper and plain text mailing views.
154 155 156 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 154 def tracked_url_for(redirect_url) alchemy_crm.recipient_reacts_url(:h => @recipient.sha1, :r => redirect_url, :host => current_host) end |
#url_for_unsubscribe_page ⇒ Object
Returns the url for the unsubscribe page. Used by link_to_unsubscribe_page
helper and inside of plain text views of mailings.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/alchemy_crm/mailings_helper.rb', line 65 def url_for_unsubscribe_page unsubscribe_page = Alchemy::Page.find_by_page_layout('newsletter_signout') if unsubscribe_page.nil? raise('Newsletter Signout Page Could Not Be Found. Please create one!') else alchemy.show_page_url( :urlname => unsubscribe_page.urlname, :lang => multi_language? ? unsubscribe_page.language_code : nil, :email => @contact ? @contact.email : nil, :host => current_host ) end end |