diff options
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala index 2239f5a50..1569d3873 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/filters.scala @@ -23,4 +23,20 @@ object filters { else array.reverse } } + + /** Used to get the first element of arrays and strings: + * + * ```html + * {% assign array = "1,2,3,4,5" | split: "," %} + * {{ array | first }} + * ``` + * The above snippet will render "1" + */ + final class First extends Filter("first") { + override def apply(value: Any, params: AnyRef*): AnyRef = value match { + case str: String if str.nonEmpty => str.charAt(0).toString + case xs: Array[String] if xs.nonEmpty => xs.head + case _ => null + } + } } |