draftjs_html 0.25.0 → 0.26.0

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
  SHA256:
3
- metadata.gz: 20fc136c6cdbd1488b5ba808c3f55caca80f8f748241bc42b53028a544878542
4
- data.tar.gz: a39a398da3a5c1513d62d008fb9f80f105a9d4b91137da4b22d072a09727fea1
3
+ metadata.gz: 9fe4601ed10ebae8924fe906ffad4cd56bebf7867ec80182876ad0a1b5a3b739
4
+ data.tar.gz: 5d14c45c7192c936fbbe524a72c4886acddaf20f1f2dff5ccf9c1ce3d8de8a5f
5
5
  SHA512:
6
- metadata.gz: c7926f0d00a1b322a1e76b8a37c36010b356d7cb3cde97662378476e02787ca8ea09227b64a496dd778ef630c70e80f7cc6db69d39f7c84c165b185a2b367627
7
- data.tar.gz: 2cddf8a0b594755ae959935f8df954a7543d3208ab4c7ad55ab95b5fe28bb9f802ec140f11dcde9b728cc924e65d077afa5248734098c1013612ab3083e6ed28
6
+ metadata.gz: 38f78c86afbac0244a8eb967be90c6b647001e6a3bbbe3a6648190a45ac9cbecc2359c45f1fee5f995ed9584d037b2c337b8e267dece3c38e15a16a4dde8b775
7
+ data.tar.gz: 249423024673740842728d7b5cb8ca4ef1aa9bec1ee521be4402e21d5d89afa7f36563232de9c6af62831ae9cac3768c654537d75a8dbb44e25735f4d2dc0ac1
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+ # schedule:
8
+ # - cron: '42 5 * * *'
9
+
10
+ jobs:
11
+ test:
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: [ '3.0' ]
16
+
17
+ runs-on: ubuntu-latest
18
+ name: Ruby ${{matrix.ruby}}
19
+ container: ruby:${{matrix.ruby}}
20
+
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+
24
+ - name: Show ruby Version
25
+ run: |
26
+ ruby -v
27
+
28
+ - name: Install Modules
29
+ run: |
30
+ ./bin/setup
31
+
32
+ - name: Run tests
33
+ run: |
34
+ rake spec
35
+
36
+
data/README.md CHANGED
@@ -229,6 +229,44 @@ The callable should return a Hash with symbol keys. The supported values are:
229
229
  - `data` (optional, default `{}`)
230
230
  - an arbitrary data-bag (Hash) of entity data
231
231
 
232
+ ### Spec support
233
+
234
+ To make it easier to test our own code, we've developed a few RSpec matchers that
235
+ make normalization and comparison of raw DraftJS use the RawBuilder DSL. To take
236
+ advantage of this, you can (for RSpec only, currently) include the following in
237
+ your `spec_helper`, or equivalent.
238
+
239
+ ```ruby
240
+ require 'draftjs_html/spec_support/rspec'
241
+
242
+ RSpec.configure do |config|
243
+ config.include DraftjsHtml::SpecSupport::RSpecMatchers
244
+ end
245
+ ```
246
+
247
+ Then, later in your tests, you can assert on raw DraftJS "json" like this:
248
+
249
+ ```ruby
250
+ my_raw_draftjs_hash = { blocks: [{ key: 'a-random-uuid', text: 'Hi!' }], entityMap: {} }
251
+
252
+ expect(my_raw_draftjs_hash).to eq_raw_draftjs {
253
+ text_block 'Hi!'
254
+ }
255
+ ```
256
+
257
+ This will normalize the `key` values and other IDs to make _actual_ differences
258
+ easier to spot.
259
+
260
+ There's also a matcher called `eq_raw_draftjs_ignoring_keys` that takes an explicit
261
+ raw DraftJS hash on both sides.
262
+
263
+ ```ruby
264
+ my_raw_draftjs_hash = { blocks: [{ key: 'a-random-uuid', text: 'Hi!' }], entityMap: {} }
265
+ my_other_draftjs_hash = { blocks: [{ key: 'a-different-random-uuid', text: 'Hi!' }], entityMap: {} }
266
+
267
+ expect(my_raw_draftjs_hash).to eq_raw_draftjs_ignoring_keys my_other_draftjs_hash
268
+ ```
269
+
232
270
  ## Development
233
271
 
234
272
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -1,6 +1,7 @@
1
1
  module DraftjsHtml
2
2
  module HtmlDefaults
3
3
  BLOCK_TYPE_TO_HTML = {
4
+ 'article' => 'p',
4
5
  'paragraph' => 'p',
5
6
  'unstyled' => 'p',
6
7
  'header-one' => 'h1',
@@ -0,0 +1,42 @@
1
+ require 'rspec/expectations'
2
+ require 'draftjs_html/spec_support'
3
+
4
+ module DraftjsHtml
5
+ module SpecSupport
6
+ module RSpecMatchers
7
+ extend RSpec::Matchers::DSL
8
+
9
+ matcher :eq_raw_draftjs do |expected|
10
+ include DraftjsHtml::SpecSupport::KeyNormalization
11
+ match do |actual|
12
+ @raw_draftjs = normalize_keys(DraftjsHtml::Draftjs::RawBuilder.build(&block_arg))
13
+ @actual = normalize_keys(actual)
14
+
15
+ values_match?(@raw_draftjs, @actual)
16
+ end
17
+
18
+ diffable
19
+
20
+ def expected
21
+ @raw_draftjs
22
+ end
23
+ end
24
+
25
+ matcher :eq_raw_draftjs_ignoring_keys do |expected|
26
+ include DraftjsHtml::SpecSupport::KeyNormalization
27
+ match do |actual|
28
+ @raw_draftjs = normalize_keys(expected)
29
+ @actual = normalize_keys(actual)
30
+
31
+ values_match?(@raw_draftjs, @actual)
32
+ end
33
+
34
+ diffable
35
+
36
+ def expected
37
+ @raw_draftjs
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DraftjsHtml
4
+ module SpecSupport
5
+ module KeyNormalization
6
+ def normalize_keys(raw_draftjs)
7
+ draftjs = DraftjsHtml::Draftjs::Content.parse(raw_draftjs)
8
+ draftjs.blocks.each.with_index do |block, i|
9
+ block.key = "block-key-#{i}"
10
+ end
11
+
12
+ draftjs.entity_map.keys.each.with_index do |entity_key, i|
13
+ new_key = "entity-key-#{i}"
14
+ draftjs.entity_map[new_key] = draftjs.entity_map.delete(entity_key)
15
+ matching_entity_ranges = draftjs.blocks.flat_map { |block| block.raw_entity_ranges.select { |entity_range| entity_range['key'] == entity_key } }
16
+ matching_entity_ranges.each { |range| range['key'] = new_key }
17
+ end
18
+
19
+ DraftjsHtml::Draftjs::ToRaw.new.convert(draftjs)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.25.0"
4
+ VERSION = "0.26.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-22 00:00:00.000000000 Z
11
+ date: 2023-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".github/workflows/ci.yml"
48
49
  - ".gitignore"
49
50
  - ".rspec"
50
51
  - ".travis.yml"
@@ -76,6 +77,8 @@ files:
76
77
  - lib/draftjs_html/html_depth.rb
77
78
  - lib/draftjs_html/node.rb
78
79
  - lib/draftjs_html/overrideable_map.rb
80
+ - lib/draftjs_html/spec_support.rb
81
+ - lib/draftjs_html/spec_support/rspec.rb
79
82
  - lib/draftjs_html/to_html.rb
80
83
  - lib/draftjs_html/version.rb
81
84
  homepage: https://github.com/dugancathal/draftjs_html