Dernière tentative pour un diff unifié propre

recurrent
echarp 8 years ago
parent ca688e0786
commit e97c5bc044
  1. 2
      Gemfile
  2. 10
      Gemfile.lock
  3. 4
      app/views/moderation_mailer/update.text.haml
  4. 36
      lib/differ/format/patch.rb

@ -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'

@ -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

@ -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

@ -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
Loading…
Cancel
Save