Skip to content

Commit

Permalink
Merge pull request #2539 from sascha-karnatz/richtext-id
Browse files Browse the repository at this point in the history
Improve Richtext editor view
  • Loading branch information
tvdeyen authored Aug 2, 2023
2 parents abb284a + 6173992 commit 0671cef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 0 additions & 4 deletions app/models/alchemy/ingredients/richtext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def preview_text(max_length = 30)
stripped_body.to_s[0..max_length - 1]
end

def element_id
"tinymce_#{id}"
end

def has_tinymce?
true
end
Expand Down
7 changes: 4 additions & 3 deletions app/views/alchemy/ingredients/_richtext_editor.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<%= content_tag :div,
class: richtext_editor.css_classes,
data: richtext_editor.data_attributes do %>
<%- richtext_dom_id = "tinymce_#{richtext_editor.id}" %>
<%= element_form.fields_for(:ingredients, richtext_editor.ingredient) do |f| %>
<%= ingredient_label(richtext_editor) %>
<%= ingredient_label(richtext_editor, :value, for: richtext_dom_id) %>
<div class="tinymce_container">
<%= f.text_area :value,
class: "has_tinymce",
id: richtext_editor.element_id %>
id: richtext_dom_id %>
</div>
<% end %>
<% if richtext_editor.has_custom_tinymce_config? %>
<script type="text/javascript" charset="utf-8">
Alchemy.Tinymce.setCustomConfig("<%= richtext_editor.element_id %>", {
Alchemy.Tinymce.setCustomConfig("<%= richtext_dom_id %>", {
<% richtext_editor.custom_tinymce_config.each do |k, v| %>
<%= k %>: <%== v.to_json %>,
<% end %>
Expand Down
6 changes: 0 additions & 6 deletions spec/models/alchemy/ingredients/richtext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
expect(richtext_ingredient.sanitized_body).to eq("<h1>Hello!</h1><p class=\"green\">Welcome to Peters Petshop.</p>")
end

describe "#element_id" do
subject { richtext_ingredient.element_id }

it { is_expected.to eq("tinymce_#{richtext_ingredient.id}") }
end

describe "#has_custom_tinymce_config?" do
subject { richtext_ingredient.has_custom_tinymce_config? }

Expand Down

0 comments on commit 0671cef

Please sign in to comment.