Class: Sendmark::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/sendmark/mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}, &block) ⇒ Mail

Returns a new instance of Mail.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sendmark/mail.rb', line 21

def initialize(args = {}, &block)
  args.each do |k, v|
    setter = "#{k}="
    send(setter, v) if respond_to?(setter)
  end

  if block_given?
    instance_eval(&block)
  end

  unless css.nil?
    @css_parser = CssParser.new
    @css_parser.load_string! css
  end
end

Instance Attribute Details

#css_parserObject (readonly)

Returns the value of attribute css_parser.



3
4
5
# File 'lib/sendmark/mail.rb', line 3

def css_parser
  @css_parser
end

Instance Method Details

#deliverObject



43
44
45
46
47
# File 'lib/sendmark/mail.rb', line 43

def deliver
  delivery_mail = mail
  delivery_mail.delivery_method(@method, @settings)
  delivery_mail.deliver
end

#delivery_method(method, settings = {}) ⇒ Object



37
38
39
40
41
# File 'lib/sendmark/mail.rb', line 37

def delivery_method(method, settings = {})
  @method = method
  @settings = settings
  self
end

#mailObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sendmark/mail.rb', line 49

def mail
  html = rendered_html
  mail = ::Mail.new(to: to, from: from, subject: subject)

  html_part = ::Mail::Part.new do
    content_type "text/html; charset=UTF-8"
    body html
  end

  mail.html_part = html_part
  mail
end

#rendered_htmlObject



62
63
64
65
66
# File 'lib/sendmark/mail.rb', line 62

def rendered_html
  render = Markdown.new(@css_parser)
  text = @markdown.nil? ? "" : @markdown
  render.render(text)
end