draftjs_exporter 0.0.5 → 0.0.6

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: 395bf9a929c33b582a3507182569147d4b7a83f5
4
- data.tar.gz: f7efaff9f468ec23b57ad2e8d1b82b919ff78be9
3
+ metadata.gz: 2ea428b81472206acdc84857705759cb955bf990
4
+ data.tar.gz: bfbcaf7327d2db7c1c9166830e423e2d90871fa2
5
5
  SHA512:
6
- metadata.gz: 189816dfafca038d85830abe93a058b28e7ed57fe4068958232903da65e4a4463a5b71465893693f25dc3303f47b5c56e9e4f357c0f2785450605489e8071d04
7
- data.tar.gz: 6a1b4e88d84d9432966a89d22136f1fdaffc1e5112aa29593731f402408b064f332a8788c525c0add8d74280f3b9a3c9682039203ef5a0a0e26eb3c1950124f6
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
- element = parent_element.document.create_element('a', href: data.fetch(:data, {}).fetch(:url))
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DraftjsExporter
3
- VERSION = '0.0.5'.freeze
3
+ VERSION = '0.0.6'.freeze
4
4
  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 = <<-EOS.strip
235
+ expected_output = <<-OUTPUT.strip
236
236
  <ul class="public-DraftStyleDefault-ul">\n<li>item1</li>\n<li>item2</li>\n</ul>
237
- EOS
237
+ OUTPUT
238
238
 
239
239
  expect(mapper.call(input)).to eq(expected_output)
240
240
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Cushion