Skip to content

Commit a640c60

Browse files
authored
Merge pull request #2044 from tf/page-type-template-rev-files
Set entry instance variable when rendering page type templates
2 parents f74bd36 + 1fdc7b7 commit a640c60

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

app/helpers/pageflow/page_types_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ def page_type_json_seed(json, page_type)
1515
end
1616

1717
def page_type_templates(entry)
18+
# Required by RevisionFileHelper#find_file_in_entry
19+
@entry = entry
20+
1821
safe_join(Pageflow.config.page_types.map do |page_type|
1922
content_tag(:script,
2023
render(template: page_type.template_path,
2124
locals: {
2225
configuration: {},
2326
page: Page.new,
24-
entry: entry,
25-
26-
# Required by RevisionFileHelper#find_file_in_entry
27-
:@entry => entry
27+
entry: entry
2828
},
2929
layout: false).to_str,
3030
type: 'text/html', data: {template: "#{page_type.name}_page"})

spec/helpers/pageflow/page_types_helper_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,37 @@ module Pageflow
8888
page_type = TestPageType.new(name: 'test',
8989
template_path: 'pageflow/test/page')
9090
Pageflow.config.page_types.register(page_type)
91-
entry = build(:entry)
91+
entry = build(:published_entry)
9292

9393
stub_template('pageflow/test/page.html.erb' => 'template')
9494

9595
result = helper.page_type_templates(entry)
9696

9797
expect(result).to have_selector('script[data-template=test_page]', :text => 'template', :visible => false)
9898
end
99+
100+
it 'supports template that uses RevisionFileHelper#find_file_in_entry' do
101+
page_type = TestPageType.new(name: 'test',
102+
template_path: 'pageflow/test/page')
103+
Pageflow.config.page_types.register(page_type)
104+
entry = create(:published_entry)
105+
image_file = create(:image_file)
106+
create(:file_usage,
107+
file: image_file,
108+
revision: entry.revision,
109+
perma_id: 11,
110+
configuration: {alt: 'Some image'})
111+
112+
helper.extend(RevisionFileHelper)
113+
stub_template('pageflow/test/page.html.erb' =>
114+
'<%= find_file_in_entry(Pageflow::ImageFile, 11).configuration["alt"] %>')
115+
116+
result = helper.page_type_templates(entry)
117+
118+
expect(result).to have_selector('script[data-template=test_page]',
119+
text: 'Some image',
120+
visible: false)
121+
end
99122
end
100123
end
101124
end

0 commit comments

Comments
 (0)