html_surgeon 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6988528869b8d0783dc66a3fc95ac318a39f44f4
4
- data.tar.gz: 9b0a847987cf59900c58d88d68edf65a78c5d2cd
3
+ metadata.gz: ab5cdfb5f4b18b04314af4cb220395841332481e
4
+ data.tar.gz: 5411f9dd20388ca336f444891a4516e069534dc4
5
5
  SHA512:
6
- metadata.gz: 9e5ffbded35f90903bc1aaa0af358dd903fa99024f122ff20195b4c91b667d8842136aa31546422ec12ee81d045be4d13d7ac6562c0844e3314ac260778b9ee8
7
- data.tar.gz: 8baf36739a718bb7eb98a0208ebb92ef2564a8349492062cb5bac7275252d7449d8802a00c56481c45b711e26a54629f779a88db28b3cbd9ff5ec9e8464dec2d
6
+ metadata.gz: 1d663853d245a480ad691f8e1218bfca304b9790326909691477cebb4ab5af418a3adb7d4093afda7c4f7439a53bd963acb5fb02613e8fc275712db8dadd40f3
7
+ data.tar.gz: f27b7bd09a2fbbda7b3f3a04caf76ed8bb7745e3ec8282ae4100f9fb8b5a2adf6628b18999b9cbef40ea9d85e231ce195fdbdea3143d2bfdf2931659ff789d3b
data/README.md CHANGED
@@ -180,7 +180,7 @@ change_set.run # => nodes skipped if reject callback return truthy or if select
180
180
  ### Replace Tag Name
181
181
 
182
182
  ```ruby
183
- surgeon.css('div.to-be-changed').replace_name_tag('article')
183
+ surgeon.css('div.to-be-changed').replace_tag_name('article')
184
184
  ```
185
185
 
186
186
  ### Add CSS Class
@@ -191,7 +191,7 @@ surgeon.css('div.to-be-changed').add_css_class('applied-some-stuff')
191
191
 
192
192
  ## Rollback
193
193
 
194
- the surgen can be used to revert any audited rollback. We can select what changes to rollback based on:
194
+ the surgeon can be used to revert any audited rollback. We can select what changes to rollback based on:
195
195
 
196
196
  - `change_set`: The change_set UUID
197
197
  - `changed_at`: The change timestamp
@@ -208,6 +208,21 @@ surgeon.rollback(changed_at: changed_at).html # => returns the html with only t
208
208
  surgeon.rollback(changed_from: changed_from).html # => returns the html with any change sets with a timestamp more recent than `changed_from` reverted
209
209
  ```
210
210
 
211
+ ## Clear Audit trail
212
+
213
+ we can clear all audit from the given html with the `clear_audit` method.
214
+
215
+ ```ruby
216
+ surgeon = HtmlSurgeon.for(GIVEN_HTML)
217
+ surgeon.clear_audit.html # => returns the html with all audit html attributes removed
218
+ ```
219
+
220
+ ## Helper Methods
221
+
222
+ ### `HtmlSurgeon.node_has_css_class?(nokogiri_node, css_class)`
223
+
224
+ it will return true if the given nokogiri node has that css_class
225
+
211
226
  ## Installation
212
227
 
213
228
  Add this line to your application's Gemfile:
@@ -238,6 +253,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/eturin
238
253
 
239
254
  ## CHANGESET
240
255
 
256
+ ### v0.5.0
257
+
258
+ - added `node_has_css_class?` helper method to `HtmlSurgeon`
259
+ - added `clear_audit` to surgeon
260
+
241
261
  ### v0.4.0
242
262
 
243
263
  - added `select` and `reject` callbacks to Change Set, based on blocks with `node` as single argument
@@ -7,6 +7,7 @@ require 'html_surgeon/version'
7
7
  require 'html_surgeon/abstract_method_error'
8
8
  require 'html_surgeon/auditor'
9
9
  require 'html_surgeon/node_reverser'
10
+ require 'html_surgeon/node_audit_cleaner'
10
11
  require 'html_surgeon/service'
11
12
  require 'html_surgeon/change_set'
12
13
  require 'html_surgeon/change'
@@ -20,4 +21,10 @@ module HtmlSurgeon
20
21
  def self.for(html_string, **options)
21
22
  Service.new html_string, **options
22
23
  end
24
+
25
+ # helper methods
26
+ def self.node_has_css_class?(nokogiri_node, css_class)
27
+ Changes::AddCssClass.has_class? nokogiri_node, css_class
28
+ end
29
+
23
30
  end
@@ -26,7 +26,7 @@ module HtmlSurgeon
26
26
 
27
27
  def audit_data(node)
28
28
  basic_audit_data.merge type: AUDIT_TYPE,
29
- existed_before: self.class.had_class?(node, css_class),
29
+ existed_before: self.class.has_class?(node, css_class),
30
30
  class: css_class
31
31
  end
32
32
 
@@ -54,7 +54,7 @@ module HtmlSurgeon
54
54
  node.get_attribute(CLASS_ATTRIBUTE).to_s.split(CLASS_SEPARATOR)
55
55
  end
56
56
 
57
- def self.had_class?(node, css_class)
57
+ def self.has_class?(node, css_class)
58
58
  node_classes(node).include? css_class
59
59
  end
60
60
 
@@ -0,0 +1,22 @@
1
+ module HtmlSurgeon
2
+ class NodeAuditCleaner
3
+ attr_reader :node
4
+
5
+ def initialize(node:)
6
+ @node = node
7
+ end
8
+
9
+ def call
10
+ write_empty_changes_list
11
+ end
12
+
13
+ private
14
+ def write_empty_changes_list
15
+ auditor.apply []
16
+ end
17
+
18
+ def auditor
19
+ @auditor ||= Auditor.new node
20
+ end
21
+ end
22
+ end
@@ -34,6 +34,14 @@ module HtmlSurgeon
34
34
  self
35
35
  end
36
36
 
37
+ def clear_audit
38
+ doc.css("[#{DATA_CHANGE_AUDIT_ATTRIBUTE}]").each do |node|
39
+ NodeAuditCleaner.new(node: node).call
40
+ end
41
+
42
+ self
43
+ end
44
+
37
45
  private
38
46
  def doc
39
47
  @doc ||= Nokogiri::HTML.fragment @given_html.dup
@@ -1,3 +1,3 @@
1
1
  module HtmlSurgeon
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_surgeon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
@@ -146,6 +146,7 @@ files:
146
146
  - lib/html_surgeon/changes.rb
147
147
  - lib/html_surgeon/changes/add_css_class.rb
148
148
  - lib/html_surgeon/changes/replace_tag_name.rb
149
+ - lib/html_surgeon/node_audit_cleaner.rb
149
150
  - lib/html_surgeon/node_reverser.rb
150
151
  - lib/html_surgeon/service.rb
151
152
  - lib/html_surgeon/version.rb