diff options
author | Hannes Rosenögger <123haynes@gmail.com> | 2015-03-04 12:58:40 +0100 |
---|---|---|
committer | Hannes Rosenögger <123haynes@gmail.com> | 2015-03-12 09:26:06 +0100 |
commit | 3c7e0f45c2d9c242bf45d153bb73e96ce7525a06 (patch) | |
tree | a905c2a07656dcb1e287b4bdf47b3b118bc36017 /app/helpers/emails_helper.rb | |
parent | 3f823068e1f6e3e88d6631de60d9aaf9ecd5e6f9 (diff) | |
download | gitlab-ce-3c7e0f45c2d9c242bf45d153bb73e96ce7525a06.tar.gz |
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.rb | 25 |
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 |