sfxcode / pebble-scala   1.1.6

Apache License 2.0 GitHub

A wrapper library for using [Pebble Templates](https://pebbletemplates.io/) in Scala.

Scala versions: 3.x 2.13 2.12

pebble-scala

A wrapper library for using Pebble Templates in Scala.

Adds first class scala support to Pebble.

Features

  • Resolver for Scala values
  • Support Scala Lists, Set, Maps, Options, ...
  • Loops support scala collections
  • Scala Support for Tests (empty, map, iterable)
  • iterate over scala collections
  • implement do Tag
  • ...

Version

Scala Version is 2.13.x / 3.0.0

SBT

libraryDependencies += "com.sfxcode.templating" %% "pebble-scala" % "1.0.2" 

Travis

Build Status

Download

Download

Usage

  1. Write Template
<html> <head> <title>{{ info.name }}</title> </head> <body> <ul> {% for value in list %} <li>{{ value }}</li> {% endfor %} </ul> </body> </html>
  1. Init Engine

Scala map with global engine parameter is optional ...

 val Engine: ScalaPebbleEngine = ScalaPebbleEngine(globalContext = Map("header" -> "pebble-scala"))
  1. Evaluate
 val context = Map("list" -> List("Resolver for Scala values", "iterate over scala collections")) val evaluated = Engine.evaluateToString("templates/template.peb", context) 
  1. Result
<html> <head> <title>pebble-scala</title> </head> <body> <ul> <li>Resolver for Scala values</li> <li>iterate over scala collections</li> </ul> </body> </html>

Supporters

JetBrains is supporting this open source project with:

Intellij IDEA