draftjs_html 0.25.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +36 -0
- data/README.md +38 -0
- data/lib/draftjs_html/html_defaults.rb +2 -0
- data/lib/draftjs_html/spec_support/rspec.rb +42 -0
- data/lib/draftjs_html/spec_support.rb +23 -0
- data/lib/draftjs_html/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3c2bb461481d4f338da121e4d8205369f6cba27ac5cf21bec8708de6fa738d
|
4
|
+
data.tar.gz: ea42f19e6600c5a046ef8a04c5ac0a1bc3542460ecc9811a4cc5b61b32d1b6c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d138ff6e137995205b14e9af4d66beb484e4509f87c5575fd870878e3fdf0212647c9312816e23014a520e5b9f4b2f6a4cd737604bde54bdc94af5e805b94c
|
7
|
+
data.tar.gz: 312deef7985e5ad14740f595b03d5d758c19613283b01a7a710ab102cc40450fe0b07ba25949f9470aa5fbf16e0db5b9de232a98c5cb6011497ba204ed5e33b6
|
@@ -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
|
@@ -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
|
data/lib/draftjs_html/version.rb
CHANGED
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.
|
4
|
+
version: 0.27.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:
|
11
|
+
date: 2023-01-10 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
|