ckeditor5 1.5.2 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/lib/ckeditor5/rails/hooks/form.rb +47 -13
- data/lib/ckeditor5/rails/version.rb +4 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482179142a7c42597ead0126fe8eedb8c2ca1ae5e33427e7c2438feea952cc40
|
4
|
+
data.tar.gz: 7fa425d5018e6a804e05780958a040cc03b946853f84fe666e1d0fe6df8b0512
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5922019eda63b05842228e06acc45d016d4489a568b5f023a756b5fc6c7355ff58f02523101b44b9066f077fe820d336ca9314a8404ad6282763d71dde4b99af
|
7
|
+
data.tar.gz: a91192a64da0d0c20f8ee8e5125e2c1b3a6e1e44c58a6fad76bc1dc9e1ef60a5e91b023f6cac551d4a615ae692cf6ced42ebf966e9ddbaae6caf64002a505361
|
data/README.md
CHANGED
@@ -30,6 +30,22 @@ CKEditor5::Rails.configure do
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
33
|
+
In your layout:
|
34
|
+
|
35
|
+
```erb
|
36
|
+
<!-- app/views/layouts/application.html.erb -->
|
37
|
+
|
38
|
+
<!DOCTYPE html>
|
39
|
+
<html>
|
40
|
+
<head>
|
41
|
+
<%= yield :head %>
|
42
|
+
</head>
|
43
|
+
<body>
|
44
|
+
<%= yield %>
|
45
|
+
</body>
|
46
|
+
</html>
|
47
|
+
```
|
48
|
+
|
33
49
|
In your view:
|
34
50
|
|
35
51
|
```erb
|
@@ -980,7 +996,7 @@ The example below shows how to define a custom plugin that allows toggling the h
|
|
980
996
|
```rb
|
981
997
|
# config/initializers/ckeditor5.rb
|
982
998
|
|
983
|
-
|
999
|
+
CKEditor5::Rails.configure do
|
984
1000
|
# ... other configuration
|
985
1001
|
|
986
1002
|
# 1. You can also use "window_name" option to import plugin from window object:
|
@@ -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.5.
|
4
|
+
version: 1.5.4
|
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
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '6.0'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '9.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '6.0'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '9.0'
|
34
34
|
description:
|
35
35
|
email: cziken58@gmail.com
|
36
36
|
executables: []
|