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.
- Host: GitHub
- URL: https://github.com/archonic/ruby_html_tree_differ
- Owner: archonic
- License: mit
- Created: 2018-08-30T00:24:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T17:16:27.000Z (about 7 years ago)
- Last Synced: 2025-04-05T14:13:55.997Z (about 1 year ago)
- Language: HTML
- Homepage:
- Size: 174 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
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.