1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/lib/action_view/unbound_template.rb
John Hawthorn 2be8d3ebf8 Store details on unbound template
Previously we just stored handler, format, and variant and assigned a
default format if none existed.

Now we want to also store locale, and move the default format behaviour
into unbound template.
2021-04-20 13:48:12 -07:00

44 lines
1,000 B
Ruby

# frozen_string_literal: true
require "concurrent/map"
module ActionView
class UnboundTemplate
attr_reader :handler, :format, :variant, :locale, :virtual_path
def initialize(source, identifier, handler, format:, variant:, locale:, virtual_path:)
@source = source
@identifier = identifier
@handler = handler
@format = format
@variant = variant
@locale = locale
@virtual_path = virtual_path
@templates = Concurrent::Map.new(initial_capacity: 2)
end
def bind_locals(locals)
@templates[locals] ||= build_template(locals)
end
private
def build_template(locals)
handler = Template.handler_for_extension(@handler)
format = @format || handler.try(:default_format)
Template.new(
@source,
@identifier,
handler,
format: format,
variant: @variant,
virtual_path: @virtual_path,
locals: locals
)
end
end
end