draftjs_exporter 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 8d9c42d97b578e844a726944450512244da1ad09
4
- data.tar.gz: 0e81b008080958f8c4dcca56371d1aeb5a73942d
3
+ metadata.gz: 395bf9a929c33b582a3507182569147d4b7a83f5
4
+ data.tar.gz: f7efaff9f468ec23b57ad2e8d1b82b919ff78be9
5
5
  SHA512:
6
- metadata.gz: 2943b0b81039708197ae5a4b222553273984cc1129ed93fc0950c2c9b209bb034175820e31316c7d5e367b5893dbf67b5e0fefe28a96270a61ed22ac7e614cea
7
- data.tar.gz: cf047100a376c3060ae27108e92bf320a5e0942293316b2bb0aefc0513bc008731ddc3d4301072fa4f2a56caf46ca72be4e953a06c34ae7624ded830623c7903
6
+ metadata.gz: 189816dfafca038d85830abe93a058b28e7ed57fe4068958232903da65e4a4463a5b71465893693f25dc3303f47b5c56e9e4f357c0f2785450605489e8071d04
7
+ data.tar.gz: 6a1b4e88d84d9432966a89d22136f1fdaffc1e5112aa29593731f402408b064f332a8788c525c0add8d74280f3b9a3c9682039203ef5a0a0e26eb3c1950124f6
data/README.md CHANGED
@@ -76,7 +76,7 @@ exporter.call({
76
76
  }
77
77
  ]
78
78
  })
79
- # => "<h1>Header</h1><div>\n<span style=\"fontStyle: 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\">paragraph</a> text</div>"
80
80
  ```
81
81
 
82
82
  ## Tests
@@ -31,7 +31,8 @@ module DraftjsExporter
31
31
  private
32
32
 
33
33
  def start_command(command)
34
- entity_details = entity_map.fetch(command.data.to_s)
34
+ entity_details = entity_for(command.data)
35
+
35
36
  decorator = entity_decorators.fetch(entity_details.fetch(:type))
36
37
  parent_element = entity_stack.last.first
37
38
  new_element = decorator.call(parent_element, entity_details)
@@ -39,7 +40,7 @@ module DraftjsExporter
39
40
  end
40
41
 
41
42
  def stop_command(command)
42
- entity_details = entity_map.fetch(command.data.to_s)
43
+ entity_details = entity_for(command.data)
43
44
  _element, expected_entity_details = entity_stack.last
44
45
 
45
46
  if expected_entity_details != entity_details
@@ -48,5 +49,10 @@ module DraftjsExporter
48
49
 
49
50
  entity_stack.pop
50
51
  end
52
+
53
+ def entity_for(key)
54
+ entity_keys = [key.to_s, key.to_s.to_sym]
55
+ entity_keys.map { |key| entity_map.fetch(key, nil) }.compact.first
56
+ end
51
57
  end
52
58
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DraftjsExporter
3
- VERSION = '0.0.4'.freeze
3
+ VERSION = '0.0.5'.freeze
4
4
  end
@@ -124,6 +124,45 @@ RSpec.describe DraftjsExporter::HTML do
124
124
  expect(mapper.call(input)).to eq(expected_output)
125
125
  end
126
126
 
127
+ context 'with deeply_symbolized entities' do
128
+ it 'decodes the content_state to html' do
129
+ input = {
130
+ entityMap: {
131
+ :'0' => {
132
+ type: 'LINK',
133
+ mutability: 'MUTABLE',
134
+ data: {
135
+ url: 'http://example.com'
136
+ }
137
+ }
138
+ },
139
+ blocks: [
140
+ {
141
+ key: 'dem5p',
142
+ text: 'some paragraph text',
143
+ type: 'unstyled',
144
+ depth: 0,
145
+ inlineStyleRanges: [],
146
+ entityRanges: [
147
+ {
148
+ offset: 5,
149
+ length: 9,
150
+ key: 0
151
+ }
152
+ ]
153
+ }
154
+ ]
155
+ }
156
+
157
+ expected_output = <<-OUTPUT.strip
158
+ <div>some <a href="http://example.com">paragraph</a> text</div>
159
+ OUTPUT
160
+
161
+ expect(mapper.call(input)).to eq(expected_output)
162
+ end
163
+ end
164
+
165
+
127
166
  it 'throws an error if entities cross over' do
128
167
  input = {
129
168
  entityMap: {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Cushion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri