demarches-normaliennes/app/models/concerns/mail_template_concern.rb

38 lines
988 B
Ruby
Raw Normal View History

module MailTemplateConcern
extend ActiveSupport::Concern
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
include TagsSubstitutionConcern
def object_for_dossier(dossier)
replace_tags(object, dossier)
end
def body_for_dossier(dossier)
replace_tags(body, dossier)
end
2018-01-04 16:34:23 +01:00
def tags(is_dossier_termine: self.class.const_get(:IS_DOSSIER_TERMINE))
super
end
module ClassMethods
def default_for_procedure(procedure)
2017-05-27 01:16:38 +02:00
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body, procedure: procedure)
end
end
private
def dossier_tags
2018-01-04 16:34:23 +01:00
super + [{ libelle: 'lien dossier', description: '', lambda: -> (d) { users_dossier_recapitulatif_link(d) } }]
end
def users_dossier_recapitulatif_link(dossier)
url = users_dossier_recapitulatif_url(dossier)
link_to(url, url, target: '_blank')
end
end