Class: Liquid::Renderer

Inherits:
Object
  • Object
show all
Defined in:
app/lib/liquid/renderer.rb

Overview

Library code: renderer.

Class Method Summary collapse

Class Method Details

.render(template_instance, options = nil, context = nil) ⇒ String

Renders a Liquid template with non-strict variables and filters, logging and
reporting any template errors (reporting is skipped when ignore_errors is set).

Parameters:

  • template_instance (Liquid::Template)

    the template to render

  • options (Hash, nil) (defaults to: nil)

    assigns passed to the template; keys are stringified
    before rendering, so any assign key is allowed

  • context (String, nil) (defaults to: nil)

    description of the render context, included in error messages

Options Hash (options):

  • :ignore_errors (Boolean)

    when truthy, suppresses the AppSignal
    error report if the template renders with errors (still logged)

Returns:

  • (String)

    the rendered output



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/lib/liquid/renderer.rb', line 16

def self.render(template_instance, options = nil, context = nil)
  options ||= {}
  options.stringify_keys!

  res = template_instance.render options, { strict_variables: false, strict_filters: false }
  if template_instance.errors.present?
    terse_options = options.dup.transform_values { |v| v.to_s.truncate(20) }
    error_message = "#{context || 'Unknown context'}: #{template_instance.errors.join(', ')}. Options: #{terse_options.inspect}"
    ErrorReporting.warning error_message if Rails.env.production? && !options['ignore_errors'].to_b
    Rails.logger.warn error_message
  end
  res
end