setup scalatags and integrate with play html

pull/4736/head
Thibault Duplessis 2018-12-02 16:26:52 +07:00
parent 48ee486c3d
commit c077322e60
8 changed files with 27 additions and 6 deletions

View File

@ -5,8 +5,9 @@ import play.api.data.Form
import play.api.http._
import play.api.libs.json.{ Json, JsObject, JsArray, JsString, Writes }
import play.api.mvc._
import play.api.mvc.BodyParsers.parse
import play.twirl.api.Html
import BodyParsers.parse
import scalatags.Text.TypedTag
import lila.api.{ PageData, Context, HeaderContext, BodyContext }
import lila.app._
@ -35,6 +36,13 @@ private[controllers] trait LilaController
protected implicit def LilaHtmlToResult(content: Html): Result = Ok(content)
protected implicit val WriteableScalatags: Writeable[TypedTag[String]] = Writeable(
(tags: TypedTag[String]) => Codec.utf_8 encode tags.render,
contentType = Some(HTML)
)
protected implicit def LilaScalatagsToHtml(tags: scalatags.Text.TypedTag[String]): Html = Html(tags.render)
protected val jsonOkBody = Json.obj("ok" -> true)
protected val jsonOkResult = Ok(jsonOkBody) as JSON

View File

@ -0,0 +1,12 @@
package lila.app
package ui
import play.twirl.api.Html
import scalatags.Text.TypedTag
object Scalatags {
implicit def LilaScalaTagsToHtml(tags: TypedTag[String]): Html = Html {
tags.render
}
}

View File

@ -5,7 +5,7 @@
}
@moreJs = {
@jsAt(s"compiled/lichess.tournament-calendar${isProd??(".min")}.js")
@jsAt(s"compiled/lichess.tournamentCalendar${isProd??(".min")}.js")
@embedJs {
var app = LichessTournamentCalendar.app(document.getElementById('tournament_calendar'), {
data: @safeJson(json),

View File

@ -2,7 +2,7 @@
@moreJs = {
@infiniteScrollTag
@jsAt(s"compiled/lichess.tournament-schedule${isProd??(".min")}.js")
@jsAt(s"compiled/lichess.tournamentSchedule${isProd??(".min")}.js")
@embedJs {
var app = LichessTournamentSchedule.app(document.getElementById('tournament_schedule'), {
data: @safeJson(json),

View File

@ -33,7 +33,7 @@ libraryDependencies ++= Seq(
scalaz, chess, compression, scalalib, hasher, typesafeConfig, findbugs,
reactivemongo.driver, reactivemongo.iteratees, akka.actor, akka.slf4j,
maxmind, prismic, netty, guava,
kamon.core, kamon.influxdb,
kamon.core, kamon.influxdb, scalatags,
java8compat, semver, scrimage, scalaConfigs, scaffeine
)
TwirlKeys.templateImports ++= Seq(

View File

@ -43,6 +43,7 @@ object Dependencies {
val specs2Scalaz = "org.specs2" %% "specs2-scalaz" % "4.0.2" % "test"
val stm = "org.scala-stm" %% "scala-stm" % "0.8"
val scalaUri = "io.lemonlabs" %% "scala-uri" % "1.2.0"
val scalatags = "com.lihaoyi" %% "scalatags" % "0.6.7"
object reactivemongo {
val version = "0.12.3"

View File

@ -1,3 +1,3 @@
const lilaGulp = require('../gulp/tsProject.js');
lilaGulp('LichessTournamentCalendar', 'lichess.tournament-calendar', __dirname);
lilaGulp('LichessTournamentCalendar', 'lichess.tournamentCalendar', __dirname);

View File

@ -1,3 +1,3 @@
const lilaGulp = require('../gulp/tsProject.js');
lilaGulp('LichessTournamentSchedule', 'lichess.tournament-schedule', __dirname);
lilaGulp('LichessTournamentSchedule', 'lichess.tournamentSchedule', __dirname);