instance method
compiled_source
Ruby on Rails 8.1.2
Since v7.1.6 PrivateSignature
compiled_source()
This method compiles the source of the template. The compilation of templates involves setting strict_locals! if applicable, encoding the template, and setting frozen string literal.
Source
# File actionview/lib/action_view/template.rb, line 443
def compiled_source
set_strict_locals = strict_locals!
source = encode!
code = @handler.call(self, source)
method_arguments =
if set_strict_locals
if set_strict_locals.include?("&")
"local_assigns, output_buffer, #{set_strict_locals}"
else
"local_assigns, output_buffer, #{set_strict_locals}, &_"
end
else
"local_assigns, output_buffer, &_"
end
# Make sure that the resulting String to be eval'd is in the
# encoding of the code
source = +<<-end_src
def #{method_name}(#{method_arguments})
@virtual_path = #{@virtual_path.inspect};#{locals_code};#{code}
end
end_src
# Make sure the source is in the encoding of the returned code
source.force_encoding(code.encoding)
# In case we get back a String from a handler that is not in
# BINARY or the default_internal, encode it to the default_internal
source.encode!
# Now, validate that the source we got back from the template
# handler is valid in the default_internal. This is for handlers
# that handle encoding but screw up
unless source.valid_encoding?
raise WrongEncodingError.new(source, Encoding.default_internal)
end
if Template.frozen_string_literal
"# frozen_string_literal: true\n#{source}"
else
source
end
end
Defined in actionview/lib/action_view/template.rb line 443
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Template