Last active
February 3, 2017 17:03
-
-
Save Daxten/b022f3076ec92df43e9efeada53ada28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val template = s""" | |
|trait RouteTrait extends ExtendedController with SimpleRouter with OptionalAuthElement with AuthConfigImpl with Circe { | |
| def routes: Router.Routes = { | |
| | |
| case GET(p"/pets" ? q_o"tags=$$tags" ? q_o"limit=$$limit") => AsyncStack { implicit request => | |
| constructResult(findPets(tags, limit)) | |
| } | |
| | |
| case POST(p"/pets") => AsyncStack(circe.json) { implicit request => | |
| constructResult(addPet()) | |
| } | |
| | |
| case GET(p"/pets/$${int(id)}") => AsyncStack { implicit request => | |
| constructResult(findPetById(id)) | |
| } | |
| | |
| case DELETE(p"/pets/$${int(id)}") => AsyncStack { implicit request => | |
| constructResult(deletePet(id)) | |
| } | |
| | |
| } | |
| | |
| def findPets(tags: Option[String], limit: Option[String])(implicit request: RequestWithAttributes[AnyContent]): HttpResult[Result] | |
| def addPet()(implicit request: RequestWithAttributes[AnyContent]): HttpResult[Result] | |
| def findPetById(id: Int)(implicit request: RequestWithAttributes[AnyContent]): HttpResult[Result] | |
| def deletePet(id: Int)(implicit request: RequestWithAttributes[AnyContent]): HttpResult[Result] | |
|} | |
""".stripMargin.trim | |
val source = | |
s""" | |
|trait RouteTrait { | |
| | |
|} | |
""".stripMargin | |
import scala.meta._ | |
val templateTree = template.parse[Source].get.collect { | |
case c @q"..$mods trait $tname[..$tparams] extends $template" => | |
c | |
}.headOption.get | |
val sourceTree = source.parse[Source].get.transform { | |
case c @q"..$mods trait $tname[..$tparams] extends $template" => | |
templateTree | |
} | |
sourceTree.syntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: