Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
270 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
module Differ | |||
module Format | |||
module Ascii | |||
class << self | |||
def format(change) | |||
(change.change? && as_change(change)) || | |||
(change.delete? && as_delete(change)) || | |||
(change.insert? && as_insert(change)) || | |||
'' | |||
end | |||
|
|||
private | |||
def as_insert(change) | |||
"{+#{change.insert.inspect}}" | |||
end | |||
|
|||
def as_delete(change) | |||
"{-#{change.delete.inspect}}" | |||
end | |||
|
|||
def as_change(change) | |||
"{#{change.delete.inspect} >> #{change.insert.inspect}}" | |||
end | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
module Differ | |||
module Format | |||
module Color | |||
class << self | |||
def format(change) | |||
(change.change? && as_change(change)) || | |||
(change.delete? && as_delete(change)) || | |||
(change.insert? && as_insert(change)) || | |||
'' | |||
end | |||
|
|||
private | |||
def as_insert(change) | |||
"\033[32m#{change.insert}\033[0m" | |||
end | |||
|
|||
def as_delete(change) | |||
"\033[31m#{change.delete}\033[0m" | |||
end | |||
|
|||
def as_change(change) | |||
as_delete(change) << as_insert(change) | |||
end | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
module Differ | |||
module Format | |||
module HTML | |||
class << self | |||
def format(change) | |||
(change.change? && as_change(change)) || | |||
(change.delete? && as_delete(change)) || | |||
(change.insert? && as_insert(change)) || | |||
'' | |||
end | |||
|
|||
private | |||
def as_insert(change) | |||
%Q{<ins class="differ">#{change.insert}</ins>} | |||
end | |||
|
|||
def as_delete(change) | |||
%Q{<del class="differ">#{change.delete}</del>} | |||
end | |||
|
|||
def as_change(change) | |||
as_delete(change) << as_insert(change) | |||
end | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
require 'spec_helper' | |||
|
|||
describe Differ::Format::Ascii do | |||
it 'should format inserts well' do | |||
@expected = '{+"SAMPLE"}' | |||
Differ::Format::Ascii.format(+'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format deletes well' do | |||
@expected = '{-"SAMPLE"}' | |||
Differ::Format::Ascii.format(-'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format changes well' do | |||
@expected = '{"THEN" >> "NOW"}' | |||
Differ::Format::Ascii.format('THEN' >> 'NOW').should == @expected | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
require 'spec_helper' | |||
|
|||
describe Differ::Format::Color do | |||
it 'should format inserts well' do | |||
@expected = "\033[32mSAMPLE\033[0m" | |||
Differ::Format::Color.format(+'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format deletes well' do | |||
@expected = "\033[31mSAMPLE\033[0m" | |||
Differ::Format::Color.format(-'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format changes well' do | |||
@expected = "\033[31mTHEN\033[0m\033[32mNOW\033[0m" | |||
Differ::Format::Color.format('THEN' >> 'NOW').should == @expected | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
require 'spec_helper' | |||
|
|||
describe Differ::Format::HTML do | |||
it 'should format inserts well' do | |||
@expected = '<ins class="differ">SAMPLE</ins>' | |||
Differ::Format::HTML.format(+'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format deletes well' do | |||
@expected = '<del class="differ">SAMPLE</del>' | |||
Differ::Format::HTML.format(-'SAMPLE').should == @expected | |||
end | |||
|
|||
it 'should format changes well' do | |||
@expected = '<del class="differ">THEN</del><ins class="differ">NOW</ins>' | |||
Differ::Format::HTML.format('THEN' >> 'NOW').should == @expected | |||
end | |||
end |
Oops, something went wrong.