mwunsch / handlebars.scala

A Scala implementation of the Handlebars templating language (a superset of Mustache).
Apache License 2.0
112 stars 40 forks source link

HelperOptions arguments list #75

Open kflorence opened 6 years ago

kflorence commented 6 years ago

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 commented 6 years ago

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

kflorence commented 6 years ago

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
      }
    }