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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2787f8b3e0e47ff54da6cc6fc80525a8f5432cfbd3ee2525b88f60fe37469ad
4
- data.tar.gz: 72943f09ae8fe960555554f2d70bace6365d8c796608e845e547004b82619a8e
3
+ metadata.gz: 2bde34585f58bd8801fa2245cabcd3f21ac959e75aa38872ddc1109667045a1c
4
+ data.tar.gz: 69543e67908af715d8d287e5f9ee82a65da908c7fa5762b25c71f5b04d779ec7
5
5
  SHA512:
6
- metadata.gz: 67e53a8f0a64aa6feccb2890415c38fc828c8404ebef8d79d619a1479c07effab7ca367894d34046d1969d39411d7dfce89bac451e0ffd07201a97a94dea701a
7
- data.tar.gz: 455f764aa8dfaefe85bdabbc991f6fb6d401296f3e849d7e00fc92b744c0a3acdcc76e139a5a5f8ae6b2afc66bd83cd1e735decb52a039aec50224394fd04713
6
+ metadata.gz: ad0f0292a369902cf8b09367c2b20b68b54d454ff9fb338d63917868e952b9d128f1389c849895c45c95978f4d352e9855895f1cbfe3f910b54fbcf0e5a7c35d
7
+ data.tar.gz: 820748d8a5d178e547230aaacae0291b677f741abd29d481c5cc54ca7a42a331e392484169e804359e47c04f2d7f88cf79a536674dc8cb970fcd5f2fc3ddf686
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- editor_js (0.2.0)
4
+ editor_js (0.2.1)
5
5
  actionview (>= 4)
6
6
  activesupport (>= 4)
7
7
  coderay (~> 1.1, >= 1.1.2)
@@ -116,4 +116,4 @@ DEPENDENCIES
116
116
  simplecov (~> 0.17.1)
117
117
 
118
118
  BUNDLED WITH
119
- 2.1.0
119
+ 2.0.2
@@ -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
- @registry ||= {}
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 = @registry[block_data['type']]
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
- raise InvalidBlockDataError, "block type <#{block_data['type']}> doesn't match <#{type}>" unless block_data['type'] == type
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
@@ -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? ? @blocks.map(&:plain).join('. ') : ''
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EditorJs
2
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
3
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.2.0
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-17 00:00:00.000000000 Z
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview