editor_js 0.2.4 → 0.3.3

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: 971be8f7a5bcc50f90032ad0d28e31e1501d578240aa433c75eb9a22e214c023
4
- data.tar.gz: c251c0c3f39a2b1159e3af404dd0f84c2b9a393eb966aa2827f0c9431b31cc30
3
+ metadata.gz: 78823d325e66419e62e84adde1e8ec37586db12f9bbfb35482ccb34187dc2799
4
+ data.tar.gz: 47c8ff8f3a588bb6418e0118bca21f183aecf3802e683078f2b2019b565e42f4
5
5
  SHA512:
6
- metadata.gz: 274b5f08751e2c5432db9eb6c74c85260a580dfcdab3747048f35f99b399b66f12c3e3936fc29e0256518ec6505a68ebad862066699ac69fe12fb5df5fd95e52
7
- data.tar.gz: 13cd21c912b10d91de9ac2558f98a41049b6e326e2bad5f4f705fb7e7968cb55831144d74d02637dfa3bf9a664ae143d39fd8d67c023a268bf83cc1004faa4d7
6
+ metadata.gz: 50a8ba307aa9a078f0e50e8364503c5c917fc429d73d5eebe134e2152493ce55d69e8301fb5c9121ce6a6098d6931372e843f59c564b2e802ef3bda9cb43fa12
7
+ data.tar.gz: 723fa09aa421e41880ddab811ee431814c9e655ef95ab0dd6fc94a3ebe790d52b1422a6189eb38f41447b743cfce1f96e1d7a27b749fc4af17c33dfcb8d0de0a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- editor_js (0.2.4)
4
+ editor_js (0.3.3)
5
5
  actionview (>= 4)
6
6
  activesupport (>= 4)
7
7
  coderay (~> 1.1, >= 1.1.2)
@@ -13,42 +13,42 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- actionview (6.0.2.1)
17
- activesupport (= 6.0.2.1)
16
+ actionview (6.0.3.2)
17
+ activesupport (= 6.0.3.2)
18
18
  builder (~> 3.1)
19
19
  erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activesupport (6.0.2.1)
22
+ activesupport (6.0.3.2)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 0.7, < 2)
25
25
  minitest (~> 5.1)
26
26
  tzinfo (~> 1.1)
27
- zeitwerk (~> 2.2)
27
+ zeitwerk (~> 2.2, >= 2.2.2)
28
28
  addressable (2.7.0)
29
29
  public_suffix (>= 2.0.2, < 5.0)
30
30
  ast (2.4.0)
31
31
  builder (3.2.4)
32
32
  coderay (1.1.2)
33
- concurrent-ruby (1.1.5)
34
- crass (1.0.5)
33
+ concurrent-ruby (1.1.6)
34
+ crass (1.0.6)
35
35
  diff-lcs (1.3)
36
36
  docile (1.3.2)
37
37
  erubi (1.9.0)
38
38
  htmlentities (4.3.4)
39
- i18n (1.7.0)
39
+ i18n (1.8.3)
40
40
  concurrent-ruby (~> 1.0)
41
41
  jaro_winkler (1.5.4)
42
42
  json (2.3.0)
43
43
  json-schema (2.8.1)
44
44
  addressable (>= 2.4)
45
- loofah (2.4.0)
45
+ loofah (2.6.0)
46
46
  crass (~> 1.0.2)
47
47
  nokogiri (>= 1.5.9)
48
48
  method_source (0.9.2)
49
49
  mini_portile2 (2.4.0)
50
- minitest (5.13.0)
51
- nokogiri (1.10.7)
50
+ minitest (5.14.1)
51
+ nokogiri (1.10.10)
52
52
  mini_portile2 (~> 2.4.0)
53
53
  nokogumbo (2.0.2)
54
54
  nokogiri (~> 1.8, >= 1.8.4)
@@ -58,14 +58,14 @@ GEM
58
58
  pry (0.12.2)
59
59
  coderay (~> 1.1.0)
60
60
  method_source (~> 0.9.0)
61
- public_suffix (4.0.1)
61
+ public_suffix (4.0.5)
62
62
  rails-dom-testing (2.0.3)
63
63
  activesupport (>= 4.2.0)
64
64
  nokogiri (>= 1.6)
65
65
  rails-html-sanitizer (1.3.0)
66
66
  loofah (~> 2.3)
67
67
  rainbow (3.0.0)
68
- rake (10.5.0)
68
+ rake (13.0.1)
69
69
  redcarpet (3.5.0)
70
70
  rspec (3.9.0)
71
71
  rspec-core (~> 3.9.0)
@@ -88,7 +88,7 @@ GEM
88
88
  ruby-progressbar (~> 1.7)
89
89
  unicode-display_width (>= 1.4.0, < 1.7)
90
90
  ruby-progressbar (1.10.1)
91
- sanitize (5.1.0)
91
+ sanitize (5.2.1)
92
92
  crass (~> 1.0.2)
93
93
  nokogiri (>= 1.8.0)
94
94
  nokogumbo (~> 2.0)
@@ -98,10 +98,10 @@ GEM
98
98
  simplecov-html (~> 0.10.0)
99
99
  simplecov-html (0.10.2)
100
100
  thread_safe (0.3.6)
101
- tzinfo (1.2.6)
101
+ tzinfo (1.2.7)
102
102
  thread_safe (~> 0.1)
103
103
  unicode-display_width (1.6.0)
104
- zeitwerk (2.2.2)
104
+ zeitwerk (2.3.1)
105
105
 
106
106
  PLATFORMS
107
107
  ruby
@@ -110,10 +110,10 @@ DEPENDENCIES
110
110
  bundler (~> 2.0)
111
111
  editor_js!
112
112
  pry (~> 0.12.2)
113
- rake (~> 10.0)
113
+ rake (~> 13.0)
114
114
  rspec (~> 3.0)
115
115
  rubocop (~> 0.77.0)
116
116
  simplecov (~> 0.17.1)
117
117
 
118
118
  BUNDLED WITH
119
- 2.0.2
119
+ 2.1.4
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'redcarpet', '~> 3.5'
34
34
  spec.add_dependency 'coderay', '~> 1.1', '>= 1.1.2'
35
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  end
@@ -24,6 +24,7 @@ require 'editor_js/blocks/paragraph_block'
24
24
  require 'editor_js/blocks/qiniu_image_block'
25
25
  require 'editor_js/blocks/quote_block'
26
26
  require 'editor_js/blocks/table_block'
27
+ require 'editor_js/blocks/attaches_block'
27
28
  require 'editor_js/document'
28
29
 
29
30
  module EditorJs
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EditorJs
4
+ module Blocks
5
+ class AttachesBlock < Base
6
+ include ActiveSupport::NumberHelper
7
+
8
+ def schema
9
+ YAML.safe_load(<<~YAML)
10
+ type: object
11
+ additionalProperties: false
12
+ properties:
13
+ file:
14
+ type: object
15
+ additionalProperties: false
16
+ properties:
17
+ url:
18
+ type: string
19
+ name:
20
+ type: string
21
+ type:
22
+ type: string
23
+ size:
24
+ type: number
25
+ title:
26
+ type: string
27
+ required:
28
+ - file
29
+ YAML
30
+ end
31
+
32
+ EXTENSIONS = {
33
+ 'doc' => '#3e74da',
34
+ 'docx' => '#3e74da',
35
+ 'odt' => '#3e74da',
36
+ 'pdf' => '#d47373',
37
+ 'rtf' => '#656ecd',
38
+ 'tex' => '#5a5a5b',
39
+ 'txt' => '#5a5a5b',
40
+ 'pptx' => '#e07066',
41
+ 'ppt' => '#e07066',
42
+ 'mp3' => '#eab456',
43
+ 'mp4' => '#f676a6',
44
+ 'xls' => '#3f9e64',
45
+ 'html' => '#2988f0',
46
+ 'htm' => '#2988f0',
47
+ 'png' => '#f676a6',
48
+ 'jpg' => '#f67676',
49
+ 'jpeg' => '#f67676',
50
+ 'gif' => '#f6af76',
51
+ 'zip' => '#4f566f',
52
+ 'rar' => '#4f566f',
53
+ 'exe' => '#e26f6f',
54
+ 'svg' => '#bf5252',
55
+ 'key' => '#e07066',
56
+ 'sketch' => '#df821c',
57
+ 'ai' => '#df821c',
58
+ 'psd' => '#388ae5',
59
+ 'dmg' => '#e26f6f',
60
+ 'json' => '#2988f0',
61
+ 'csv' => '#3f9e64'
62
+ }
63
+
64
+ ICONS = {
65
+ file_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="40"><path d="M17 0l15 14V3v34a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3V3a3 3 0 0 1 3-3h20-6zm0 2H3a1 1 0 0 0-1 1v34a1 1 0 0 0 1 1h26a1 1 0 0 0 1-1V14H17V2zm2 10h7.926L19 4.602V12z"></path></svg>',
66
+ custom_file_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="40"><g fill="#A8ACB8" fill-rule="evenodd"><path fill-rule="nonzero" d="M17 0l15 14V3v34a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3V3a3 3 0 0 1 3-3h20-6zm0 2H3a1 1 0 0 0-1 1v34a1 1 0 0 0 1 1h26a1 1 0 0 0 1-1V14H17V2zm2 10h7.926L19 4.602V12z"></path><path d="M7 22h18v2H7zm0 4h18v2H7zm0 4h18v2H7z"></path></g></svg>',
67
+ download_icon: '<svg xmlns="http://www.w3.org/2000/svg" width="17pt" height="17pt" viewBox="0 0 17 17"><path d="M9.457 8.945V2.848A.959.959 0 0 0 8.5 1.89a.959.959 0 0 0-.957.957v6.097L4.488 5.891a.952.952 0 0 0-1.351 0 .952.952 0 0 0 0 1.351l4.687 4.688a.955.955 0 0 0 1.352 0l4.687-4.688a.952.952 0 0 0 0-1.351.952.952 0 0 0-1.351 0zM3.59 14.937h9.82a.953.953 0 0 0 .953-.957.952.952 0 0 0-.953-.953H3.59a.952.952 0 0 0-.953.953c0 .532.425.957.953.957zm0 0" fill-rule="evenodd"></path></svg>'
68
+ }
69
+
70
+ def render(_options = {})
71
+ file_info = data['file']
72
+ title = data['title']
73
+ extension = file_info['name']&.split('.')&.last
74
+ extension = '' unless EXTENSIONS.key?(extension)
75
+
76
+ content_tag :div, class: css_name do
77
+ html_str = content_tag :div, class: "#{css_name}__file-icon", data: {extension: extension}, style: "color: #{EXTENSIONS[extension]};" do
78
+ (EXTENSIONS[extension] ? ICONS[:file_icon] : ICONS[:custom_file_icon]).html_safe
79
+ end
80
+
81
+ html_str += content_tag :div, class: "#{css_name}__file-info" do
82
+ [
83
+ content_tag(:div, title, class: "#{css_name}__title"),
84
+ content_tag(:div, number_to_human_size(file_info['size']), class: "#{css_name}__size")
85
+ ].join().html_safe
86
+ end
87
+
88
+ html_str += content_tag :a, class: "#{css_name}__download-button", href: file_info['url'], target: '_blank', rel: 'nofollow noindex noreferrer' do
89
+ ICONS[:download_icon].html_safe
90
+ end
91
+ html_str.html_safe
92
+ end
93
+ end
94
+
95
+ def sanitize!
96
+ data['title'] = Sanitize.fragment(data['title'], remove_contents: true).strip
97
+ file_info = data['file'] || {}
98
+ file_info.each do |key, val|
99
+ break if key == 'size'
100
+
101
+ file_info[key] = Sanitize.fragment(val, remove_contents: true).strip
102
+ end
103
+ data['file'] = file_info
104
+ end
105
+
106
+ def plain
107
+ decode_html data['title'].strip
108
+ end
109
+ end
110
+ end
111
+ end
@@ -28,7 +28,7 @@ module EditorJs
28
28
  data['items'].map do |item|
29
29
  content_tag(:div, class: css_name('__warrper')) do
30
30
  html_str = content_tag(:input, nil, type: 'checkbox', disabled: true, checked: item['checked'])
31
- html_str += content_tag(:label, item['text'])
31
+ html_str += content_tag(:label, item['text'].html_safe)
32
32
  html_str.html_safe
33
33
  end.html_safe
34
34
  end.join.html_safe
@@ -36,8 +36,23 @@ module EditorJs
36
36
  end
37
37
 
38
38
  def sanitize!
39
+ safe_tags = {
40
+ 'b' => nil,
41
+ 'i' => nil,
42
+ 'u' => ['class'],
43
+ 'del' => ['class'],
44
+ 'a' => ['href'],
45
+ 'mark' => ['class'],
46
+ 'code' => ['class']
47
+ }
48
+
39
49
  data['items'].each do |item|
40
- item['text'] = Sanitize.fragment(item['text'], remove_contents: true).strip
50
+ item['text'] = Sanitize.fragment(
51
+ item['text'],
52
+ elements: safe_tags.keys,
53
+ attributes: safe_tags.select {|k, v| v},
54
+ remove_contents: true
55
+ )
41
56
  end
42
57
  end
43
58
 
@@ -13,6 +13,12 @@ module EditorJs
13
13
  level:
14
14
  type: number
15
15
  enum: [1,2,3,4,5,6]
16
+ alignment:
17
+ type: string
18
+ enum:
19
+ - align-left
20
+ - align-center
21
+ - align-right
16
22
  required:
17
23
  - text
18
24
  - level
@@ -20,7 +26,15 @@ module EditorJs
20
26
  end
21
27
 
22
28
  def render(_options = {})
23
- content_tag(:"h#{data['level']}", data['text'].html_safe, class: css_name)
29
+ alignment = data['alignment']
30
+ class_name_str = css_name
31
+ if alignment.present?
32
+ class_name_str = [
33
+ class_name_str,
34
+ css_name("__#{alignment}")
35
+ ].join(' ')
36
+ end
37
+ content_tag(:"h#{data['level']}", data['text'].html_safe, class: class_name_str)
24
38
  end
25
39
 
26
40
  def sanitize!
@@ -33,6 +33,8 @@ module EditorJs
33
33
  safe_tags = {
34
34
  'b' => nil,
35
35
  'i' => nil,
36
+ 'u' => ['class'],
37
+ 'del' => ['class'],
36
38
  'a' => ['href'],
37
39
  'mark' => ['class'],
38
40
  'code' => ['class']
@@ -10,17 +10,33 @@ module EditorJs
10
10
  properties:
11
11
  text:
12
12
  type: string
13
+ alignment:
14
+ type: string
15
+ enum:
16
+ - align-left
17
+ - align-center
18
+ - align-right
13
19
  YAML
14
20
  end
15
21
 
16
22
  def render(_options = {})
17
- content_tag(:div, class: css_name) { data['text'].html_safe }
23
+ alignment = data['alignment']
24
+ class_name_str = css_name
25
+ if alignment.present?
26
+ class_name_str = [
27
+ class_name_str,
28
+ css_name("__#{alignment}")
29
+ ].join(' ')
30
+ end
31
+ content_tag(:div, class: class_name_str) { data['text'].html_safe }
18
32
  end
19
33
 
20
34
  def sanitize!
21
35
  safe_tags = {
22
36
  'b' => nil,
23
37
  'i' => nil,
38
+ 'u' => ['class'],
39
+ 'del' => ['class'],
24
40
  'a' => ['href'],
25
41
  'mark' => ['class'],
26
42
  'code' => ['class']
@@ -32,9 +32,12 @@ module EditorJs
32
32
  safe_tags = {
33
33
  'b' => nil,
34
34
  'i' => nil,
35
+ 'u' => ['class'],
36
+ 'del' => ['class'],
35
37
  'a' => ['href'],
36
38
  'mark' => ['class'],
37
- 'code' => ['class']
39
+ 'code' => ['class'],
40
+ 'br' => nil
38
41
  }
39
42
 
40
43
  %w(text caption).each do |key|
@@ -42,7 +45,7 @@ module EditorJs
42
45
  data[key],
43
46
  elements: safe_tags.keys,
44
47
  attributes: safe_tags.select {|k, v| v},
45
- remove_contents: true
48
+ remove_contents: false
46
49
  )
47
50
  end
48
51
  data['alignment'] = Sanitize.fragment(data['alignment'], remove_contents: true)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EditorJs
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.3'
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.2.4
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -140,14 +140,14 @@ dependencies:
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '10.0'
143
+ version: '13.0'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '10.0'
150
+ version: '13.0'
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: rspec
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +182,7 @@ files:
182
182
  - bin/setup
183
183
  - editor_js.gemspec
184
184
  - lib/editor_js.rb
185
+ - lib/editor_js/blocks/attaches_block.rb
185
186
  - lib/editor_js/blocks/base.rb
186
187
  - lib/editor_js/blocks/checklist_block.rb
187
188
  - lib/editor_js/blocks/code_block.rb