Module: EmailTemplateHelper

Extended by:
ActiveSupport::Concern
Defined in:
app/helpers/email_template_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Ok, some madness ahead. There seems to be a bug in rails as documented www.candland.net/2012/04/17/rails-routes-used-in-an-isolated-engine/ where including the URL helpers will cause all other path helpers to go crazy. So instead of include Rails.application.routes.url_helpers we specifically respond to path and url helpers in the method_missing and proxy them up to the main_app if they exist. This way the email helpers in the devise templates will still work.



10
11
12
13
14
15
16
# File 'app/helpers/email_template_helper.rb', line 10

def method_missing(method_name, *args, &block)
  if method_name.to_s.end_with?('_path', '_url')
    main_app.send(method_name, *args)
  else
    super
  end
end

Instance Method Details

#email_message_body_text(&block) ⇒ Object



30
31
32
# File 'app/helpers/email_template_helper.rb', line 30

def email_message_body_text(&block)
  (:span, capture(&block), style: "font-family: Avenir, 'Helvetica Neue', Helvetica, sans-serif; font-size:28px; color:#444444;")
end

#email_message_button(&block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/email_template_helper.rb', line 38

def email_message_button(&block)
  (:table, border: 0, cellpadding: 0, cellspacing: 0, width: '50%', style: 'background-color:#16A086;') do
    (:tr) do
      concat(email_message_spacer(4))
      concat((:td, nil, style: "padding: 18px 20px 18px 20px; font-family:  Avenir, 'Helvetica Neue', Helvetica, sans-serif, sans-serif; color: #ffffff; font-size: 18px; text-align: center;") do
        (:span, capture(&block), style: 'text-decoration: none; color: #ffffff;')
      end)
    end
  end
end

#email_message_section(&block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/email_template_helper.rb', line 49

def email_message_section(&block)
  (:tr) do
    (:td) do
      (:table, border: 0, cellpadding: 0, cellspacing: 0, width: '100%') do
        (:tr) do
          (:td, align: 'center', valign: 'top') do
            (:table, border: 0, cellpadding: 10, cellspacing: 0, width: '100%') do
              (:tr) do
                (:td, capture(&block), align: 'center', valign: 'top')
              end
            end
          end
        end
      end
    end
  end
end

#email_message_small_text(&block) ⇒ Object



34
35
36
# File 'app/helpers/email_template_helper.rb', line 34

def email_message_small_text(&block)
  (:span, capture(&block), style: "font-family: Avenir, 'Helvetica Neue', Helvetica, sans-serif; font-size:22px; color:#444444;")
end

#email_message_spacer(count = 1) ⇒ Object



22
23
24
25
26
27
28
# File 'app/helpers/email_template_helper.rb', line 22

def email_message_spacer(count = 1)
  (1..count).each do
    return capture do
      concat (:br)
    end
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/helpers/email_template_helper.rb', line 18

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('_path', '_url') || super
end