Class: LexxyVariables::Renderers::Liquid

Inherits:
Object
  • Object
show all
Defined in:
lib/lexxy_variables/renderers/liquid.rb

Overview

Opt-in renderer that resolves each key through Liquid, enabling dotted access, drops (e.g. company.name }), and filters. Requires the liquid gem. It is loaded here, when a host instantiates this renderer, so apps on the default renderer never pull it in.

Security: only the chip's key is parsed as a Liquid template, never body text, so } or % an author types stays literal. The resolved value is injected as a DOM text node and escaped per output format by the resolver, so drops must NOT pre-escape their values.

assigns is the Hash passed to Liquid: string values and/or Liquid::Drop instances.

Instance Method Summary collapse

Constructor Details

#initialize(error_mode: :lax) ⇒ Liquid

Returns a new instance of Liquid.



16
17
18
19
# File 'lib/lexxy_variables/renderers/liquid.rb', line 16

def initialize(error_mode: :lax)
  require "liquid"
  @error_mode = error_mode
end

Instance Method Details

#resolve_value(key, assigns) ⇒ Object



21
22
23
# File 'lib/lexxy_variables/renderers/liquid.rb', line 21

def resolve_value(key, assigns)
  ::Liquid::Template.parse("{{ #{key} }}", error_mode: @error_mode).render(assigns)
end