editor_js 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -12
- data/editor_js.gemspec +1 -1
- data/lib/editor_js.rb +1 -0
- data/lib/editor_js/blocks/attaches_block.rb +111 -0
- data/lib/editor_js/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acb250e53e4ac2ca1a58b57158be0c202b0bfbdbd139a6c1d42960448f429646
|
4
|
+
data.tar.gz: 945fd7ee5b68505e3e8410f63abba4d282327a39fe1ab0023fd4bca2e56439e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4faa65d0158ea4e23d19a6c4fc9ddae3e919e5b5e37a3635451fd00ad2656f8af9b9a149f50ebba19b05f11f149747f0ea88ff052767c756e2ac30180e37076a
|
7
|
+
data.tar.gz: f55ca3cae24b0d553abdf9fecb96234e722c2410fc099719f4d5140258a380e341abb5f59c1afc6f32f62950c4988f8470d8fc6ce81aa46f5c0e019032a42b5c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
editor_js (0.
|
4
|
+
editor_js (0.3.0)
|
5
5
|
actionview (>= 4)
|
6
6
|
activesupport (>= 4)
|
7
7
|
coderay (~> 1.1, >= 1.1.2)
|
@@ -13,13 +13,13 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
actionview (6.0.2.
|
17
|
-
activesupport (= 6.0.2.
|
16
|
+
actionview (6.0.2.2)
|
17
|
+
activesupport (= 6.0.2.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.
|
22
|
+
activesupport (6.0.2.2)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
24
|
i18n (>= 0.7, < 2)
|
25
25
|
minitest (~> 5.1)
|
@@ -30,13 +30,13 @@ GEM
|
|
30
30
|
ast (2.4.0)
|
31
31
|
builder (3.2.4)
|
32
32
|
coderay (1.1.2)
|
33
|
-
concurrent-ruby (1.1.
|
34
|
-
crass (1.0.
|
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.
|
39
|
+
i18n (1.8.2)
|
40
40
|
concurrent-ruby (~> 1.0)
|
41
41
|
jaro_winkler (1.5.4)
|
42
42
|
json (2.3.0)
|
@@ -47,8 +47,8 @@ GEM
|
|
47
47
|
nokogiri (>= 1.5.9)
|
48
48
|
method_source (0.9.2)
|
49
49
|
mini_portile2 (2.4.0)
|
50
|
-
minitest (5.
|
51
|
-
nokogiri (1.10.
|
50
|
+
minitest (5.14.0)
|
51
|
+
nokogiri (1.10.9)
|
52
52
|
mini_portile2 (~> 2.4.0)
|
53
53
|
nokogumbo (2.0.2)
|
54
54
|
nokogiri (~> 1.8, >= 1.8.4)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
rails-html-sanitizer (1.3.0)
|
66
66
|
loofah (~> 2.3)
|
67
67
|
rainbow (3.0.0)
|
68
|
-
rake (
|
68
|
+
rake (13.0.1)
|
69
69
|
redcarpet (3.5.0)
|
70
70
|
rspec (3.9.0)
|
71
71
|
rspec-core (~> 3.9.0)
|
@@ -101,7 +101,7 @@ GEM
|
|
101
101
|
tzinfo (1.2.6)
|
102
102
|
thread_safe (~> 0.1)
|
103
103
|
unicode-display_width (1.6.0)
|
104
|
-
zeitwerk (2.
|
104
|
+
zeitwerk (2.3.0)
|
105
105
|
|
106
106
|
PLATFORMS
|
107
107
|
ruby
|
@@ -110,7 +110,7 @@ DEPENDENCIES
|
|
110
110
|
bundler (~> 2.0)
|
111
111
|
editor_js!
|
112
112
|
pry (~> 0.12.2)
|
113
|
-
rake (~>
|
113
|
+
rake (~> 13.0)
|
114
114
|
rspec (~> 3.0)
|
115
115
|
rubocop (~> 0.77.0)
|
116
116
|
simplecov (~> 0.17.1)
|
data/editor_js.gemspec
CHANGED
@@ -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", "~>
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
37
|
spec.add_development_dependency "rspec", "~> 3.0"
|
38
38
|
end
|
data/lib/editor_js.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-15 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: '
|
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: '
|
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
|