An open API service indexing awesome lists of open source software.

https://github.com/archonic/ruby_html_tree_differ

Ruby wrapper for the Python library html-tree-diff.
https://github.com/archonic/ruby_html_tree_differ

Last synced: 5 months ago
JSON representation

Ruby wrapper for the Python library html-tree-diff.

Awesome Lists containing this project

README

          

# ruby_html_tree_differ

Shows the difference between two HTML documents, rendered to HTML. Relies on the [html-tree-diff](https://github.com/christian-oudard/htmltreediff/) python module and calls it using [pycall.rb](https://github.com/mrkn/pycall.rb).

### Prerequisites

You must have python installed. You can set the python command (`python` or `python3`) with the ENV variable `PYTHON`. By default pycall checks for `python3`, then `python`. If your `RUBY_PLATFORM` is `x86_x64_linux` you should set the ENV variable `LIBPYTHON` to the output of `which python` or `which python3`. For me it was `/usr/bin/python3`. Check pycall's [finder.rb](https://github.com/mrkn/pycall.rb/blob/master/lib/pycall/libpython/finder.rb) if you have trouble.

### Install

Gemfile:
```
gem "ruby_html_tree_differ"
```

Or:
```
gem install ruby_html_tree_differ
```

### Example

```ruby
require 'ruby_html_tree_differ'

differ = RubyHtmlTreeDiffer.new

old_doc = <Unchanged paragraph.

Altered paragraph.


Deleted paragraph.


EOF

new_doc = <Unchanged paragraph.

Alterated paragraph.


EOF

print differ.diff! old_doc, new_doc
```

```html

Unchanged paragraph.



Altered
Alterated
paragraph.



Deleted paragraph.



```

Check test/test.rb for 2 benchmarks. Very long documents take a long time to process. If you are using this in a web application, you will want to calculate the diff in a background job and cache the result.