Skip to content

Commit

Permalink
fix a little bug when using inside a Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuehly committed Jun 5, 2024
1 parent 7679e9d commit eb92772
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 48 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ spring.view-component.local-development=true
<summary>Gradle</summary>

```kotlin
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.0")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.1-SNAPSHOT")
sourceSets {
main {
resources {
Expand All @@ -249,7 +249,7 @@ sourceSets {
<dependency>
<groupId>de.tschuehly</groupId>
<artifactId>spring-view-component-thymeleaf</artifactId>
<version>0.8.0</version>
<version>0.8.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -286,7 +286,7 @@ plugins {
id("gg.jte.gradle") version("3.1.12")
}

implementation("de.tschuehly:spring-view-component-jte:0.8.0")
implementation("de.tschuehly:spring-view-component-jte:0.8.1-SNAPSHOT")

jte{
generate()
Expand All @@ -305,7 +305,7 @@ jte{
<dependency>
<groupId>de.tschuehly</groupId>
<artifactId>spring-view-component-jte</artifactId>
<version>0.8.0</version>
<version>0.8.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -343,7 +343,7 @@ jte{
<summary>Gradle</summary>

```kotlin
implementation("de.tschuehly:spring-view-component-kte:0.8.0")
implementation("de.tschuehly:spring-view-component-kte:0.8.1-SNAPSHOT")
jte{
generate()
sourceDirectory = Path("src/main/kotlin")
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.0"
version = "0.8.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import org.springframework.context.ApplicationContext
interface IViewContext {
companion object {
var applicationContext: ApplicationContext? = null
var componentTemplate: String? = null
var templateSuffx: String = ""

fun <T> server(clazz: Class<T>): T{
return applicationContext?.getBean(clazz) ?: throw RuntimeException(clazz.simpleName)
}

fun getViewComponentTemplate(context: IViewContext): String {
return getViewComponentTemplateWithoutSuffix(context) + templateSuffx
}

fun getViewComponentTemplateWithoutSuffix(context: IViewContext): String {
val componentName = getViewComponentName(context.javaClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class ViewComponentAutoConfiguration {
viewComponentProperties: ViewComponentProperties
): FileSystemWatcher {
val fileSystemWatcher = FileSystemWatcher()
val buildDir = applicationContext.getBeansWithAnnotation(ViewComponent::class.java).values.map {
it.javaClass.protectionDomain.codeSource.location.path
}.first()

val viewComponentDirectory = File(viewComponentProperties.viewComponentRoot)
val templateRoot = File(viewComponentProperties.standaloneTemplateRoot)
fileSystemWatcher.addSourceDirectory(viewComponentDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ViewComponentAspect(val applicationContext: ApplicationContext) {
throw ViewComponentException("${returnValue.javaClass} needs to implement ViewContext abstract class")
}
IViewContext.applicationContext = applicationContext
IViewContext.componentTemplate = IViewContext.getViewComponentTemplateWithoutSuffix(viewContext)
return viewContext
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ViewContextMethodReturnValueHandler : HandlerMethodReturnValueHandler {
val viewContext = returnValue?.takeIf {
(IViewContext::class.java.isAssignableFrom(it.javaClass))
} as IViewContext
mavContainer.view = IViewContext.componentTemplate
mavContainer.view = IViewContext.getViewComponentTemplateWithoutSuffix(context = viewContext)
mavContainer.addAttribute(viewContext)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/jte-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ repositories {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")

implementation("de.tschuehly:spring-view-component-jte:0.8.0")
implementation("de.tschuehly:spring-view-component-jte:0.8.1-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.11")
implementation("org.webjars:webjars-locator-core:0.58")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.0"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT"))
}

tasks.withType<Test> {
Expand Down
2 changes: 1 addition & 1 deletion examples/jte-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>JTE Example</description>
<properties>
<java.version>17</java.version>
<view.component.version>0.8.0</view.component.version>
<view.component.version>0.8.1-SNAPSHOT</view.component.version>
</properties>
<dependencies>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions examples/kte-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ repositories {
}

dependencies {
implementation("de.tschuehly:spring-view-component-kte:0.8.0")
implementation("de.tschuehly:spring-view-component-core:0.8.0")
implementation("de.tschuehly:spring-view-component-kte:0.8.1-SNAPSHOT")
implementation("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT")
implementation("io.github.wimdeblauwe:htmx-spring-boot:3.1.1")

implementation("org.webjars.npm:htmx.org:1.9.11")
Expand All @@ -47,7 +47,7 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.0"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT"))
}

tasks.withType<KotlinCompile> {
Expand Down
5 changes: 0 additions & 5 deletions examples/kte-example/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ includeBuild("..\\..\\kte"){
substitute(module("de.tschuehly:spring-view-component-kte")).using(project(":"))
}
}
includeBuild("..\\..\\jte"){
dependencySubstitution {
substitute(module("de.tschuehly:spring-view-component-jte")).using(project(":"))
}
}
includeBuild("..\\..\\core"){
dependencySubstitution {
substitute(module("de.tschuehly:spring-view-component-core")).using(project(":"))
Expand Down
4 changes: 2 additions & 2 deletions examples/thymeleaf-java-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ repositories {

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.0")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.1-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.11")
implementation("org.webjars:webjars-locator-core:0.58")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.0"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT"))
}

tasks.withType<Test> {
Expand Down
2 changes: 1 addition & 1 deletion examples/thymeleaf-java-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Thymeleaf Java Example</description>
<properties>
<java.version>17</java.version>
<view.component.version>0.8.0</view.component.version>
<view.component.version>0.8.1-SNAPSHOT</view.component.version>
</properties>
<dependencies>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions examples/thymeleaf-kotlin-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ repositories {
}

dependencies {
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.0")
implementation("de.tschuehly:spring-view-component-core:0.8.0")
implementation("de.tschuehly:spring-view-component-thymeleaf:0.8.1-SNAPSHOT")
implementation("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT")

implementation("org.webjars.npm:htmx.org:1.9.2")
implementation("org.webjars:webjars-locator:0.47")
Expand All @@ -35,7 +35,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

testImplementation("org.springframework.boot:spring-boot-devtools")
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.0"))
testImplementation(testFixtures("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT"))
}

tasks.withType<KotlinCompile> {
Expand Down
6 changes: 6 additions & 0 deletions examples/thymeleaf-kotlin-example/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ includeBuild("..\\..\\thymeleaf"){
substitute(module("de.tschuehly:spring-view-component-thymeleaf")).using(project(":"))
}
}

includeBuild("..\\..\\core"){
dependencySubstitution {
substitute(module("de.tschuehly:spring-view-component-core")).using(project(":"))
}
}
4 changes: 2 additions & 2 deletions jte/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.0"
version = "0.8.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand All @@ -22,7 +22,7 @@ repositories {
}
dependencies {
api("gg.jte:jte:3.1.12")
api("de.tschuehly:spring-view-component-core:0.8.0")
api("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT")

implementation("gg.jte:jte-spring-boot-starter-3:3.1.12")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class JteViewContextAspect(
//
}

@Pointcut("execution(public de.tschuehly.spring.viewcomponent.jte.ViewContext+ *(..))")
@Pointcut("execution(de.tschuehly.spring.viewcomponent.jte.ViewContext+ *(..))")
fun isRenderOrGetMethod() {
//
}

@AfterReturning(pointcut = "isViewComponent() && isRenderOrGetMethod()", returning = "viewContext")
fun renderInject(viewContext: ViewContext): ViewContext {
ViewContext.templateEngine = jteTemplateEngine
IViewContext.templateSuffx = jteProperties.templateSuffix
ViewContext.templateSuffix = jteProperties.templateSuffix
return viewContext
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tschuehly.spring.viewcomponent.jte

import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.IViewContext.Companion.getViewComponentTemplate
import de.tschuehly.spring.viewcomponent.core.exception.RenderException
import gg.jte.Content
import gg.jte.TemplateEngine
Expand All @@ -10,11 +9,13 @@ import gg.jte.TemplateOutput

interface ViewContext : Content, IViewContext {
companion object{
var templateSuffix: String? = null
var templateEngine: TemplateEngine? = null
}
override fun writeTo(output: TemplateOutput) {
templateEngine?.render(
getViewComponentTemplate(this), this,
IViewContext.getViewComponentTemplateWithoutSuffix(this) + templateSuffix,
this,
output
) ?: throw RenderException("Template Engine not initialized")
}
Expand Down
4 changes: 2 additions & 2 deletions kte/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.0"
version = "0.8.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}
dependencies {
api("gg.jte:jte-kotlin:3.1.12")
api("de.tschuehly:spring-view-component-core:0.8.0")
api("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT")

implementation("gg.jte:jte-spring-boot-starter-3:3.1.12")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KteViewContextAspect(
@AfterReturning(pointcut = "isViewComponent() && isRenderOrGetMethod()", returning = "viewContext")
fun renderInject(viewContext: ViewContext): ViewContext {
ViewContext.templateEngine = jteTemplateEngine
IViewContext.templateSuffx = jteProperties.templateSuffix
ViewContext.templateSuffx = jteProperties.templateSuffix
return viewContext
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tschuehly.spring.viewcomponent.kte

import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.IViewContext.Companion.getViewComponentTemplate
import de.tschuehly.spring.viewcomponent.core.exception.RenderException
import gg.jte.Content
import gg.jte.TemplateEngine
Expand All @@ -10,11 +9,13 @@ import gg.jte.TemplateOutput

interface ViewContext : Content, IViewContext {
companion object{
var templateSuffx: String? = null
var templateEngine: TemplateEngine? = null
}
override fun writeTo(output: TemplateOutput) {
templateEngine?.render(
getViewComponentTemplate(this), this,
IViewContext.getViewComponentTemplateWithoutSuffix(this) + templateSuffx
, this,
output
) ?: throw RenderException("Template Engine not initialized")
}
Expand Down
4 changes: 2 additions & 2 deletions thymeleaf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ plugins {
}

group = "de.tschuehly"
version = "0.8.0"
version = "0.8.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}

dependencies {
api("de.tschuehly:spring-view-component-core:0.8.0")
api("de.tschuehly:spring-view-component-core:0.8.1-SNAPSHOT")
api("org.springframework.boot:spring-boot-devtools")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ThymeleafViewComponentTagProcessor(dialectPrefix: String) :
val modelFactory = webContext.modelFactory
engine.enableSpringELCompiler = true
val viewComponentBody = modelFactory.createText(
engine.process(IViewContext.getViewComponentTemplate(viewContext), webContext)
engine.process(IViewContext.getViewComponentTemplateWithoutSuffix(viewContext), webContext)
)
structureHandler.replaceWith(viewComponentBody, true)

Expand Down

0 comments on commit eb92772

Please sign in to comment.