From e460e04e16abe5409b2e4918016a29b0415790ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Rosen=C3=B6gger?= <123haynes@gmail.com> Date: Fri, 16 Jan 2015 14:38:53 +0100 Subject: Add Diff syntax colors for email-on-push notifications --- CHANGELOG | 2 +- app/helpers/emails_helper.rb | 10 ++++++++++ app/views/layouts/notify.html.haml | 2 +- app/views/notify/repository_push_email.html.haml | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 387d42a7aca..166c6d3bbbf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,7 +5,7 @@ v 7.8.0 - - - - - + - Add diff syntax highlighting in email-on-push service notifications (Hannes Rosenögger) - - - diff --git a/app/helpers/emails_helper.rb b/app/helpers/emails_helper.rb index 24d67c21d6b..b336263049c 100644 --- a/app/helpers/emails_helper.rb +++ b/app/helpers/emails_helper.rb @@ -29,4 +29,14 @@ module EmailsHelper end end end + + def add_email_highlight_css + Rugments::Themes::Github.render(:scope => '.highlight') + end + + def color_email_diff(diffcontent) + formatter = Rugments::Formatters::HTML.new(cssclass: 'highlight') + lexer = Rugments::Lexers::Diff.new + raw formatter.format(lexer.lex(diffcontent)) + end end diff --git a/app/views/layouts/notify.html.haml b/app/views/layouts/notify.html.haml index e81cf9e5bf6..a722db2f32c 100644 --- a/app/views/layouts/notify.html.haml +++ b/app/views/layouts/notify.html.haml @@ -16,7 +16,7 @@ font-size:small; color:#777 } - + #{add_email_highlight_css} %body %div.content = yield diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml index d678147ec5d..b6fe445867c 100644 --- a/app/views/notify/repository_push_email.html.haml +++ b/app/views/notify/repository_push_email.html.haml @@ -23,7 +23,7 @@ = diff.new_path || diff.old_path %hr %pre - = diff.diff + = color_email_diff(diff.diff) %br - if @compare.timeout -- cgit v1.2.1