find the editable element in a different page only if it is a fixed one

did committed Sep 28, 2015
commit 552b013e147ef7c0e4c4119a1156bee1503156c7
Showing 2 changed files with 24 additions and 5 deletions
locomotive/steam/liquid/tags/editable/base.rb b/lib/locomotive/steam/liquid/tags/editable/base.rb +2 -2
@@ @@ -38,7 +38,7 @@ module Locomotive
if element = service.find(page, block, @slug)
render_element(context, element)
else
- # Locomotive::Common::Logger.error "[#{page.fullpath}] missing #{@tag_name} \"#{@slug}\" (#{context['block'].try(:name) || 'default'})"
+ Locomotive::Common::Logger.error "[#{page.fullpath}] missing #{@tag_name} \"#{@slug}\" (#{context['block'].try(:name) || 'default'})"
super
end
end
@@ @@ -48,7 +48,7 @@ module Locomotive
def fetch_page(context)
page = context.registers[:page]
- return page if page.fullpath == @page_fullpath
+ return page if !@element_options[:fixed] || page.fullpath == @page_fullpath
pages = context.registers[:pages] ||= {}
service = context.registers[:services].page_finder
spec/unit/liquid/tags/editable/text_spec.rb +22 -3
@@ @@ -74,10 +74,10 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
let(:live_editing) { false }
let(:element_editing) { true }
- let(:page) { instance_double('Page', fullpath: 'hello-world') }
+ let(:child_page) { instance_double('Page', fullpath: 'child-page') }
let(:element) { instance_double('EditableText', _id: 42, id: 42, default_content?: true, inline_editing?: element_editing, inline_editing: element_editing, format: 'html') }
let(:services) { Locomotive::Steam::Services.build_instance(nil) }
- let(:context) { ::Liquid::Context.new({}, {}, { page: page, services: services, live_editing: live_editing }) }
+ let(:context) { ::Liquid::Context.new({}, {}, { page: child_page, services: services, live_editing: live_editing }) }
before { allow(services.editable_element).to receive(:find).and_return(element) }
@@ @@ -85,6 +85,11 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
it { is_expected.to eq 'Hello world' }
+ it "doesn't try to find the element in another page" do
+ expect(services.page_finder).not_to receive(:find).with('hello-world')
+ is_expected.to eq 'Hello world'
+ end
+
context 'no element found, render the default content' do
let(:element) { nil }
@@ @@ -92,6 +97,20 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
end
+ context 'fixed element' do
+
+ let(:layout) { instance_double('Page', fullpath: 'layout') }
+ let(:source) { "{% editable_text title, hint: 'Simple short text', fixed: true %}Hello world{% endeditable_text %}" }
+ let(:options) { { page: layout } }
+ let(:element) { instance_double('EditableText', _id: 42, id: 42, default_content?: true, inline_editing?: element_editing, inline_editing: element_editing, format: 'html', fixed: true) }
+
+ it 'fetches the related page in order to get the element' do
+ expect(services.page_finder).to receive(:find).with('layout').and_return(layout)
+ is_expected.to eq 'Hello world'
+ end
+
+ end
+
context 'modified content' do
let(:element) { instance_double('EditableText', content: 'Hello world!', default_content?: false, format: 'html') }
@@ @@ -103,7 +122,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
let(:source) { '{% block wrapper %}{% block sidebar %}{% editable_text title %}Hello world{% endeditable_text %}{% endblock %}{% endblock %}' }
- before { expect(services.editable_element).to receive(:find).with(page, 'wrapper/sidebar', 'title').and_return(element) }
+ before { expect(services.editable_element).to receive(:find).with(child_page, 'wrapper/sidebar', 'title').and_return(element) }
it { is_expected.to eq 'Hello world' }
end