Skip to content

Commit 7093766

Browse files
committed
addition to the previous commit (default_content was not correctly set)
1 parent 85d1d6d commit 7093766

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/services/locomotive/page_parsing_service.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,19 @@ def block_visible?(page_id, parsed, attributes)
153153

154154
def add_or_modify_editable_element(page, attributes)
155155
if element = page.editable_elements.by_block_and_slug(attributes[:block], attributes[:slug]).first
156+
# context: the editable element has been created from the page YAML header
157+
existing_content = element._type.nil? && !element.content.blank?
158+
156159
# FIXME: we don't want to deal here with the generic Locomotive::EditableElement class
157160
element = page.editable_elements.with_same_class!(element, "Locomotive::#{attributes[:type].to_s.classify}".constantize)
158161
element.attributes = attributes
162+
163+
# we know now this was an editable_text element. If it already had
164+
# a content, then it shouldn't be flagged as default_content.
165+
if element.respond_to?(:default_content?) && existing_content
166+
element.default_content = false
167+
end
168+
159169
element
160170
else
161171
klass = "Locomotive::#{attributes[:type].to_s.classify}".constantize

spec/services/locomotive/page_parsing_service_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
service.find_or_create_editable_elements(page)
5959
end
6060

61-
subject { page.reload.editable_elements.first.class }
61+
subject { page.reload.editable_elements.first }
6262

63-
it { expect(subject).to eq(Locomotive::EditableText) }
63+
it { expect(subject.class).to eq(Locomotive::EditableText) }
64+
it { expect(subject.default_content?).to eq(false) }
6465

6566
end
6667

0 commit comments

Comments
 (0)