org.webjars.play.RequireJS.scala Maven / Gradle / Ivy
The newest version!
package org.webjars.play
import play.api.mvc.Call
import scala.language.reflectiveCalls
object RequireJS {
def setup(main: String): String = {
// We have to use reflection because the reverse routing is not available in the library project
def nastyReflectedRoute(path: String, routerName: String): Call = {
val clazz = Class.forName("controllers.routes", true, play.api.Play.current.classloader)
val field = clazz.getDeclaredField(routerName)
val routeInstance = field.get(null)
routeInstance.asInstanceOf[{ def at(path: String): Call }].at(path)
}
def nastyReflectedWebJarAssetsRoute(path: String): Call = nastyReflectedRoute(path, "WebJarAssets")
def nastyReflectedAssetsRoute(path: String): Call = nastyReflectedRoute(path, "Assets")
val setupJavaScript: String = org.webjars.RequireJS.getSetupJavaScript(nastyReflectedWebJarAssetsRoute("").url)
val mainRoute = nastyReflectedAssetsRoute(main)
val requireRoute = nastyReflectedWebJarAssetsRoute(controllers.WebJarAssets.locate("require.min.js"))
s"""
|""".stripMargin
}
}