draftjs_exporter 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/draftjs_exporter/entities/link.rb +10 -1
- data/lib/draftjs_exporter/version.rb +1 -1
- data/spec/integrations/html_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ea428b81472206acdc84857705759cb955bf990
|
4
|
+
data.tar.gz: bfbcaf7327d2db7c1c9166830e423e2d90871fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a28dc46b4ca619c7bb93d31f8e131b1f14f34281190914d9190c104415fa1956d7a5a7dc2882ddb5de2b34f70dd51e3d76a8f8eeab03eb146d81a0ab8a7f2cb0
|
7
|
+
data.tar.gz: 97fe6d57a9469c14695c85456b9850ce6804f95393e93512b17b31f0c5505ac64fe708e61b5af5c8c594c028ef8a7a72de5d0bb6b507fe5dda10c4026efa9e4e
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ from Draft.js and convert it to HTML using Ruby.
|
|
16
16
|
# Create configuration for entities and styles
|
17
17
|
config = {
|
18
18
|
entity_decorators: {
|
19
|
-
'LINK' => DraftjsExporter::Entities::Link.new
|
19
|
+
'LINK' => DraftjsExporter::Entities::Link.new(className: 'link')
|
20
20
|
},
|
21
21
|
block_map: {
|
22
22
|
'header-one' => { element: 'h1' },
|
@@ -76,7 +76,7 @@ exporter.call({
|
|
76
76
|
}
|
77
77
|
]
|
78
78
|
})
|
79
|
-
# => "<h1>Header</h1><div>\n<span style=\"font-style: italic;\">some</span> <a href=\"http://example.com\">paragraph</a> text</div>"
|
79
|
+
# => "<h1>Header</h1><div>\n<span style=\"font-style: italic;\">some</span> <a href=\"http://example.com\" class=\"link\">paragraph</a> text</div>"
|
80
80
|
```
|
81
81
|
|
82
82
|
## Tests
|
@@ -2,8 +2,17 @@
|
|
2
2
|
module DraftjsExporter
|
3
3
|
module Entities
|
4
4
|
class Link
|
5
|
+
attr_reader :configuration
|
6
|
+
|
7
|
+
def initialize(configuration = { className: nil })
|
8
|
+
@configuration = configuration
|
9
|
+
end
|
10
|
+
|
5
11
|
def call(parent_element, data)
|
6
|
-
|
12
|
+
args = { href: data.fetch(:data, {}).fetch(:url) }
|
13
|
+
args[:class] = configuration.fetch(:className) if configuration[:className]
|
14
|
+
|
15
|
+
element = parent_element.document.create_element('a', args)
|
7
16
|
parent_element.add_child(element)
|
8
17
|
element
|
9
18
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe DraftjsExporter::HTML do
|
|
7
7
|
subject(:mapper) do
|
8
8
|
described_class.new(
|
9
9
|
entity_decorators: {
|
10
|
-
'LINK' => DraftjsExporter::Entities::Link.new
|
10
|
+
'LINK' => DraftjsExporter::Entities::Link.new(className: 'foobar-baz')
|
11
11
|
},
|
12
12
|
block_map: {
|
13
13
|
'header-one' => { element: 'h1' },
|
@@ -118,7 +118,7 @@ RSpec.describe DraftjsExporter::HTML do
|
|
118
118
|
}
|
119
119
|
|
120
120
|
expected_output = <<-OUTPUT.strip
|
121
|
-
<div>some <a href="http://example.com">paragraph</a> text</div>
|
121
|
+
<div>some <a href="http://example.com" class="foobar-baz">paragraph</a> text</div>
|
122
122
|
OUTPUT
|
123
123
|
|
124
124
|
expect(mapper.call(input)).to eq(expected_output)
|
@@ -155,7 +155,7 @@ RSpec.describe DraftjsExporter::HTML do
|
|
155
155
|
}
|
156
156
|
|
157
157
|
expected_output = <<-OUTPUT.strip
|
158
|
-
<div>some <a href="http://example.com">paragraph</a> text</div>
|
158
|
+
<div>some <a href="http://example.com" class="foobar-baz">paragraph</a> text</div>
|
159
159
|
OUTPUT
|
160
160
|
|
161
161
|
expect(mapper.call(input)).to eq(expected_output)
|
@@ -232,9 +232,9 @@ RSpec.describe DraftjsExporter::HTML do
|
|
232
232
|
]
|
233
233
|
}
|
234
234
|
|
235
|
-
expected_output = <<-
|
235
|
+
expected_output = <<-OUTPUT.strip
|
236
236
|
<ul class="public-DraftStyleDefault-ul">\n<li>item1</li>\n<li>item2</li>\n</ul>
|
237
|
-
|
237
|
+
OUTPUT
|
238
238
|
|
239
239
|
expect(mapper.call(input)).to eq(expected_output)
|
240
240
|
end
|