contentful_converter 0.0.1.12 → 0.0.1.13

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: 9bcee9dc48afd4c917fb46ba299eb5cad6030fac447ba86de0ae51ad03eef629
4
- data.tar.gz: e51cd46ed8ec8eed058d2461d78c06f0de7128aaac5a7d867c4992d4cea41c88
3
+ metadata.gz: 4af2afd7d0764a46305dea57d839478d7c424478c31beb7707a2e34c18a93815
4
+ data.tar.gz: bb2172e979ebff1f518f9286653bf84d79437cc905220bf1da0148c4e45021a9
5
5
  SHA512:
6
- metadata.gz: f6d89e89940edeca060d2c2eab090b3518e87a7282cca6eb27f77978c400935cf40a34a8e355348032b624b936fded51206dfda82ab517acd9130ee1930b231c
7
- data.tar.gz: c0c490af7c05434c146f198909e367f8ef861bdd87c126b77906b7e721262549025e39bb4239d73bac87a9af716978446a5b7dd5d283b32be89bbc1710e91a36
6
+ metadata.gz: 96d859ac6abc2a91cf99b1a53f0dd87116612690eca93cd0c3f454c50f85f6ba34a4d9eb39a79db216b8ae4b6083d6e09e87aead1613044d677886e3bb379622
7
+ data.tar.gz: a18b48a7d94854c67a89cfaf7cb103c5be8402c6c867e01e5743817665270ec3e88d3e631442f9cac02775c860b532d0ab5e5778b28fe81df4cac73dbd7e6e0a
data/README.md CHANGED
@@ -45,13 +45,131 @@ ContentfulConverter.convert('<h3>hello world</h3>')
45
45
  ```
46
46
 
47
47
  ### Additional info
48
- **HREF links**
49
48
 
50
- * HTML hyperlinks with full URL e.g: (https://google.com), will be converted into URL hyperlinks
51
-
52
- * HTML hyperlinks without a scheme e.g: ('/aboutus/contact'), will be converted into ENTRY hyperlinks, with the href value as an ID
49
+ **`<a>`**
50
+
51
+ * HTML hyperlinks with full URL e.g: (`<a href="https://google.com"></a>`), will be converted into URL hyperlinks
52
+ ```ruby
53
+ {
54
+ nodeType: 'paragraph',
55
+ data: {},
56
+ content: [
57
+ {
58
+ nodeType: 'hyperlink',
59
+ data: {
60
+ uri: 'https://google.com'
61
+ },
62
+ content: [
63
+ {
64
+ marks: [],
65
+ value: 'click me',
66
+ nodeType: 'text',
67
+ data: {}
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ }
73
+ ```
74
+
75
+ * HTML hyperlinks without a scheme e.g: (`<a href="/about_us/contact">about us</a>`), will be converted into ENTRY hyperlinks, with the href value as an ID
76
+ ```ruby
77
+ {
78
+ nodeType: "paragraph",
79
+ data: {},
80
+ content: [
81
+ {
82
+ nodeType: "entry-hyperlink",
83
+ data: {
84
+ target: {
85
+ sys: {
86
+ id: "/about_us/contact",
87
+ type: "Link",
88
+ linkType: "Entry"
89
+ }
90
+ }
91
+ },
92
+ content: [
93
+ {
94
+ data: {},
95
+ marks: [],
96
+ value: "about us",
97
+ nodeType: "text"
98
+ }
99
+ ]
100
+ }
101
+ ]
102
+ }
103
+ ```
104
+
105
+ * HTML hyperlinks without a scheme but with an extension e.g: (`<a href="/path/to_file.docx">file</a>`), will be converted into ASSET hyperlinks, with the href value as an ID, excluding the extension.
106
+ ```ruby
107
+ {
108
+ nodeType: "paragraph",
109
+ data: {},
110
+ content: [
111
+ {
112
+ nodeType: "asset-hyperlink",
113
+ data: {
114
+ target: {
115
+ sys: {
116
+ id: "/path/to_file",
117
+ type: "Link",
118
+ linkType: "Entry"
119
+ }
120
+ }
121
+ },
122
+ content: [
123
+ {
124
+ data: {},
125
+ marks: [],
126
+ value: "file",
127
+ nodeType: "text"
128
+ }
129
+ ]
130
+ }
131
+ ]
132
+ }
133
+ ```
134
+
135
+ **`<embed />`**
136
+
137
+ If you want to add an embedded entry block, you need to create an `<embed>` element in HTML
138
+ with src as the entry ID and type for the entry type.
139
+
140
+ * Embedded Entry block: `<embed src="id_of_your_entry_123" type="entry"/>`
141
+ ```ruby
142
+ {
143
+ data: {
144
+ target: {
145
+ sys: {
146
+ id: "id_of_your_entry_123",
147
+ type: "Link",
148
+ linkType: "Entry"
149
+ }
150
+ }
151
+ },
152
+ content: [],
153
+ nodeType: "embedded-entry-block"
154
+ }
155
+ ```
53
156
 
54
- * HTML hyperlinks without a scheme but with an extension e.g: ('myfile.docx'), will be converted into ASSET hyperlinks, with the href value as an ID, minus the extension.
157
+ * Embedded Asset block: `<embed src="id_of_your_entry_123" type="asset"/>`
158
+ ```ruby
159
+ {
160
+ data: {
161
+ target: {
162
+ sys: {
163
+ id: "id_of_your_entry_123",
164
+ type: "Link",
165
+ linkType: "Asset"
166
+ }
167
+ }
168
+ },
169
+ content: [],
170
+ nodeType: "embedded-asset-block"
171
+ }
172
+ ```
55
173
 
56
174
  ---
57
175
 
@@ -9,6 +9,7 @@ require 'contentful_converter/nodes/underline'
9
9
  require 'contentful_converter/nodes/italic'
10
10
  require 'contentful_converter/nodes/strong'
11
11
  require 'contentful_converter/nodes/code'
12
+ require 'contentful_converter/nodes/embed'
12
13
  require 'contentful_converter/nodes/ordered_list'
13
14
  require 'contentful_converter/nodes/unordered_list'
14
15
  require 'contentful_converter/nodes/horizontal_line'
@@ -36,6 +37,7 @@ module ContentfulConverter
36
37
  'div' => Nodes::Paragraph,
37
38
  'br' => Nodes::Paragraph,
38
39
  'section' => Nodes::Paragraph,
40
+ 'embed' => Nodes::Embed,
39
41
  'hr' => Nodes::HorizontalLine,
40
42
  'blockquote' => Nodes::Blockquote,
41
43
  'ul' => Nodes::UnorderedList,
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'contentful_converter/nodes/hyperlink'
4
+
5
+ module ContentfulConverter
6
+ module Nodes
7
+ class Embed < Hyperlink
8
+ EMBED_VALUES = {
9
+ asset: 'embedded-asset-block',
10
+ entry: 'embedded-entry-block'
11
+ }.freeze
12
+
13
+ def needs_p_wrapping?
14
+ false
15
+ end
16
+
17
+ private
18
+
19
+ def type
20
+ EMBED_VALUES[type_value.downcase.to_sym] || raise('Incorrect embed type')
21
+ end
22
+
23
+ def options
24
+ hyperlink_entry_option(type_value.capitalize)
25
+ end
26
+
27
+ def type_value
28
+ nokogiri_node[:type] || raise('Embed element requires a type')
29
+ end
30
+
31
+ def parsed_link
32
+ nokogiri_node[:src]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -23,7 +23,7 @@ module ContentfulConverter
23
23
  end
24
24
 
25
25
  def hyperlink_option
26
- { data: { uri: parsed_href.to_s } }
26
+ { data: { uri: parsed_link.to_s } }
27
27
  end
28
28
 
29
29
  def hyperlink_entry_option(type)
@@ -31,7 +31,7 @@ module ContentfulConverter
31
31
  data: {
32
32
  target: {
33
33
  sys: {
34
- id: parsed_href.to_s.split('.').first,
34
+ id: parsed_link.to_s.split('.').first,
35
35
  type: "Link",
36
36
  linkType: type
37
37
  }
@@ -41,21 +41,19 @@ module ContentfulConverter
41
41
  end
42
42
 
43
43
  def uri_scheme?
44
- parsed_href.scheme
44
+ parsed_link.scheme
45
45
  end
46
46
 
47
47
  def uri_extension?
48
- parsed_href.to_s.split('.')[1]
48
+ parsed_link.to_s.split('.')[1]
49
49
  end
50
50
 
51
- def parsed_href
52
- return URI(href_value) if href_value
53
-
54
- URI('')
51
+ def parsed_link
52
+ link_value ? URI(link_value) : URI('')
55
53
  end
56
54
 
57
- def href_value
58
- nokogiri_node['href']
55
+ def link_value
56
+ nokogiri_node[:href]
59
57
  end
60
58
  end
61
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentfulConverter
4
- VERSION = '0.0.1.12'
4
+ VERSION = '0.0.1.13'
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.12
4
+ version: 0.0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Avlonitis
@@ -52,6 +52,7 @@ files:
52
52
  - lib/contentful_converter/nodes/blockquote.rb
53
53
  - lib/contentful_converter/nodes/code.rb
54
54
  - lib/contentful_converter/nodes/document.rb
55
+ - lib/contentful_converter/nodes/embed.rb
55
56
  - lib/contentful_converter/nodes/header.rb
56
57
  - lib/contentful_converter/nodes/horizontal_line.rb
57
58
  - lib/contentful_converter/nodes/hyperlink.rb