Module: Antlers::Variables

Extended by:
Queries
Included in:
ForNode, FormNode, Props, VarNode
Defined in:
lib/modules/variables.rb

Instance Method Summary collapse

Methods included from Queries

user_defined_string?, wrapped_in?

Instance Method Details

#evaluate(name:, current_binding:) ⇒ Object

Evaluation limited to the following for security and to prevent a templating language becoming a programming language.

  1. An instance variable
  2. A method call/local variable
  3. A method chain
  4. A static string


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/modules/variables.rb', line 14

def evaluate(name:, current_binding:)
  return name.to_s unless current_binding

  name, *chain = name.split('.')

  result = method_var(name:, current_binding:)
  return method_chain(result:, chain:) if chain.count > 0
  return result if result

  nil
rescue StandardError
  nil
end

#fallback(value) ⇒ Object



28
29
30
31
32
# File 'lib/modules/variables.rb', line 28

def fallback(value)
  return value[1..-2] if Queries.user_defined_string?(value)

  value
end