Last active
March 23, 2019 19:25
-
-
Save raeno/4eb3905cabf66c22297669c47a56ff26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= content_for :sender | |
= @store.name | |
= content_for :branding | |
= render 'layouts/front/store_branding', store: @store | |
= content_for :excuse | |
= t 'review_request_html', | |
scope: 'front.mailer.excuses', | |
helpfulcrowd: link_to('HelpfulCrowd', 'https://www.helpfulcrowd.com'), | |
store: "<b>#{ @store.name }</b>".html_safe | |
== @presenter.parsed_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReviewRequestBodyPresenter < TemplatePresenter | |
def initialize(review_request, store) | |
@store = store | |
@review_request | |
end | |
def parsed_template | |
parse_template template, safe, paragraphize | |
end | |
private | |
def template | |
@store.settings(:reviews).review_request_mail_body | |
end | |
def supported_placeholders | |
[:customer_name, :store_url] | |
end | |
def customer_name | |
@review_request.customer.name | |
end | |
def store_url | |
@store.url | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TemplatePresenter | |
def supported_placeholders | |
[] | |
end | |
def template | |
'' | |
end | |
protected | |
def parse_template(safe, paragraphize) | |
template = CGI::escape_html(template) unless safe | |
template = template.paragraphize if paragraphize | |
supported_placeholders.select{ |x| template.include?("[#{x }]") }.each do |key| | |
replacement = send(key) | |
has_tags = ["<table>", "<div>", "<p>"].any? { |tag| replacement.include?(tag) } | |
template = template.gsub("<p>[#{ key }]</p>", replacement) if has_tags && template.include?("<p>[#{ key }]</p>") | |
template = template.gsub("[#{ key }]", replacement) | |
end | |
template | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment