ckeditor5 0.0.1 → 1.0.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 +21 -0
- data/README.md +94 -13
- data/lib/ckeditor5/rails/assets/assets_bundle.rb +94 -0
- data/lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb +76 -0
- data/lib/ckeditor5/rails/assets/webcomponent.mjs +603 -0
- data/lib/ckeditor5/rails/cdn/ckbox_bundle.rb +49 -0
- data/lib/ckeditor5/rails/cdn/ckeditor_bundle.rb +58 -0
- data/lib/ckeditor5/rails/cdn/helpers.rb +64 -0
- data/lib/ckeditor5/rails/cdn/url_generator.rb +38 -0
- data/lib/ckeditor5/rails/cloud/helpers.rb +13 -0
- data/lib/ckeditor5/rails/editor/helpers.rb +64 -0
- data/lib/ckeditor5/rails/editor/props.rb +61 -0
- data/lib/ckeditor5/rails/editor/props_plugin.rb +31 -0
- data/lib/ckeditor5/rails/engine.rb +33 -0
- data/lib/ckeditor5/rails/helpers.rb +13 -0
- data/lib/ckeditor5/rails/presets.rb +99 -0
- data/lib/ckeditor5/rails/semver.rb +19 -0
- data/lib/ckeditor5/rails/version.rb +5 -0
- data/lib/ckeditor5/rails.rb +12 -0
- data/lib/{ckeditor5.rb → ckeditor5_rails.rb} +1 -1
- metadata +39 -12
- data/.github/workflows/ruby.yml +0 -28
- data/.gitignore +0 -56
- data/Rakefile +0 -3
- data/ckeditor5.gemspec +0 -23
- data/lib/ckeditor5/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781d7cd0e2b9bb1ba9aed6f103dfeb8b9cd318970025b876a7baa792b3466d38
|
4
|
+
data.tar.gz: b2b19f8a7a549d66c1ea0ccde434a97b4b25912dd8cfe5e9e6b9e7bc512d7709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf87efd1b431a9fe2ebde09157946c268a1aeaf539c9c1dc31e8af887335b910909229da052af9f04550851750ff3b55e3f13cbd419b194d80d9b238184b71cf
|
7
|
+
data.tar.gz: b6bcf709b3cca9f23afef77bad824b8d5cf36d83cf1f8d00d3263f03228a9f7f4e52dda11b927b7f3885cacf73724b5b2a887d9af1dc73728179a61c21f75264
|
data/Gemfile
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
5
|
+
gem 'bundler', '~> 2.5', '>= 2.5.21'
|
6
|
+
gem 'rails', '~> 6.0', '>= 6.0.4'
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'brakeman', '~> 6.1', '>= 6.1.1', require: false
|
10
|
+
gem 'guard'
|
11
|
+
gem 'guard-bundler'
|
12
|
+
gem 'guard-rails'
|
13
|
+
gem 'rake', '~> 13.2', '>= 13.2.1'
|
14
|
+
gem 'rspec', '~> 3.13'
|
15
|
+
gem 'rubocop', '~> 1.66', require: false
|
16
|
+
gem 'rubocop-rails', '~> 2.26', '>= 2.26.2', require: false
|
17
|
+
gem 'rubocop-rails-omakase', '~> 1.0.0', require: false
|
18
|
+
end
|
19
|
+
|
20
|
+
group :test, :development do
|
21
|
+
gem 'capybara', '~> 3.40'
|
22
|
+
end
|
23
|
+
|
3
24
|
gemspec
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# CKEditor 5 Rails Integration
|
2
2
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
4
|
-

|
5
5
|
[](http://makeapullrequest.com)
|
6
6
|

|
7
7
|
[](https://github.com/Mati365/ckeditor5-rails/issues)
|
8
8
|
|
9
|
-
Unofficial CKEditor 5 Ruby on Rails integration.
|
9
|
+
Unofficial CKEditor 5 Ruby on Rails integration gem. Provides seamless integration of CKEditor 5 with Rails applications through web components and helper methods.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Installation
|
12
12
|
|
13
13
|
Add this line to your application's Gemfile:
|
14
14
|
|
@@ -16,20 +16,101 @@ Add this line to your application's Gemfile:
|
|
16
16
|
gem 'ckeditor5'
|
17
17
|
```
|
18
18
|
|
19
|
-
##
|
19
|
+
## Basic Usage
|
20
20
|
|
21
|
-
|
22
|
-
- [ ] Add support for CKEditor 5 Watchdog and Context.
|
23
|
-
- [ ] Add support for CKEditor 5 CDN and NPM packages.
|
24
|
-
- [ ] Add support for CKEditor 5 Collaboration.
|
25
|
-
- [ ] Add support for SSR.
|
21
|
+
### Presets
|
26
22
|
|
27
|
-
|
23
|
+
Override default preset configuration:
|
28
24
|
|
29
|
-
|
25
|
+
```rb
|
26
|
+
# config/initializers/ckeditor5.rb
|
27
|
+
|
28
|
+
CKEditor5::Rails::Engine.configure do |config|
|
29
|
+
config.presets.override :default do |preset|
|
30
|
+
preset.menubar visible: false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Create new preset:
|
36
|
+
|
37
|
+
```rb
|
38
|
+
# config/initializers/ckeditor5.rb
|
39
|
+
|
40
|
+
CKEditor5::Rails::Engine.configure do |config|
|
41
|
+
config.presets.define :custom do |preset|
|
42
|
+
shape :classic
|
43
|
+
|
44
|
+
menubar
|
45
|
+
|
46
|
+
toolbar :undo, :redo, :|, :heading, :|, :bold, :italic, :underline, :|,
|
47
|
+
:link, :insertImage, :ckbox, :mediaEmbed, :insertTable, :blockQuote, :|,
|
48
|
+
:bulletedList, :numberedList, :todoList, :outdent, :indent
|
49
|
+
|
50
|
+
plugins :AccessibilityHelp, :Autoformat, :AutoImage, :Autosave,
|
51
|
+
:BlockQuote, :Bold, :CKBox, :CKBoxImageEdit, :CloudServices,
|
52
|
+
:Essentials, :Heading, :ImageBlock, :ImageCaption, :ImageInline,
|
53
|
+
:ImageInsert, :ImageInsertViaUrl, :ImageResize, :ImageStyle,
|
54
|
+
:ImageTextAlternative, :ImageToolbar, :ImageUpload, :Indent,
|
55
|
+
:IndentBlock, :Italic, :Link, :LinkImage, :List, :ListProperties,
|
56
|
+
:MediaEmbed, :Paragraph, :PasteFromOffice, :PictureEditing,
|
57
|
+
:SelectAll, :Table, :TableCaption, :TableCellProperties,
|
58
|
+
:TableColumnResize, :TableProperties, :TableToolbar,
|
59
|
+
:TextTransformation, :TodoList, :Underline, :Undo, :Base64UploadAdapter
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Somewhere in your view
|
64
|
+
|
65
|
+
= ckeditor5_editor preset: :custom
|
66
|
+
```
|
67
|
+
|
68
|
+
### CDN Configuration
|
69
|
+
|
70
|
+
#### jsDelivr (Default)
|
71
|
+
|
72
|
+
```slim
|
73
|
+
- content_for :head
|
74
|
+
= ckeditor5_assets version: '43.2.0'
|
75
|
+
```
|
76
|
+
|
77
|
+
#### unpkg
|
78
|
+
|
79
|
+
```slim
|
80
|
+
- content_for :head
|
81
|
+
= ckeditor5_unpkg_assets version: '43.2.0'
|
82
|
+
```
|
83
|
+
|
84
|
+
#### CKEditor Cloud
|
85
|
+
|
86
|
+
It's available only for licensed users.
|
87
|
+
|
88
|
+
```slim
|
89
|
+
- content_for :head
|
90
|
+
= ckeditor5_assets version: '43.2.0', license_key: 'YOUR-LICENSE-KEY'
|
91
|
+
```
|
92
|
+
|
93
|
+
### Editor type
|
94
|
+
|
95
|
+
#### Classic Editor
|
96
|
+
|
97
|
+
```slim
|
98
|
+
- content_for :head
|
99
|
+
= ckeditor5_assets version: '43.2.0' # Optional: translations: [ :pl, :es ]
|
100
|
+
|
101
|
+
= ckeditor5_editor
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Multiroot Editor
|
30
105
|
|
31
106
|
```slim
|
32
|
-
=
|
107
|
+
= ckeditor5_editor type: :multiroot do
|
108
|
+
= ckeditor5_toolbar
|
109
|
+
br
|
110
|
+
= ckeditor5_editable 'editable-a' do
|
111
|
+
| This is a toolbar editable
|
112
|
+
br
|
113
|
+
= ckeditor5_editable 'editable-b'
|
33
114
|
```
|
34
115
|
|
35
116
|
## License
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module'
|
4
|
+
|
5
|
+
module CKEditor5::Rails::Assets
|
6
|
+
class AssetsBundle
|
7
|
+
def initialize
|
8
|
+
validate_implementation!
|
9
|
+
end
|
10
|
+
|
11
|
+
def empty?
|
12
|
+
scripts.empty? && stylesheets.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def translations_scripts
|
16
|
+
scripts.select(&:translation?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def preloads
|
20
|
+
stylesheets + scripts.map(&:url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def <<(other)
|
24
|
+
raise TypeError, 'other must be an instance of AssetsBundle' unless other.is_a?(AssetsBundle)
|
25
|
+
|
26
|
+
@scripts = scripts + other.scripts
|
27
|
+
@stylesheets = stylesheets + other.stylesheets
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def validate_implementation!
|
33
|
+
%i[scripts stylesheets].each do |method|
|
34
|
+
unless respond_to?(method, true)
|
35
|
+
raise NotImplementedError, "#{self.class} must implement the ##{method} method"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class JSExportsMeta
|
42
|
+
attr_reader :url, :import_meta
|
43
|
+
|
44
|
+
delegate :esm?, :window?, :import_name, :window_name, :import_as, to: :import_meta
|
45
|
+
|
46
|
+
def initialize(url, translation: false, **import_options)
|
47
|
+
@url = url
|
48
|
+
@import_meta = JSImportMeta.new(**import_options)
|
49
|
+
@translation = translation
|
50
|
+
end
|
51
|
+
|
52
|
+
def translation?
|
53
|
+
@translation
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class JSImportMeta
|
58
|
+
attr_reader :import_as, :import_name, :window_name
|
59
|
+
|
60
|
+
def initialize(import_as: nil, import_name: nil, window_name: nil)
|
61
|
+
validate_arguments!(import_as, import_name, window_name)
|
62
|
+
@import_as = import_as
|
63
|
+
@import_name = import_name
|
64
|
+
@window_name = window_name
|
65
|
+
end
|
66
|
+
|
67
|
+
def esm?
|
68
|
+
import_name.present?
|
69
|
+
end
|
70
|
+
|
71
|
+
def window?
|
72
|
+
window_name.present?
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_h
|
76
|
+
{
|
77
|
+
import_as: import_as,
|
78
|
+
import_name: import_name,
|
79
|
+
window_name: window_name
|
80
|
+
}.compact
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def validate_arguments!(import_as, import_name, window_name)
|
86
|
+
if import_name.nil? && window_name.nil?
|
87
|
+
raise ArgumentError,
|
88
|
+
'import_name or window_name must be present'
|
89
|
+
end
|
90
|
+
|
91
|
+
raise ArgumentError, 'import_name required when import_as is present' if import_as && import_name.nil?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'action_view'
|
5
|
+
|
6
|
+
module CKEditor5::Rails::Assets
|
7
|
+
WEBCOMPONENT_SOURCE = File.read(File.join(__dir__, 'webcomponent.mjs')).html_safe
|
8
|
+
|
9
|
+
class AssetsBundleHtmlSerializer
|
10
|
+
include ActionView::Helpers::TagHelper
|
11
|
+
|
12
|
+
attr_reader :bundle
|
13
|
+
|
14
|
+
def initialize(bundle)
|
15
|
+
raise TypeError, 'bundle must be an instance of AssetsBundle' unless bundle.is_a?(AssetsBundle)
|
16
|
+
|
17
|
+
@bundle = bundle
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_html
|
21
|
+
safe_join([
|
22
|
+
preload_tags,
|
23
|
+
styles_tags,
|
24
|
+
window_scripts_tags,
|
25
|
+
scripts_import_map_tag,
|
26
|
+
web_component_tag
|
27
|
+
])
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.url_resource_preload_type(url)
|
31
|
+
case File.extname(url)
|
32
|
+
when '.js' then 'script'
|
33
|
+
when '.css' then 'style'
|
34
|
+
else 'fetch'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def web_component_tag
|
41
|
+
@web_component_tag ||= tag.script(WEBCOMPONENT_SOURCE, type: 'module', nonce: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def window_scripts_tags
|
45
|
+
@window_scripts_tags ||= safe_join(bundle.scripts.filter_map do |script|
|
46
|
+
tag.script(src: script.url, nonce: true, async: true) if script.window?
|
47
|
+
end)
|
48
|
+
end
|
49
|
+
|
50
|
+
def scripts_import_map_tag
|
51
|
+
return @scripts_import_map_tag if defined?(@scripts_import_map_tag)
|
52
|
+
|
53
|
+
import_map = bundle.scripts.each_with_object({}) do |script, map|
|
54
|
+
map[script.import_name] = script.url if script.esm?
|
55
|
+
end
|
56
|
+
|
57
|
+
@scripts_import_map_tag = tag.script(
|
58
|
+
{ imports: import_map }.to_json.html_safe,
|
59
|
+
type: 'importmap',
|
60
|
+
nonce: true
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def styles_tags
|
65
|
+
@styles_tags ||= safe_join(bundle.stylesheets.map do |url|
|
66
|
+
tag.link(href: url, rel: 'stylesheet')
|
67
|
+
end)
|
68
|
+
end
|
69
|
+
|
70
|
+
def preload_tags
|
71
|
+
@preload_tags ||= safe_join(bundle.preloads.map do |url|
|
72
|
+
tag.link(href: url, rel: 'preload', as: self.class.url_resource_preload_type(url))
|
73
|
+
end)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|