Module: Leftbrained::HasWebFallback::InstanceMethods

Defined in:
lib/leftbrained/has_web_fallback.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#deliver!(mail = @mail) ⇒ Object

After delivering any mail, pop a version out to the file system



150
151
152
153
154
# File 'lib/leftbrained/has_web_fallback.rb', line 150

def deliver!(mail=@mail)
  super(mail)
  write_web_fallback if has_web_fallback?
  mail
end

#has_html_part?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/leftbrained/has_web_fallback.rb', line 140

def has_html_part?
  !!mail.parts.find{ |part| 'text/html' == part.content_type }
end

#has_web_fallback?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/leftbrained/has_web_fallback.rb', line 121

def has_web_fallback?
  self.class.has_web_fallback? @action_name
end

#html_partObject



144
145
146
# File 'lib/leftbrained/has_web_fallback.rb', line 144

def html_part
  mail.parts.find{ |part| 'text/html' == part.content_type }.body
end

#render_message(method_name, body) ⇒ Object

If this method needs a fallback version set an instance variable in the template so we can actually tell the user what the URL will be.



127
128
129
130
# File 'lib/leftbrained/has_web_fallback.rb', line 127

def render_message(method_name, body)
  body[:web_fallback_url] = web_fallback_url if has_web_fallback?
  super
end

#web_fallback_pathObject



117
118
119
# File 'lib/leftbrained/has_web_fallback.rb', line 117

def web_fallback_path
  File.join(self.class.path_for_web_fallback(@action_name), web_fallback_uuid)
end

#web_fallback_urlObject



113
114
115
# File 'lib/leftbrained/has_web_fallback.rb', line 113

def web_fallback_url
  File.join(self.class.url_for_web_fallback(@action_name), web_fallback_uuid)
end

#web_fallback_uuidObject



109
110
111
# File 'lib/leftbrained/has_web_fallback.rb', line 109

def web_fallback_uuid
  @web_fallback_uuid ||= self.class.web_fallback_uuid_for(@action_name)
end

#write_web_fallbackObject



132
133
134
135
136
137
138
# File 'lib/leftbrained/has_web_fallback.rb', line 132

def write_web_fallback
  return unless has_html_part?
  FileUtils.mkdir_p(File.dirname(web_fallback_path))
  f = File.new(web_fallback_path, 'w')
  f.puts(html_part)
  f.close
end