Skip to content

Built in Expressions Reference

firebaseco edited this page Oct 13, 2011 · 12 revisions

Glossary:

  • Bypass result: Returns the last result in the expression-block.

@return

Description: Returns the input expression as a result

Hint: Unsupported

Input: Executed once

Result: Any value

@get

Description: Returns the variable path in the hint.

Hint: Required, the path of the variable.

Input: Ignored

Result: Any value

@set

Description: Sets the input as the value for the variable name given in the hint.

Hint: Required, the path of the variable.

Input: Executed once

Result: Bypass

@scopeSet

Description: Sets the input as the value for the variable name given in the hint. The variable is created only for the current block, it does not override variables of outer scope.

Hint: Required, the path of the variable.

Input: Executed once

Result: Bypass

@if

Description: Returns the input if the operand is evaluated as true(following the Javascript evaluation rules for booleans), otherwise it returns the result in the block. The operand can be a path in the hint or the previous result.

Hint: Optional, the path of the variable.

Input: Executed once

Result: If the condition is met returns the input, otherwise it Bypass the result.

@unless

Description: Returns the input if the operand is evaluated as false(following the Javascript evaluation rules for booleans). The operand can be a variable name in the hint or the previous result.

Hint: Optional, the path of the variable.

Input: Executed once

Result: If the condition is met returns the input, otherwise it Bypass the result.

@loop

Description: Process the input forever or until it founds a loop control expression. Returns an array with the results of every input execution.

Hint: Optional, prefix for Input variable names.

Input: Executed multiple times.

Result: Array

Input Variables: CurrentIndex

@each

Description: Process the input per element in the array in the last result. Returns an array with the results of every input execution.

Hint: Optional, prefix for Input variable names.

Input: Executed multiple times.

Input Variables: CurrentItem, CurrentIndex

Result: Array

@break

Description: Immediately stops the execution of the current or any other iteration. Any result in the current iteration will NOT be added to the loop.

Hint: Unsupported

Input: Ignored

Result: Bypass

@continue

Description: Immediately stops the execution of the current iteration. Any result in the current iteration will NOT be added to the loop.

Hint: Unsupported

Input: Ignored

Result: Bypass

@input

Description: When used inside priest JSON code, it executes the input of the root expression. Specially intended for custom expressions.

Hint: Unsupported

Input: Ignored

Result: Any value.

@try

Description: Returns the input, if there is any error it will be saved internally so @catch or @returnError work properly.

Hint: Unsupported

Input: Executed once.

Result: Any value. Bypass if any errors occurs.

@catch

Description: Returns the input if an error was catch by @try. Clears the error automatically.

Hint: Optional, prefix for Input variable names.

Input: Executed once.

Result: Any value. Bypass if there is no errors.

Input Variables: CurrentError

@returnError

Description: Returns the last error in the expression block. if there is no errors it returns undefined.

Hint: Unsupported

Input: Ignored.

Result: Any value.

@clearError

Description: Clears the last error in the expression block.

Hint: Unsupported

Input: Ignored.

Result: Bypass.

@raiseError

Description: Raises an error using the input.

Hint: Unsupported

Input: Executed once.

Result: Bypass.

@equals

Description: Returns true if all the comparable values are equal, otherwise returns false. A hint with 'strict' can enforce the expression to compare types too, by default this is turned off. If operand doesn't have at least two comparable values it will return undefined.

Hint: Optional, "strict" can enforce type checking.

Input: Executed once.

Result: Boolean value or undefined.

@notEquals

Description: Returns true if all the comparable values are not equal, otherwise returns false. A hint with 'strict' can enforce the expression to compare types too, by default this is turned off. If operand doesn't have at least two comparable values it will return undefined. Ignores any input.

Hint: Optional, "strict" can enforce type checking.

Input: Executed once.

Result: Boolean value or undefined.

@increment

Description: Increments the given variable name in the hint by the input. If the operand or the input are not numbers it will assign NaN.

Hint: Required, Variable name.

Input: Executed once.

Result: Bypass.

@decrement

Description: Decrements the given variable name in the hint by the input. If the operand or the input are not numbers it will assign NaN.

Hint: Required, Variable name.

Input: Executed once.

Result: Bypass.

Comparable Values and Operands

Due the flexibility of the Javascript object-system, priest behaves in certain ways when a conditional expression needs to compare the values of a given input(mostly known as operand). Internally priest will try to convert anything to an array of comparable values before execute any comparison and it follows some simple rules:

  • the comparable values of any array it's the array itself
  • the comparable values of null is an empty array
  • the comparable values of undefined is an empty array
  • the comparable values of an empty object is an empty array
  • the comparable values of any object are all the values of the first-level properties
  • the comparable values of any boolean is an empty array
  • the comparable values of any string are all the chars in the String
Clone this wiki locally