Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Richtext editor view #2539

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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