Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Rosenögger <123haynes@gmail.com>2015-03-04 14:58:40 +0300
committerHannes Rosenögger <123haynes@gmail.com>2015-03-12 11:26:06 +0300
commit3c7e0f45c2d9c242bf45d153bb73e96ce7525a06 (patch)
treea905c2a07656dcb1e287b4bdf47b3b118bc36017 /app/helpers/emails_helper.rb
parent3f823068e1f6e3e88d6631de60d9aaf9ecd5e6f9 (diff)
replace images in emails with inline images
This adds the functionality of replacing all images that were uploaded to gitlab with inline images(base64) in emails. This change fixes the broken images in emails that 7.8 introduced
Diffstat (limited to 'app/helpers/emails_helper.rb')
-rw-r--r--app/helpers/emails_helper.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/helpers/emails_helper.rb b/app/helpers/emails_helper.rb
index 92cc9c426b8..08476f8516e 100644
--- a/app/helpers/emails_helper.rb
+++ b/app/helpers/emails_helper.rb
@@ -1,3 +1,6 @@
+require 'html/pipeline'
+require 'html/pipeline/gitlab'
+
module EmailsHelper
# Google Actions
@@ -39,4 +42,26 @@ module EmailsHelper
lexer = Rugments::Lexers::Diff.new
raw formatter.format(lexer.lex(diffcontent))
end
+
+ def replace_image_links_with_base64(text, project)
+ # Used pipelines in GitLab:
+ # GitlabEmailImageFilter - replaces images that have been uploaded as attachments with inline images in emails.
+ #
+ # see https://gitlab.com/gitlab-org/html-pipeline-gitlab for more filters
+ filters = [
+ HTML::Pipeline::Gitlab::GitlabEmailImageFilter
+ ]
+
+ context = {
+ base_url: File.join(Gitlab.config.gitlab.url, project.path_with_namespace, 'uploads'),
+ upload_path: File.join(Rails.root, 'public', 'uploads', project.path_with_namespace),
+ }
+
+ pipeline = HTML::Pipeline::Gitlab.new(filters).pipeline
+
+ result = pipeline.call(text, context)
+ text = result[:output].to_html(save_with: 0)
+
+ text.html_safe
+ end
end