contentful_converter 0.0.1.22 → 0.0.1.23

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
  SHA256:
3
- metadata.gz: ff50772e7cf3d60d6587047360fd5f2aa1f87eb3e7110c731b1fdf6862b70cbe
4
- data.tar.gz: 82c222abe96c9d3ac4ccf0e1e0f95f9dcc9d1e11dfda819bbd24737007b3512b
3
+ metadata.gz: 85c33ddb801f9755c49bfb41f96ec9e8ae51ec8d4ec69d5ff2bf7a7ac9af1476
4
+ data.tar.gz: 1fe744e0153d34094992cb71eb8cd8500415e951ac49839d9804e3d6288fee39
5
5
  SHA512:
6
- metadata.gz: f9bc85b65ff13a53db3bc3c21050287799c273be82778d2a9378f18bc83d8b80af3d5b3b7f43db921743c66e3bd5125b26ce14252586c13b40938222f072d165
7
- data.tar.gz: 37a4f52a6b29bad99ddfc7618b5706e6ae80512633993daf179b4f79810db54925b5c324bd6911015e5ce5b60abf5717e362ef6139091d51084984cda395d1d2
6
+ metadata.gz: 6964e495b8f4ace1179a0de5e0048dafa93c1fed93c66e803a5ee73f5285942e7a9418cc3fc96d8e89dbd289a785a6c3301d5c9d9b5c459272a622f3fb47938f
7
+ data.tar.gz: 2a5e04b05af9082d6c11ec6d5d53588662fbfff6d681825059499170f764061416f06203dfbc94ee97098169bc36c6833c648a09bf2ad9e9dca4098a0a7e459d
data/README.md CHANGED
@@ -44,6 +44,16 @@ ContentfulConverter.convert('<h3>hello world</h3>')
44
44
 
45
45
  ### Additional info
46
46
 
47
+ **Exclude Nodes**
48
+
49
+ Add nodes to be removed from the conversion
50
+
51
+ ```ruby
52
+ ContentfulConverter.configure do |config|
53
+ config.forbidden_nodes = 'table', 'script'
54
+ end
55
+ ```
56
+
47
57
  **`<a>`**
48
58
 
49
59
  * HTML hyperlinks with full URL e.g: (`<a href="https://google.com"></a>`), will be converted into URL hyperlinks
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ContentfulConverter
4
+ class << self
5
+ attr_accessor :configuration
6
+ end
7
+
8
+ def self.configure
9
+ self.configuration ||= Configuration.new
10
+ yield(configuration) if block_given?
11
+ self
12
+ end
13
+
14
+ class Configuration
15
+ attr_reader :forbidden_nodes
16
+
17
+ def initialize
18
+ @forbidden_nodes = []
19
+ end
20
+
21
+ def forbidden_nodes=(*nodes)
22
+ @forbidden_nodes = nodes.flatten.uniq
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'nokogiri'
4
+ require 'contentful_converter/configuration'
4
5
 
5
6
  module ContentfulConverter
6
7
  class NokogiriBuilder
@@ -18,6 +19,7 @@ module ContentfulConverter
18
19
  # nokogiri creates a tree that is accepted by contentful.
19
20
  def transform(html)
20
21
  doc = create_nokogiri_fragment(html)
22
+ remove_forbidden_elements(doc)
21
23
  find_nodes(doc, %w[section div]).each { |elem| elem.name = 'p' }
22
24
  find_nodes(doc, 'img').each { |elem| elem.name = 'embed' }
23
25
  doc.to_html
@@ -27,6 +29,13 @@ module ContentfulConverter
27
29
  Nokogiri::HTML.fragment(html)
28
30
  end
29
31
 
32
+ def remove_forbidden_elements(doc)
33
+ forbidden_nodes = ContentfulConverter.configure.configuration.forbidden_nodes
34
+ return if forbidden_nodes.empty?
35
+
36
+ find_nodes(doc, forbidden_nodes).each(&:remove)
37
+ end
38
+
30
39
  def normalize_lists(nokogiri_fragment)
31
40
  find_nodes(nokogiri_fragment, 'li').each { |li| wrap_parents_in_ul(li) }
32
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentfulConverter
4
- VERSION = '0.0.1.22'
4
+ VERSION = '0.0.1.23'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.22
4
+ version: 0.0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Avlonitis
@@ -46,6 +46,7 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - README.md
48
48
  - lib/contentful_converter.rb
49
+ - lib/contentful_converter/configuration.rb
49
50
  - lib/contentful_converter/converter.rb
50
51
  - lib/contentful_converter/node_builder.rb
51
52
  - lib/contentful_converter/nodes/base.rb