editor_js 0.3.6.1 → 0.4.0

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
  SHA256:
3
- metadata.gz: cc68a5b437f52314867a5c04726164825c17d4fae12fa60afe079903b776b9ad
4
- data.tar.gz: ab4234218fdea2e6fe97f9860366a4122e3553535b0941175ee06ef262538311
3
+ metadata.gz: 39729360ee7471d852aa04a598687de0afedb79cd1cf56a2196731bb21c85a5e
4
+ data.tar.gz: d5781ef2b0f8f48d13386b06e72c5bab6f9bd35dfa1ef84b406ab3cfdc7c7d57
5
5
  SHA512:
6
- metadata.gz: 3ce06f481e7c0578c6405466ee84a757c4acb2ac7a90c277f4f19bbdfb6f102bb98ea027cf93cf345f0d9f1d0aa42a6d0953fc60c73800b3d50d0f2dae27b32b
7
- data.tar.gz: 51a76b6c4af5c00d99752cb06d375b91e74a3be4abef4f325a40b9256ef1a99c321fb74757d3a487dde4ae902bd957cb0689a77a2b4c4d1a365df5e373dfb657
6
+ metadata.gz: 1dbdc91120a843bac1ceb161e9b1b2de3ee6c7e6fd33a3c2e925cc8cf3fedae7e2e8601379f9d14b0fc5a986c0df1d1eb53f68808775b7151aea0538838dc85e
7
+ data.tar.gz: 8431e9d06fab59d6e630483ad99176bc72033d58a54bdc2a42214a3c535c7496e2f22c57f6fd5c33f46fe20410efc1dbbd0952a8d276fb8cf24d5ad889787628
data/Changes.md ADDED
@@ -0,0 +1,6 @@
1
+ # EditorJS Changes
2
+
3
+ ## 0.4.0
4
+
5
+ - only discard invalid blocks instead of marking invalid to the whole document.
6
+ - support customized invalid block renderer
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- editor_js (0.3.6.1)
4
+ editor_js (0.4.0)
5
5
  actionview (>= 4)
6
6
  activesupport (>= 4)
7
7
  commonmarker (~> 0.21.2)
8
8
  htmlentities (~> 4.3, >= 4.3.4)
9
9
  json-schema (~> 2)
10
10
  rouge (~> 3.26)
11
- sanitize (~> 6.0)
11
+ sanitize (~> 6.0.0)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -32,6 +32,35 @@ doc.output # [Hash] return sanitized data
32
32
 
33
33
  ```
34
34
 
35
+ **Capture invalid block:**
36
+
37
+ ```ruby
38
+ class MyInvalidBlockRender do
39
+ def initialize(raw)
40
+ @raw = raw
41
+ # can record/log invalid block from here:
42
+ # Sentry.capture_message "invalid block: #{raw}"
43
+ end
44
+
45
+ def valid?
46
+ false
47
+ end
48
+
49
+ def render
50
+ '<div>invalid block</div>'
51
+ end
52
+
53
+ def plain; end
54
+ def output; {} end
55
+ end
56
+
57
+ doc = EditorJs::Document.new(editor_js_output, invalid_block_renderer: MyInvalidBlockRender)
58
+ doc.render # [String] render HTML for display
59
+ doc.plain # [String] render text for full-text searching
60
+ doc.output # [Hash] return sanitized data
61
+
62
+ ```
63
+
35
64
  ## Development
36
65
 
37
66
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/editor_js.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'htmlentities', '~> 4.3', '>= 4.3.4'
32
32
  spec.add_dependency 'json-schema', '~> 2'
33
33
  spec.add_dependency 'rouge', '~> 3.26'
34
- spec.add_dependency 'sanitize', '~> 6.0'
34
+ spec.add_dependency 'sanitize', '~> 6.0.0'
35
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
36
  spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -21,8 +21,9 @@ module EditorJs
21
21
  - version
22
22
  YAML
23
23
 
24
- def initialize(str_or_hash)
24
+ def initialize(str_or_hash, invalid_block_renderer: nil)
25
25
  str_or_hash = JSON.parse(str_or_hash) unless str_or_hash.is_a?(Hash)
26
+ @invalid_block_renderer = invalid_block_renderer
26
27
  @content = str_or_hash
27
28
  @blocks = []
28
29
  end
@@ -33,12 +34,11 @@ module EditorJs
33
34
  @valid = JSON::Validator.validate(SCHEMA, @content)
34
35
  return false unless @valid
35
36
 
36
- blocks = @content['blocks'].map do |blk_data|
37
- EditorJs::Blocks::Base.load(blk_data)
38
- end
39
- @valid = blocks.all?(&:valid?)
40
- @blocks = blocks if @valid
41
- @valid
37
+ @blocks = @content['blocks'].map do |blk_data|
38
+ blk = EditorJs::Blocks::Base.load(blk_data)
39
+ blk.valid? ? blk : @invalid_block_renderer&.new(blk_data)
40
+ end.compact
41
+ @valid = @blocks.count.positive?
42
42
  end
43
43
 
44
44
  def render
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EditorJs
4
- VERSION = '0.3.6.1'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: editor_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '6.0'
109
+ version: 6.0.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '6.0'
116
+ version: 6.0.0
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: bundler
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +167,7 @@ files:
167
167
  - ".rspec"
168
168
  - ".rubocop.yml"
169
169
  - ".travis.yml"
170
+ - Changes.md
170
171
  - Gemfile
171
172
  - Gemfile.lock
172
173
  - LICENSE.txt