Class: Liquid::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/autoescape/liquid_ext/variable.rb

Instance Method Summary collapse

Instance Method Details

#non_escaping_renderObject



9
# File 'lib/liquid/autoescape/liquid_ext/variable.rb', line 9

alias non_escaping_render render

#render(context) ⇒ String

Possibly render the variable with HTML escaping applied

If the auto-escaping context variable has been set by the autoescape % tag or Liquid auto-escaping is globally enabled, this will run the variable through the global exemption list to determine if it is exempt from auto-escaping. If it is not, its contents will be rendered as a string with all unsafe HTML characters escaped. In all other cases, the original, unescaped value of the variable will be rendered.

Parameters:

  • context (Liquid::Context)

    The variable’s rendering context

Returns:

  • (String)

    The potentially escaped contents of the variable



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/liquid/autoescape/liquid_ext/variable.rb', line 22

def render(context)
  is_global = Autoescape.configuration.global?
  is_local = context[Autoescape::ENABLED_FLAG]

  if !is_global && !is_local
    return non_escaping_render(context)
  end

  if is_global && is_local == false
    is_exempt = true
  else
    variable = Autoescape::TemplateVariable.from_liquid_variable(self)
    is_exempt = Autoescape.configuration.exemptions.apply?(variable)
  end

  @filters << [:escape, []] unless is_exempt
  output = non_escaping_render(context)
  @filters.pop unless is_exempt

  output
end