ckeditor5 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/ckeditor5/rails/assets/webcomponent.mjs +6 -1
- data/lib/ckeditor5/rails/editor/helpers.rb +3 -2
- data/lib/ckeditor5/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aee8586159157d2581cefe62cc87ea58d822db618c0f0dd9ceee5c0d3fdba46
|
4
|
+
data.tar.gz: 550633bd1bb74e54909f19447f7ced3bff0f6bd10324b44c9076641eb65e08e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba63dc4631e0703b8d719b7b2c21efc97183455550e6eb6406f96f8e789baaf1ed7dd202d0711ca100f39e906b386c026ef8515042d6441bce465baf6de8b10a
|
7
|
+
data.tar.gz: 15a0df8fd18291bc5d47e9a15df2d0192316512b38a85ec07c4bc047895d1111a6bd92afa2c09bdab639f31485a039538d7390048e39d66ea22bf51373e22e38
|
data/README.md
CHANGED
@@ -804,12 +804,26 @@ This section covers frequent questions and scenarios when working with CKEditor
|
|
804
804
|
|
805
805
|
### Setting Initial Content 📝
|
806
806
|
|
807
|
+
You can set the initial content of the editor using the `initial_data` keyword argument or by passing the content directly to the `ckeditor5_editor` helper block.
|
808
|
+
|
809
|
+
The example below shows how to set the initial content of the editor using the `initial_data` keyword argument:
|
810
|
+
|
807
811
|
```erb
|
808
812
|
<%= ckeditor5_editor initial_data: "<p>Initial content</p>" %>
|
809
813
|
```
|
810
814
|
|
815
|
+
The example below shows how to set the initial content of the editor using the `ckeditor5_editor` helper block.
|
816
|
+
|
817
|
+
```erb
|
818
|
+
<%= ckeditor5_editor do %>
|
819
|
+
<p>Initial content</p>
|
820
|
+
<% end %>
|
821
|
+
```
|
822
|
+
|
811
823
|
### Setting Editor Language 🌐
|
812
824
|
|
825
|
+
You can set the language of the editor using the `language` method in the `config/initializers/ckeditor5.rb` file. The `translations` method fetches the translations files, while the `language` method sets the default language of the editor.
|
826
|
+
|
813
827
|
```rb
|
814
828
|
config.presets.override :default do
|
815
829
|
translations :pl, :es
|
@@ -819,6 +833,8 @@ end
|
|
819
833
|
|
820
834
|
### Integrating with Forms 📋
|
821
835
|
|
836
|
+
You can integrate CKEditor 5 with Rails form builders like `form_for` or `simple_form`. The example below shows how to integrate CKEditor 5 with a Rails form using the `form_for` helper:
|
837
|
+
|
822
838
|
#### Rails form builder integration
|
823
839
|
|
824
840
|
```erb
|
@@ -51,12 +51,17 @@ class CKEditorComponent extends HTMLElement {
|
|
51
51
|
/** @type {Record<string, HTMLElement>} Map of editable elements by name */
|
52
52
|
editables = {};
|
53
53
|
|
54
|
+
/** @type {String} Initial HTML passed to component */
|
55
|
+
#initialHTML = '';
|
56
|
+
|
54
57
|
/**
|
55
58
|
* Lifecycle callback when element is connected to DOM
|
56
59
|
* Initializes the editor when DOM is ready
|
57
60
|
* @protected
|
58
61
|
*/
|
59
62
|
connectedCallback() {
|
63
|
+
this.#initialHTML = this.innerHTML;
|
64
|
+
|
60
65
|
try {
|
61
66
|
execIfDOMReady(() => this.#reinitializeEditor());
|
62
67
|
} catch (error) {
|
@@ -179,7 +184,7 @@ class CKEditorComponent extends HTMLElement {
|
|
179
184
|
this.style.display = 'block';
|
180
185
|
|
181
186
|
if (!this.isMultiroot() && !this.isDecoupled()) {
|
182
|
-
this.innerHTML = `<${this.#editorElementTag}
|
187
|
+
this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;
|
183
188
|
this.#assignInputAttributes();
|
184
189
|
}
|
185
190
|
|
@@ -24,14 +24,15 @@ module CKEditor5::Rails
|
|
24
24
|
config = config.deep_merge(extra_config)
|
25
25
|
config[:initialData] = initial_data if initial_data
|
26
26
|
|
27
|
+
raise ArgumentError, 'Cannot pass initial data and block at the same time.' if initial_data && block
|
28
|
+
|
27
29
|
editor_props = build_editor_props(
|
28
30
|
config: config,
|
29
31
|
type: type,
|
30
32
|
context: context
|
31
33
|
)
|
32
34
|
|
33
|
-
render_editor_component(editor_props, html_attributes,
|
34
|
-
&(%i[multiroot decoupled].include?(type) ? block : nil))
|
35
|
+
render_editor_component(editor_props, html_attributes, &block)
|
35
36
|
end
|
36
37
|
|
37
38
|
def ckeditor5_editable(name = nil, **kwargs, &block)
|