handlebars.scala icon indicating copy to clipboard operation
handlebars.scala copied to clipboard

HelperOptions arguments list

Open kflorence opened this issue 6 years ago • 2 comments

HelperOptions[T] trait provides the argument method, which returns a single argument value. Is there any way to get a list of all argument values?

My specific use-case is building an i18n helper method which will accept a key, a language, and a variable list of arguments to substitute in the message.

kflorence avatar Oct 24 '17 18:10 kflorence

A simple fix for this might be to just expose def arguments: Seq[Binding[T]] on the trait.

kflorence avatar Oct 24 '17 19:10 kflorence

Until #76 is merged, the following can be used as a workaround:

    @tailrec
    def getArguments(index: Int, arguments: Seq[Any]): Seq[Any] = {
      options.argument(index) match {
        case FullBinding(v) => getArguments(index + 1, arguments :+ v)
        case VoidBinding => arguments
      }
    }

kflorence avatar Nov 20 '17 23:11 kflorence