Skip to content

Commit

Permalink
Add Pebble request() function
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin-marginean committed May 6, 2024
1 parent c11812c commit 1a28399
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
invirtVersion = 0.8.27
invirtVersion = 0.8.28
kotlinVersion = 1.9.23
http4kVersion = 5.17.0.0
mockkVersion = 1.13.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class InvirtPebbleExtension : AbstractExtension() {
jsonFunction,
jsonArrayFunction,

// Request query
// Request
requestFunction,
replaceQueryFunction,
replacePageFunction,
removeQueryValueFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ val currencyFromMinorUnitFunction = pebbleFunction("currencyFromMinorUnit", "min
val errorsFunction = pebbleFunction("errors") {
validationErrorContextKey[currentHttp4kRequest!!]
}

val requestFunction = pebbleFunction("request") {
currentHttp4kRequest!!
}
18 changes: 13 additions & 5 deletions invirt-http4k/src/test/kotlin/invirt/pebble/PebbleFunctionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package invirt.pebble

import invirt.data.Page
import invirt.http4k.StoreRequestOnThread
import invirt.http4k.views.Views
import invirt.http4k.views.ok
import invirt.http4k.views.renderTemplate
import invirt.http4k.views.setDefaultViewLens
import invirt.http4k.views.withView
import invirt.http4k.views.*
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.comparables.shouldBeGreaterThan
import io.kotest.matchers.shouldBe
Expand All @@ -28,6 +24,18 @@ class PebbleFunctionsTest : StringSpec() {
testFunction("today", "/test", "${LocalDate.now()}")
}

"request" {
testFunction(
"request",
"/test?q=john",
"""
GET
/test?q=john
john
""".trimIndent()
)
}

"replaceQuery" {
testFunction("replaceQuery", "/test", "/test?from=10")
testFunction("replaceQuery", "/test?from=5", "/test?from=10")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ request().method }}

{{ request().uri }}

{{ request().query("q") }}

0 comments on commit 1a28399

Please sign in to comment.