markdiff 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e77befcb13e1946b68b5820403d3a3583836fbe8
4
- data.tar.gz: 99b131827eece95036986a5f528d96f4ebfb484a
3
+ metadata.gz: 5b3010fbe85faa7a63e166ffe7d18c45007f01a3
4
+ data.tar.gz: b1a4af8e050c517e9017e60539f3ccb946f394e4
5
5
  SHA512:
6
- metadata.gz: 5201a42d38ed0d77c37b62171abd3163ef0428cc06648a4024082fc22e36d7a001e0720b8389f178e4720bafe123411f3102289c2ced21dc35ad77bab5222491
7
- data.tar.gz: b0267e2e49d7ca40cc8bd7c82c08652bd0ec1786fcd35e01553fa0d77a2707363aa98f52d82be3302bc99381a90bd2e3c35ed6de8f5318b2d2f1eee01b190415
6
+ metadata.gz: 6012e20cb4d9129e710c4f49c88cdfe652b8a1951c8b07425433745bead2d49dc58d58c3a251a4042e11c9ef24c2788bee4beb81b705b17f6a6cfeaca737699f
7
+ data.tar.gz: aab0e79a022a104345388c5f79d378a6affa4774f92ee7aad69abb4211058449d454b0399ee52d49c75216c2bf5844653cdc592abc9a17405bb697edaa7ecb1a
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.2.0
2
+ - Support div.changed and li.changed
3
+
4
+ ## 0.1.0
5
+ - 1st Release
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Markdiff
1
+ # Markdiff [![Build Status](https://travis-ci.org/r7kamura/markdiff.svg)](https://travis-ci.org/r7kamura/markdiff)
2
2
  Rendered Markdown differ.
3
3
 
4
4
  ## Usage
@@ -7,7 +7,7 @@ require "markdiff"
7
7
 
8
8
  differ = Markdiff::Differ.new
9
9
  node = differ.render("<p>a</p>", "<p>b</p>")
10
- node.to_html #=> "<p><del>a</del><ins>b</ins></p>"
10
+ node.to_html #=> '<div class="changed"><p><del>a</del><ins>b</ins></p></div>'
11
11
  ```
12
12
 
13
13
  See [spec/markdiff/differ_spec.rb](spec/markdiff/differ_spec.rb) for more examples.
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -16,16 +16,26 @@ module Markdiff
16
16
  case operation
17
17
  when ::Markdiff::Operations::AddChildOperation
18
18
  operation.target_node.add_child(operation.inserted_node)
19
+ mark_li_as_changed(operation.target_node)
20
+ mark_top_level_node_as_changed(operation.target_node)
19
21
  when ::Markdiff::Operations::AddDataBeforeHrefOperation
20
22
  operation.target_node["data-before-href"] = operation.target_node["href"]
21
23
  operation.target_node["href"] = operation.after_href
24
+ mark_li_as_changed(operation.target_node)
25
+ mark_top_level_node_as_changed(operation.target_node)
22
26
  when ::Markdiff::Operations::AddDataBeforeTagNameOperation
23
27
  operation.target_node["data-before-tag-name"] = operation.target_node.name
24
28
  operation.target_node.name = operation.after_tag_name
29
+ mark_li_as_changed(operation.target_node)
30
+ mark_top_level_node_as_changed(operation.target_node)
25
31
  when ::Markdiff::Operations::AddPreviousSiblingOperation
26
32
  operation.target_node.add_previous_sibling(operation.inserted_node)
33
+ mark_li_as_changed(operation.target_node)
34
+ mark_top_level_node_as_changed(operation.target_node.parent)
27
35
  when ::Markdiff::Operations::RemoveOperation
28
36
  operation.target_node.replace(operation.inserted_node)
37
+ mark_li_as_changed(operation.target_node)
38
+ mark_top_level_node_as_changed(operation.target_node)
29
39
  end
30
40
  end
31
41
  node
@@ -153,5 +163,23 @@ module Markdiff
153
163
  before_node["href"] != after_node["href"] &&
154
164
  before_node.inner_html == after_node.inner_html
155
165
  end
166
+
167
+ # @param [Nokogiri::XML::Node] node
168
+ def mark_li_as_changed(node)
169
+ until node.parent.nil? || node.parent.fragment?
170
+ if node.name == "li" && node["class"] != "changed"
171
+ node["class"] = "changed"
172
+ end
173
+ node = node.parent
174
+ end
175
+ end
176
+
177
+ # @param [Nokogiri::XML::Node] node
178
+ def mark_top_level_node_as_changed(node)
179
+ node = node.parent until node.parent.nil? || node.parent.fragment?
180
+ unless node.name == "div" && node["class"] == "changed"
181
+ node.replace(%(<div class="changed">#{node}</div>))
182
+ end
183
+ end
156
184
  end
157
185
  end
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md