Module: Antex::LiquidHelpers

Included in:
Job
Defined in:
lib/antex/liquid_helpers.rb

Overview

Exposes helper methods to simplify Liquid templates rendering.

Defined Under Namespace

Classes: UnknownClass

Instance Method Summary collapse

Instance Method Details

#liquid_render(object, context_hash = {}) ⇒ String

Recursively renders Liquid template strings, possibly organized in nested arrays and hashes, using the given hash of contextual variables.

Parameters:

  • object (String, Array, Hash)

    the object to render

  • context_hash (Hash) (defaults to: {})

    the context hash accessible from the object strings

Returns:

  • (String)

    the rendered object

Raises:

  • (UnknownClass)

    when given anything that’s not renderable



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/antex/liquid_helpers.rb', line 18

def liquid_render(object, context_hash = {})
  case object
  when String
    liquid_render_string object, context_hash
  when Array
    liquid_render_array object, context_hash
  when Hash
    liquid_render_hash object, context_hash
  else
    raise UnknownClass, "I don't know how to render a #{object.class}."
  end
end