editor_js 0.2.0 → 0.2.1
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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/editor_js/blocks/base.rb +12 -4
- data/lib/editor_js/document.rb +3 -1
- data/lib/editor_js/version.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bde34585f58bd8801fa2245cabcd3f21ac959e75aa38872ddc1109667045a1c
|
4
|
+
data.tar.gz: 69543e67908af715d8d287e5f9ee82a65da908c7fa5762b25c71f5b04d779ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad0f0292a369902cf8b09367c2b20b68b54d454ff9fb338d63917868e952b9d128f1389c849895c45c95978f4d352e9855895f1cbfe3f910b54fbcf0e5a7c35d
|
7
|
+
data.tar.gz: 820748d8a5d178e547230aaacae0291b677f741abd29d481c5cc54ca7a42a331e392484169e804359e47c04f2d7f88cf79a536674dc8cb970fcd5f2fc3ddf686
|
data/Gemfile.lock
CHANGED
@@ -7,6 +7,8 @@ module EditorJs
|
|
7
7
|
include ActionView::Helpers::TextHelper
|
8
8
|
include ERB::Util
|
9
9
|
|
10
|
+
require 'active_support/core_ext/string/inflections'
|
11
|
+
|
10
12
|
# ActionView::Helpers::TagHelper requires output_buffer accessor
|
11
13
|
attr_accessor :raw, :output_buffer
|
12
14
|
|
@@ -62,26 +64,32 @@ module EditorJs
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def self.inherited(parent)
|
65
|
-
|
66
|
-
@registry[parent.type] = parent
|
67
|
+
::EditorJs::Blocks::Base.registry[parent.type] = parent
|
67
68
|
super
|
68
69
|
end
|
69
70
|
|
70
71
|
def self.load(block_data)
|
71
72
|
block_data = JSON.parse(block_data) unless block_data.is_a?(Hash)
|
72
|
-
klass =
|
73
|
+
klass = ::EditorJs::Blocks::Base.registry[block_data['type'].underscore]
|
73
74
|
raise InvalidBlockTypeError, block_data['type'] if klass.nil?
|
74
75
|
|
75
76
|
klass.new(block_data)
|
76
77
|
end
|
77
78
|
|
79
|
+
def self.registry
|
80
|
+
@registry ||= {}
|
81
|
+
end
|
82
|
+
|
78
83
|
private
|
79
84
|
|
80
85
|
def cast_block_data_to_hash(block_data)
|
81
86
|
raise InvalidBlockDataError, block_data unless block_data.is_a?(Hash)
|
82
87
|
|
83
88
|
block_data = block_data.deep_stringify_keys
|
84
|
-
|
89
|
+
unless block_data['type'].underscore == type
|
90
|
+
raise InvalidBlockDataError,\
|
91
|
+
"block type <#{block_data['type']}> doesn't match <#{type}>"
|
92
|
+
end
|
85
93
|
|
86
94
|
block_data
|
87
95
|
rescue JSON::ParserError => _e
|
data/lib/editor_js/document.rb
CHANGED
@@ -46,7 +46,9 @@ module EditorJs
|
|
46
46
|
def plain
|
47
47
|
return @renderred_plain if instance_variable_defined?(:@renderred_plain)
|
48
48
|
|
49
|
-
@renderred_plain = valid?
|
49
|
+
@renderred_plain = valid? && @blocks.map(&:plain).select do |text|
|
50
|
+
text if text.present?
|
51
|
+
end.join('. ') || ''
|
50
52
|
end
|
51
53
|
|
52
54
|
def output
|
data/lib/editor_js/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|