ckeditor5 1.5.3 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/README.md +32 -0
- data/lib/ckeditor5/rails/cdn/helpers.rb +2 -1
- data/lib/ckeditor5/rails/editor/helpers.rb +22 -9
- data/lib/ckeditor5/rails/hooks/form.rb +47 -13
- data/lib/ckeditor5/rails/version.rb +1 -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: 4936a08e0bc4d84574d2f692c6efe59e683cac2be8d87cc2ef51cdd2ad7846e8
|
4
|
+
data.tar.gz: d1a65da5eb7795fcd85bb258a067afb6990c6f6f7ea6fe5359e11cc767883139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9590a33cd9a2caf0c191255d7efa154a7bbbde8857ee8b40bf19cf9ae03411220230cbc5cf1f608aabf1ba3dcb8a49cb9ceb768553a8655efd139c0e9e98c110
|
7
|
+
data.tar.gz: 2d2c6853bf4a09e01da3fb83f44ed711b8ee96de4bd9e2bf0e47c1519b04169507e56e403f012731dd6c402c3e7b8196b3e42cc833d6689c3bc6dbe2e6c5abfc
|
data/Gemfile
CHANGED
@@ -6,15 +6,11 @@ gem 'bundler', '~> 2.5', '>= 2.5.21'
|
|
6
6
|
|
7
7
|
group :development do
|
8
8
|
gem 'brakeman', '~> 6.1', '>= 6.1.1', require: false
|
9
|
-
gem 'rails', '~> 7.0', '>= 7.0.0'
|
10
9
|
gem 'rake', '~> 13.2', '>= 13.2.1'
|
11
10
|
gem 'rspec', '~> 3.13'
|
12
|
-
gem 'rspec-expectations', '~> 3.13'
|
13
|
-
gem 'rspec-rails', '~> 7.0'
|
14
11
|
gem 'rubocop', '~> 1.66', require: false
|
15
12
|
gem 'rubocop-rails', '~> 2.26', '>= 2.26.2', require: false
|
16
13
|
gem 'rubocop-rails-omakase', '~> 1.0.0', require: false
|
17
|
-
gem 'sprockets-rails', '~> 3.2', '>= 3.2.2'
|
18
14
|
end
|
19
15
|
|
20
16
|
group :test, :development do
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg?style=flat-square)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
|
4
4
|
![Gem Version](https://img.shields.io/gem/v/ckeditor5?style=flat-square)
|
5
|
+
![Gem Total Downloads](https://img.shields.io/gem/dt/ckeditor5?style=flat-square&color=orange)
|
5
6
|
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg?style=flat-square)](http://makeapullrequest.com)
|
6
7
|
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/mati365/ckeditor5-rails?style=flat-square)
|
7
8
|
[![GitHub issues](https://img.shields.io/github/issues/mati365/ckeditor5-rails?style=flat-square)](https://github.com/Mati365/ckeditor5-rails/issues)
|
@@ -30,6 +31,22 @@ CKEditor5::Rails.configure do
|
|
30
31
|
end
|
31
32
|
```
|
32
33
|
|
34
|
+
In your layout:
|
35
|
+
|
36
|
+
```erb
|
37
|
+
<!-- app/views/layouts/application.html.erb -->
|
38
|
+
|
39
|
+
<!DOCTYPE html>
|
40
|
+
<html>
|
41
|
+
<head>
|
42
|
+
<%= yield :head %>
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
<%= yield %>
|
46
|
+
</body>
|
47
|
+
</html>
|
48
|
+
```
|
49
|
+
|
33
50
|
In your view:
|
34
51
|
|
35
52
|
```erb
|
@@ -550,6 +567,9 @@ To specify a custom preset, you need to pass the `preset` keyword argument with
|
|
550
567
|
<% content_for :head do %>
|
551
568
|
<%= ckeditor5_assets preset: :custom %>
|
552
569
|
<% end %>
|
570
|
+
|
571
|
+
<%-# This editor will use `custom` preset defined in `ckeditor5_assets` above %>
|
572
|
+
<%= ckeditor5_editor %>
|
553
573
|
```
|
554
574
|
|
555
575
|
In order to define such preset, you can use the following configuration:
|
@@ -568,6 +588,18 @@ CKEditor5::Rails.configure do
|
|
568
588
|
end
|
569
589
|
```
|
570
590
|
|
591
|
+
:warning: Keep in mind that all `ckeditor5_editor` helpers will use the configuration from the preset defined in the `ckeditor5_assets`. If you want to use a different preset for a specific editor, you can pass the `preset` keyword argument to the `ckeditor5_editor` helper.
|
592
|
+
|
593
|
+
```erb
|
594
|
+
<!-- app/views/demos/index.html.erb -->
|
595
|
+
|
596
|
+
<% content_for :head do %>
|
597
|
+
<%= ckeditor5_assets preset: :custom %>
|
598
|
+
<% end %>
|
599
|
+
|
600
|
+
<%= ckeditor5_editor preset: :default %>
|
601
|
+
```
|
602
|
+
|
571
603
|
#### Inline preset definition
|
572
604
|
|
573
605
|
It's possible to define the preset directly in the `ckeditor5_assets` helper method. It allows you to dynamically specify version, cdn provider or even translations in the view. The example below inherits the default preset and adds Polish translations and other options:
|
@@ -9,23 +9,19 @@ module CKEditor5::Rails
|
|
9
9
|
class EditorContextError < StandardError; end
|
10
10
|
class PresetNotFoundError < ArgumentError; end
|
11
11
|
|
12
|
-
def ckeditor5_editor(
|
12
|
+
def ckeditor5_editor(
|
13
13
|
config: nil, extra_config: {},
|
14
|
-
type: nil, preset:
|
14
|
+
type: nil, preset: nil,
|
15
15
|
initial_data: nil, watchdog: true,
|
16
16
|
**html_attributes, &block
|
17
17
|
)
|
18
|
+
validate_editor_input!(initial_data, block)
|
18
19
|
controller_context = validate_and_get_editor_context!
|
19
|
-
preset = fetch_editor_preset(preset)
|
20
20
|
|
21
|
-
|
21
|
+
preset = resolve_editor_preset(preset || controller_context[:preset])
|
22
|
+
config = build_editor_config(preset, config, extra_config, initial_data)
|
22
23
|
type ||= preset.type
|
23
24
|
|
24
|
-
config = config.deep_merge(extra_config)
|
25
|
-
config[:initialData] = initial_data if initial_data
|
26
|
-
|
27
|
-
raise ArgumentError, 'Cannot pass initial data and block at the same time.' if initial_data && block
|
28
|
-
|
29
25
|
editor_props = Editor::Props.new(
|
30
26
|
controller_context, type, config,
|
31
27
|
watchdog: watchdog
|
@@ -52,6 +48,23 @@ module CKEditor5::Rails
|
|
52
48
|
|
53
49
|
private
|
54
50
|
|
51
|
+
def validate_editor_input!(initial_data, block)
|
52
|
+
return unless initial_data && block
|
53
|
+
|
54
|
+
raise ArgumentError, 'Cannot pass initial data and block at the same time.'
|
55
|
+
end
|
56
|
+
|
57
|
+
def resolve_editor_preset(preset_name)
|
58
|
+
fetch_editor_preset(preset_name || :default)
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_editor_config(preset, config, extra_config, initial_data)
|
62
|
+
editor_config = config || preset.config
|
63
|
+
editor_config = editor_config.deep_merge(extra_config)
|
64
|
+
editor_config[:initialData] = initial_data if initial_data
|
65
|
+
editor_config
|
66
|
+
end
|
67
|
+
|
55
68
|
def validate_and_get_editor_context!
|
56
69
|
unless defined?(@__ckeditor_context)
|
57
70
|
raise EditorContextError,
|
@@ -2,22 +2,56 @@
|
|
2
2
|
|
3
3
|
module CKEditor5::Rails::Hooks
|
4
4
|
module Form
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
html_options = options.merge(
|
14
|
-
name: object_name,
|
15
|
-
required: options.delete(:required),
|
16
|
-
initial_data: value
|
17
|
-
)
|
5
|
+
class EditorInputBuilder
|
6
|
+
def initialize(object_name, object, template)
|
7
|
+
@object_name = object_name
|
8
|
+
@object = object
|
9
|
+
@template = template
|
10
|
+
end
|
18
11
|
|
12
|
+
def build_editor(method, options = {})
|
13
|
+
html_options = build_html_options(method, options)
|
14
|
+
add_validation_classes!(method, html_options)
|
19
15
|
@template.ckeditor5_editor(**html_options)
|
20
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :object_name, :object, :template
|
21
|
+
|
22
|
+
def build_html_options(method, options)
|
23
|
+
{
|
24
|
+
name: build_field_name(method, options),
|
25
|
+
initial_data: fetch_initial_data(method, options),
|
26
|
+
id: options[:id] || "#{object_name}_#{method}".parameterize,
|
27
|
+
**options
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_field_name(method, options)
|
32
|
+
return options[:as] || method.to_s if object_name.blank?
|
33
|
+
|
34
|
+
"#{object_name}[#{options[:as] || method}]"
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_initial_data(method, options)
|
38
|
+
return object.send(method) if object.respond_to?(method)
|
39
|
+
|
40
|
+
options[:initial_data]
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_validation_classes!(method, html_options)
|
44
|
+
return unless object.respond_to?(:errors) && object.errors[method].present?
|
45
|
+
|
46
|
+
html_options[:class] = [html_options[:class], 'is-invalid'].compact.join(' ')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module FormBuilderExtension
|
51
|
+
def ckeditor5(method, options = {})
|
52
|
+
EditorInputBuilder.new(object_name, object, @template)
|
53
|
+
.build_editor(method, options)
|
54
|
+
end
|
21
55
|
end
|
22
56
|
end
|
23
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ckeditor5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-11-
|
12
|
+
date: 2024-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|