ckeditor5 1.5.3 → 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/Gemfile +0 -4
- data/README.md +16 -0
- 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: 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/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
@@ -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
|
@@ -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
|