alphagov/smartdown — pull request #53 by dsingleton (2014-09-09 17:02:32+00:00)
Title: Function predicates

Adds support for calling a function with arguments, these arguments can even be evaluatable themselves, eg, another function, the result of a predicate.

A contrived example would look like this:
```
calculate_holiday_pay(days_worked, calculate_salary(monthly_salary)
```
Where:
- `calculate_holiday_pay` is a function, this would be injected in the Smartdown Engine scope by the calling application
- `days_worked` is an answer to a question that the user has answered, eg, 12
- `calculate_salary` is another injected function, that takes it's own argument, calculates its answer, which is evaluated by `calculate_holiday_pay`

Predicate is a really bad name for this, but it's consistent with the naming and structure of the existing code and I didn't want to change it for just one thing. It's something that should be looked at in the future.

The specs do quite a good job of showing how they're used:
- Parsing: https://github.com/alphagov/smartdown/blob/ad214a3a55aff3921012c8ea24d8ff2af556cf5d/spec/parser/predicates_spec.rb
- Evaluation: https://github.com/alphagov/smartdown/blob/ff83ecc41d95eb84f1fcbdf54a1d5b39695d01d1/spec/model/predicates/function_spec.rb

The functions will be evaluated in next node rules/predicates and within conditions, but not yet for interpolations. That's coming in https://github.com/alphagov/smartdown/tree/complex-interpolation