# frozen_string_literal: truemoduleViewComponentclassTemplateDEFAULT_FORMAT=:htmlprivate_constant:DEFAULT_FORMATDataWithSource=Struct.new(:format,:identifier,:short_identifier,:type,keyword_init: true)attr_reader:details,:pathdelegate:virtual_path,to: :@componentdelegate:format,:variant,to: :@detailsdefinitialize(component:,details:,lineno: nil,path: nil)@component=component@details=details@lineno=lineno@path=pathendclassFile<Templatedefinitialize(component:,details:,path:)super(component: component,details: details,path: path,lineno: 0)enddeftype:fileend# Load file each time we look up #source in case the file has been modifieddefsource::File.read(@path)endendclassInline<Templateattr_reader:sourcedefinitialize(component:,inline_template:)details=ActionView::TemplateDetails.new(nil,inline_template.language.to_sym,nil,nil)super(component: component,details: details,path: inline_template.path,lineno: inline_template.lineno,)@source=inline_template.source.dupenddeftype:inlineendendclassInlineCall<Templatedefinitialize(component:,method_name:,defined_on_self:)variant=method_name.to_s.include?("call_")?method_name.to_s.sub("call_","").to_sym:nildetails=ActionView::TemplateDetails.new(nil,nil,nil,variant)super(component: component,details: details)@call_method_name=method_name@defined_on_self=defined_on_selfenddeftype:inline_callenddefcompile_to_component@component.define_method(safe_method_name,@component.instance_method(@call_method_name))enddefsafe_method_name_callm=safe_method_nameprocdomaybe_escape_html(send(m))doKernel.warn("WARNING: The #{self.class} component rendered HTML-unsafe output. "\"The output will be automatically escaped, but you may want to investigate.")endendenddefdefined_on_self?@defined_on_selfendenddefcompile_to_component@component.silence_redefinition_of_method(call_method_name)# rubocop:disable Style/EvalWithLocation@component.class_eval<<~RUBY,@path,@lineno-1
def #{call_method_name}
@view_context.instance_variable_set(:@virtual_path, virtual_path)
#{compiled_source}
end
RUBY# rubocop:enable Style/EvalWithLocation@component.define_method(safe_method_name,@component.instance_method(@call_method_name))enddefsafe_method_name_callm=safe_method_nameproc{send(m)}enddefrequires_compiled_superclass?inline_call?&&!defined_on_self?enddefinline_call?type==:inline_callenddefdefault_format?format.nil?||format==DEFAULT_FORMATendalias_method:html?,:default_format?defcall_method_name@call_method_name||=["call",(normalized_variant_nameifvariant.present?),(formatunlessdefault_format?)].compact.join("_").to_symenddefsafe_method_name"_#{call_method_name}_#{@component.name.underscore.gsub("/","__")}"enddefnormalized_variant_namevariant.to_s.gsub("-","__")endprivatedefcompiled_sourcehandler=details.handler_classthis_source=sourcethis_source.rstrip!if@component.strip_trailing_whitespace?short_identifier=defined?(Rails.root)?@path.sub("#{Rails.root}/",""):@pathformat=self.format||DEFAULT_FORMATtype=ActionView::Template::Types[format]handler.call(DataWithSource.new(format:,identifier: @path,short_identifier:,type:),this_source)endendend