Skip to content

Commit

Permalink
Merge pull request #2044 from tf/page-type-template-rev-files
Browse files Browse the repository at this point in the history
Set entry instance variable when rendering page type templates
  • Loading branch information
tf authored Jan 2, 2024
2 parents f74bd36 + 1fdc7b7 commit a640c60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/helpers/pageflow/page_types_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def page_type_json_seed(json, page_type)
end

def page_type_templates(entry)
# Required by RevisionFileHelper#find_file_in_entry
@entry = entry

safe_join(Pageflow.config.page_types.map do |page_type|
content_tag(:script,
render(template: page_type.template_path,
locals: {
configuration: {},
page: Page.new,
entry: entry,

# Required by RevisionFileHelper#find_file_in_entry
:@entry => entry
entry: entry
},
layout: false).to_str,
type: 'text/html', data: {template: "#{page_type.name}_page"})
Expand Down
25 changes: 24 additions & 1 deletion spec/helpers/pageflow/page_types_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,37 @@ module Pageflow
page_type = TestPageType.new(name: 'test',
template_path: 'pageflow/test/page')
Pageflow.config.page_types.register(page_type)
entry = build(:entry)
entry = build(:published_entry)

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

result = helper.page_type_templates(entry)

expect(result).to have_selector('script[data-template=test_page]', :text => 'template', :visible => false)
end

it 'supports template that uses RevisionFileHelper#find_file_in_entry' do
page_type = TestPageType.new(name: 'test',
template_path: 'pageflow/test/page')
Pageflow.config.page_types.register(page_type)
entry = create(:published_entry)
image_file = create(:image_file)
create(:file_usage,
file: image_file,
revision: entry.revision,
perma_id: 11,
configuration: {alt: 'Some image'})

helper.extend(RevisionFileHelper)
stub_template('pageflow/test/page.html.erb' =>
'<%= find_file_in_entry(Pageflow::ImageFile, 11).configuration["alt"] %>')

result = helper.page_type_templates(entry)

expect(result).to have_selector('script[data-template=test_page]',
text: 'Some image',
visible: false)
end
end
end
end

0 comments on commit a640c60

Please sign in to comment.