Skip to content

Commit

Permalink
Update examples, fix routes generation in Ktor DSL parser
Browse files Browse the repository at this point in the history
  • Loading branch information
TanVD committed Feb 8, 2020
1 parent 360623e commit 609587c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ inline fun <reified Desc : DeclarationDescriptorWithSource, reified Elem : PsiEl
}
}

/** Gather all expressions inside current — recursively */
/**
* Gather all expressions inside current — recursively
*
* Previous is sorted from the nearest element (at the start) to the most distant
*/
fun KtElement.visit(context: BindingContext, body: (element: KtElement, previous: List<KtElement>) -> Boolean) {
val stack = Stack<KtElement>()
val previous = Stack<KtElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal object DynamicRoutesProcessor : SubTypesProcessor<Unit>() {
val routeCalls = previous.filter { it is KtCallExpression && it.getFqName(binding) == "io.ktor.routing.route" }
val path = routeCalls.map {
(it as KtCallExpression).getArgumentOrNull("path", binding)?.asString(binding) ?: ""
}
}.filter { it.isNotBlank() }.reversed()
return URIPath(path.joinToString(separator = "/"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal object StaticRoutesProcessor : SubTypesProcessor<Unit>() {
val staticCalls = previous.filter { it is KtCallExpression && it.getFqName(binding) == "io.ktor.http.content.static" }
val path = staticCalls.map {
(it as KtCallExpression).getArgumentOrNull("remotePath", binding)?.asString(binding) ?: ""
}
}.filter { it.isNotBlank() }.reversed()
return URIPath(path.joinToString(separator = "/"))
}

Expand Down
14 changes: 5 additions & 9 deletions examples/kotless-shortener/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import io.kotless.DSLType
import io.kotless.plugin.gradle.dsl.KotlessConfig
import io.kotless.plugin.gradle.dsl.Webapp.Route53
import io.kotless.plugin.gradle.dsl.kotless

group = "io.kotless"
group = "io.kotless.examples"
version = "0.1.0"

plugins {
Expand Down Expand Up @@ -45,16 +43,14 @@ kotless {
}

webapp {
lambda {
kotless {
packages = setOf("io.kotless.examples")
}
}

route53 = Route53("short", "kotless.io")
}

extensions {
local {
useAWSEmulation = true
}

terraform {
files {
add(file("src/main/tf/extensions.tf"))
Expand Down
15 changes: 1 addition & 14 deletions examples/kotless-site/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import io.kotless.DSLType
import io.kotless.plugin.gradle.dsl.Webapp.Route53
import io.kotless.plugin.gradle.dsl.kotless

group = "io.kotless"
group = "io.kotless.examples"
version = "0.1.3"

plugins {
Expand Down Expand Up @@ -40,19 +39,7 @@ kotless {
}

webapp {
lambda {
kotless {
packages = setOf("io.kotless.examples")
}
}

route53 = Route53("site", "kotless.io")
}

extensions {
local {
useAWSEmulation = false
}
}
}

4 changes: 4 additions & 0 deletions examples/ktor-shortener/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ kotless {
}

extensions {
local {
useAWSEmulation = true
}

terraform {
files {
add(file("src/main/tf/extensions.tf"))
Expand Down
7 changes: 0 additions & 7 deletions examples/ktor-site/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io.kotless.DSLType
import io.kotless.plugin.gradle.dsl.Webapp.Route53
import io.kotless.plugin.gradle.dsl.kotless
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
Expand Down Expand Up @@ -47,11 +46,5 @@ kotless {
webapp {
route53 = Route53("ktor.site", "kotless.io")
}

extensions {
local {
useAWSEmulation = false
}
}
}

0 comments on commit 609587c

Please sign in to comment.