diff --git a/Gemfile b/Gemfile index 69769af5..9922461b 100644 --- a/Gemfile +++ b/Gemfile @@ -67,7 +67,7 @@ gem 'email_validator' # Email address obfuscation gem 'actionview-encoded_mail_to' # To display a patched diff for event descriptions -gem 'differ', github: 'genuitytech/differ', branch: 'add_patch_format' +gem 'differ' # A generic library to administrate the tool gem 'activeadmin', github: 'gregbell/active_admin' diff --git a/Gemfile.lock b/Gemfile.lock index e5aafd9a..e5c05966 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,13 +6,6 @@ GIT jquery-rails rails (>= 3.2.2) -GIT - remote: git://github.com/genuitytech/differ.git - revision: ff1a29ab2fa87620149e001d07aa48bef92de850 - branch: add_patch_format - specs: - differ (0.1.2) - GIT remote: git://github.com/gregbell/active_admin.git revision: 944af76ace89f941a7baa92775854d2e1d0e6dba @@ -135,6 +128,7 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) devise-i18n (0.11.2) + differ (0.1.2) docile (1.1.5) em-websocket (0.5.1) eventmachine (>= 0.12.9) @@ -387,7 +381,7 @@ DEPENDENCIES compass-rails devise devise-i18n - differ! + differ email_validator font-awesome-rails geocoder diff --git a/app/views/moderation_mailer/update.text.haml b/app/views/moderation_mailer/update.text.haml index e2f4fbcb..87dfec7b 100644 --- a/app/views/moderation_mailer/update.text.haml +++ b/app/views/moderation_mailer/update.text.haml @@ -10,7 +10,9 @@ - prev = render file: '/events/show' - @event = former -= Differ.diff(new, prev).format_as(:patch).gsub(/\[\d{1,2}m/, '') +- require 'differ/format/patch' +- Differ.format = Differ::Format::Patch += Differ.diff new, prev \ - if @current_user = edit_moderation_url @event diff --git a/lib/differ/format/patch.rb b/lib/differ/format/patch.rb new file mode 100644 index 00000000..d9204cea --- /dev/null +++ b/lib/differ/format/patch.rb @@ -0,0 +1,36 @@ +# Formatter for diff output +module Differ + module Format + # Try to format as unified diff, using - and + + module Patch + class << self + def format(change) + case + when change.change? + as_change change + when change.delete? + as_delete change + when change.insert? + as_insert change + else + '' + end + end + + private + + def as_insert(change) + "+ #{change.insert}" + end + + def as_delete(change) + "- #{change.delete}" + end + + def as_change(change) + [as_delete(change), as_insert(change)].join '\n' + end + end + end + end +end