Skip to content

Commit

Permalink
Rails 7.1 now requires the template to be an UnboundTemplate instance…
Browse files Browse the repository at this point in the history
…, so we return that with backwards compat for Rails 6.1
  • Loading branch information
patbenatar committed Oct 18, 2023
1 parent b0f2696 commit b14c0d1
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/rbexy/rails/component_template_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ def find_rbx_templates(templates_path, extensions, component_name, virtual_path)
Dir["#{templates_path}.*{#{extensions}}"].map do |template_path|
source = File.binread(template_path)
extension = File.extname(template_path)[1..-1]
handler = ActionView::Template.handler_for_extension(extension)

ActionView::Template.new(
"#{source}#{component_class_cachebuster(component_name, extension)}",
template_path,
handler,
format: extension.to_sym,
locals: [],
build_template(
source: "#{source}#{component_class_cachebuster(component_name, extension)}",
template_path: template_path,
extension: extension.to_sym,
virtual_path: virtual_path
)
end
Expand All @@ -68,17 +65,36 @@ def find_call_component_cachebuster_templates(templates_path, component_name, vi
return [] unless component_class && component_class.call_component?

[
ActionView::Template.new(
cachebuster_digest_as_comment(component_class.component_file_location, :rbx),
"#{templates_path}.rbexycall",
ActionView::Template.handler_for_extension(:rbx),
format: :rbx,
locals: [],
build_template(
source: cachebuster_digest_as_comment(component_class.component_file_location, :rbx),
template_path: "#{templates_path}.rbexycall",
extension: :rbx,
virtual_path: virtual_path
)
]
end

if ActionView.version >= Gem::Version.new("7.0.0")
def build_template(source:, template_path:, extension:, virtual_path:)
ActionView::UnboundTemplate.new(
source,
template_path,
details: ActionView::TemplateDetails.new(nil, extension, extension, nil),
virtual_path: virtual_path
).bind_locals([])
end
else
def build_template(source:, template_path:, extension:, virtual_path:)
ActionView::UnboundTemplate.new(
source,
template_path,
ActionView::Template.handler_for_extension(extension),
format: extension.to_sym,
virtual_path: virtual_path
).bind_locals([])
end
end

def component_class_cachebuster(component_name, template_format)
component_class = find_component_class(component_name)
return unless component_class
Expand Down

0 comments on commit b14c0d1

Please sign in to comment.