Class: LucidMail
- Inherits:
-
Object
- Object
- LucidMail
- Extended by:
- LucidPropDeclaration::Mixin
- Includes:
- Isomorfeus::PreactViewHelper
- Defined in:
- lib/lucid_mail.rb
Instance Attribute Summary collapse
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#rendered_component ⇒ Object
readonly
Returns the value of attribute rendered_component.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(**props) ⇒ LucidMail
constructor
A new instance of LucidMail.
- #render_component ⇒ Object
- #send ⇒ Object
Constructor Details
#initialize(**props) ⇒ LucidMail
Returns a new instance of LucidMail.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lucid_mail.rb', line 17 def initialize(**props) @props = LucidProps.new(self.class.validated_props(props)) @mail = nil @rendered_component = nil @loc_h = if self.class.const_defined?('::Isomorfeus::Puppetmaster') "#{::Isomorfeus::Puppetmaster.served_app.host}:#{::Isomorfeus::Puppetmaster.served_app.port}" elsif self.class.const_defined?('::Iodine') host = ::Iodine::DEFAULT_SETTINGS[:address] host = 'localhost' unless host "#{host}:#{::Iodine::DEFAULT_SETTINGS[:port]}" else 'localhost:3000' end end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
13 14 15 |
# File 'lib/lucid_mail.rb', line 13 def mail @mail end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
14 15 16 |
# File 'lib/lucid_mail.rb', line 14 def props @props end |
#rendered_component ⇒ Object (readonly)
Returns the value of attribute rendered_component.
15 16 17 |
# File 'lib/lucid_mail.rb', line 15 def rendered_component @rendered_component end |
Instance Method Details
#build ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lucid_mail.rb', line 42 def build render_component unless rendered_component html_body = rendered_component text_body = Html2Text.convert(rendered_component) @mail = Mail.new @mail.to(props.to) @mail.from(props.from) @mail.subject(props.subject) @mail.reply_to(props.reply_to) if props.key?(:reply_to) @mail.text_part do content_type 'text/plain; charset=UTF-8' body text_body end @mail.html_part do content_transfer_encoding 'binary' content_type 'text/html; charset=UTF-8' body html_body end self end |
#render_component ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/lucid_mail.rb', line 32 def render_component component_props = { location_host: @loc_h }.merge(props.props) rendered_tree = mount_component(props.component, component_props, props.asset, use_ssr: true) @rendered_component = <<~HTML <!DOCTYPE html> <html><head><style type="text/css">#{ssr_styles}</style></head><body>#{rendered_tree}</body></html> HTML self end |
#send ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/lucid_mail.rb', line 63 def send s = Time.now STDERR.puts "m #{s}" build unless mail STDERR.puts "mr #{Time.now - s}" r = Isomorfeus.email_sender.send_email(mail) STDERR.puts "ms #{Time.now - s}" r end |