Skip to content

Instantly share code, notes, and snippets.

@alebon
Last active December 31, 2015 09:34
Show Gist options
  • Save alebon/12c4639dc4218b2ea614 to your computer and use it in GitHub Desktop.
Save alebon/12c4639dc4218b2ea614 to your computer and use it in GitHub Desktop.
object JsFunctions {
// Some more code here, using the buildServiceFunctions method
def buildServerFunctions(name: String, funcs: List[RoundTripInfo], session: Box[LiftSession]): JsCmd = {
JsRaw("""lift_serverFunctions().apply('%s', %s)"""
.format(name, session.getOrElse(throw new Exception("Session required")).buildRoundtrip(funcs).toJsCmd).stripMargin).cmd
}
}
trait NgAccountService extends NgService {
def ngAccountServerFunctions(xhtml: NodeSeq): NodeSeq = {
val serverFunctionMappings = List[RoundTripInfo](
"signup" -> this.ngAccountService_signup _)
this.applyService("accountService", serverFunctionMappings)
}
/**
* Sends activation mail (with activation link)
*
* @param emailValue
* @return
*/
protected def ngAccountService_signup(emailValue: String): JsonAST.JValue = {
// Some BL here
val hostAndPath = S.hostAndPath
// Response value
}
}
class NgPublic extends StatefulSnippet
with NgAccountService {
override def dispatch: DispatchIt = {
case "accountService" => ngAccountServerFunctions
}
}
trait NgService extends Logger {
protected implicit lazy val formats = DefaultFormats
/**
* Helper method to simplify ngServices
*
* @param serverFunctionMappings
*/
protected def applyService(serviceName: String, serverFunctionMappings: List[RoundTripInfo]): NodeSeq = {
S.putAtEndOfBody(JsFunctions.serverFunctions(serviceName, serverFunctionMappings, S.session))
NodeSeq.Empty
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment