Encoder
class Encoder[ScalaType, DomType](encode: ScalaType => DomType)Converts a Scala value into the representation expected by a DOM definition.
For a custom HtmlAttr, DomType is String. The attribute calls encode when
:= is evaluated, and the HTML renderer escapes that encoded string later. An encoder should
therefore describe representation only: it neither needs to pre-escape HTML nor implies semantic
sanitization of URLs, CSS, JavaScript, or custom attribute values.
Custom attribute definitions can pair an encoder with htmlAttr:
val priority = htmlAttr("data-priority", Encoder[Int, String](_.toString))
div(priority := 2)The attribute constructor validates the custom name. The encoder controls only its value and must return a non-null string for a string-valued custom attribute. The library's BooleanAsAttrPresenceEncoder is a specialized exception interpreted by HtmlAttr.
Parameters
encodeconversion applied to each assigned Scala value
Type parameters
ScalaTypeinput type accepted by the DSL definition
DomTypeencoded representation consumed by that definition
Defined by scalive.codecs.Encoder. View source (scalive/api/src/scalive/codecs/Encoder.scala:28-28)
Values1
encode
val encode: ScalaType => DomTypeDefined by scalive.codecs.Encoder.encode. View source (scalive/api/src/scalive/codecs/Encoder.scala:28-28)