io.github.cloudify.scala.spdf.ParamShow.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spdf_2.9.2 Show documentation
Show all versions of spdf_2.9.2 Show documentation
Create PDFs using plain old HTML+CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit.
The newest version!
package io.github.cloudify.scala.spdf
/**
* Renders a parameter of type T to a sequence of strings that will be
* appended to the command line.
*/
trait ParamShow[T] {
def show(name: String, value: T): Iterable[String]
}
object ParamShow {
implicit object StringParamShow extends ParamShow[String] {
override def show(name: String, value: String): Iterable[String] =
formatParam(name, Some(value))
}
implicit object BooleanParamShow extends ParamShow[Boolean] {
override def show(name: String, value: Boolean): Iterable[String] = value match {
case true => formatParam(name, None)
case _ => Iterable.empty
}
}
implicit object IntParamShow extends ParamShow[Int] {
override def show(name: String, value: Int): Iterable[String] =
formatParam(name, Some(value.toString))
}
implicit object FloatParamShow extends ParamShow[Float] {
override def show(name: String, value: Float): Iterable[String] =
formatParam(name, Some("%.2f".format(value)))
}
implicit object PageOrientationParamShow extends ParamShow[PageOrientation] {
override def show(name: String, value: PageOrientation): Iterable[String] =
formatParam(name, Some(value.value))
}
private def formatParam(name: String, value: Option[String]): Iterable[String] =
Seq(Some("--" + name), value).flatten
}