class ViewComponent::Base
def render_in(view_context, &block)
-
(String)
-
def render_in(view_context, &block) self.class.compile(raise_errors: true) @view_context = view_context self.__vc_original_view_context ||= view_context @output_buffer = ActionView::OutputBuffer.new @lookup_context ||= view_context.lookup_context # required for path helpers in older Rails versions @view_renderer ||= view_context.view_renderer # For content_for @view_flow ||= view_context.view_flow # For i18n @virtual_path ||= virtual_path # For template variants (+phone, +desktop, etc.) @__vc_variant ||= @lookup_context.variants.first # For caching, such as #cache_if @current_template = nil unless defined?(@current_template) old_current_template = @current_template @current_template = self if block && defined?(@__vc_content_set_by_with_content) raise DuplicateContentError.new(self.class.name) end @__vc_content_evaluated = false @__vc_render_in_block = block before_render if render? rendered_template = if compiler.renders_template_for?(@__vc_variant, request&.format&.to_sym) render_template_for(@__vc_variant, request&.format&.to_sym) else maybe_escape_html(render_template_for(@__vc_variant, request&.format&.to_sym)) do Kernel.warn("WARNING: The #{self.class} component rendered HTML-unsafe output. The output will be automatically escaped, but you may want to investigate.") end end.to_s # Avoid allocating new string when output_preamble and output_postamble are blank if output_preamble.blank? && output_postamble.blank? rendered_template else safe_output_preamble + rendered_template + safe_output_postamble end else "" end ensure @current_template = old_current_template end