demarches-normaliennes/app/services/mail_template_presenter_service.rb

24 lines
732 B
Ruby
Raw Normal View History

class MailTemplatePresenterService
include ActionView::Helpers::SanitizeHelper
include ActionView::Helpers::TextHelper
def self.create_commentaire_for_state(dossier, state)
service = new(dossier, state)
body = ["<p>[#{service.safe_subject}]</p>", service.safe_body].join('')
CommentaireService.create!(CONTACT_EMAIL, dossier, body: body)
end
def safe_body
sanitize(@email_template.body_for_dossier(@dossier), scrubber: Sanitizers::MailScrubber.new)
end
def safe_subject
Nokogiri::HTML.parse(truncate(@email_template.subject_for_dossier(@dossier), length: 100)).text
end
def initialize(dossier, state)
@dossier = dossier
@email_template = dossier.email_template_for(state)
end
end