-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kte): kte now working without development mode on (#25)
* fix(kte): kte now working without development mode on * fix(local-development): upgraded version, kte creates now custom jteviewresolver and viewcomponent annotation now can override bean name of component annotation * Update version to 0.8.4-SNAPSHOT Changed all dependencies and version properties from 0.8.4 to 0.8.4-SNAPSHOT for ongoing development. This ensures the project uses the latest snapshot versions during development phases. --------- Co-authored-by: Christoph Hagelkruys <christophhagelkruys@MBPvonChristoph.home> Co-authored-by: tschuehly <tschuehly@outlook.com>
- Loading branch information
1 parent
69c8580
commit 09f2e5f
Showing
15 changed files
with
74 additions
and
52 deletions.
There are no files selected for viewing
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
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
3 changes: 2 additions & 1 deletion
3
core/src/main/kotlin/de/tschuehly/spring/viewcomponent/core/component/ViewComponent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package de.tschuehly.spring.viewcomponent.core.component | ||
|
||
import org.springframework.core.annotation.AliasFor | ||
import org.springframework.stereotype.Component | ||
|
||
|
||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Component | ||
annotation class ViewComponent | ||
annotation class ViewComponent(@get:AliasFor(annotation = Component::class, attribute = "value") val value: String = "") | ||
|
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
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
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
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
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
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
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
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
67 changes: 44 additions & 23 deletions
67
kte/src/main/kotlin/de/tschuehly/spring/viewcomponent/kte/KteConfiguration.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,76 @@ | ||
package de.tschuehly.spring.viewcomponent.kte | ||
|
||
import de.tschuehly.spring.viewcomponent.core.component.ViewComponentProperties | ||
import gg.jte.CodeResolver | ||
import gg.jte.ContentType | ||
import gg.jte.TemplateEngine | ||
import gg.jte.resolve.DirectoryCodeResolver | ||
import gg.jte.springframework.boot.autoconfigure.JteProperties | ||
import gg.jte.springframework.boot.autoconfigure.JteViewResolver | ||
import org.springframework.beans.factory.BeanClassLoaderAware | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | ||
import org.springframework.context.ApplicationContext | ||
import org.springframework.context.annotation.* | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Primary | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
@Configuration | ||
class KteConfiguration { | ||
class KteConfiguration : BeanClassLoaderAware { | ||
var classLoader: ClassLoader? = null | ||
|
||
@Bean | ||
fun kteViewContextAspect(templateEngine: TemplateEngine, jteProperties: JteProperties): KteViewContextAspect { | ||
fun kteViewContextAspect( | ||
templateEngine: TemplateEngine, | ||
jteProperties: JteProperties | ||
): KteViewContextAspect { | ||
return KteViewContextAspect(templateEngine, jteProperties) | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(TemplateEngine::class) | ||
fun jteTemplateEngine(viewComponentProperties: ViewComponentProperties,applicationContext: ApplicationContext): TemplateEngine { | ||
if (!viewComponentProperties.localDevelopment) { | ||
return TemplateEngine.createPrecompiled( | ||
/* classDirectory = */ Path.of(this.javaClass.classLoader.getResource("").toURI()), | ||
/* contentType = */ ContentType.Html, | ||
/* parentClassLoader = */ this.javaClass.classLoader | ||
fun kteNonLocalTemplateEngine(viewComponentProperties: ViewComponentProperties): TemplateEngine { | ||
if (viewComponentProperties.localDevelopment) { | ||
val split = getViewComponentRootPath(viewComponentProperties).split("/") | ||
.toTypedArray() | ||
val codeResolver: CodeResolver = | ||
DirectoryCodeResolver(FileSystems.getDefault().getPath("", *split)) | ||
return TemplateEngine.create( | ||
codeResolver, | ||
Paths.get("jte-classes"), | ||
ContentType.Html, | ||
classLoader | ||
) | ||
} | ||
val split = getViewComponentRootPath(viewComponentProperties).split("/").toTypedArray() | ||
val codeResolver: CodeResolver = DirectoryCodeResolver(FileSystems.getDefault().getPath("", *split)) | ||
return TemplateEngine.create( | ||
codeResolver, | ||
Paths.get("jte-classes"), | ||
ContentType.Html, | ||
Thread.currentThread().contextClassLoader | ||
return TemplateEngine.createPrecompiled( | ||
/* classDirectory = */ Path.of( | ||
classLoader?.getResource("")?.toURI() | ||
?: throw RuntimeException("ClassLoader is null") | ||
), | ||
/* contentType = */ ContentType.Html, | ||
/* parentClassLoader = */ classLoader | ||
) | ||
} | ||
|
||
@Bean | ||
fun kteViewResolver(templateEngine: TemplateEngine?): JteViewResolver { | ||
return JteViewResolver(templateEngine, ".kte") | ||
} | ||
|
||
@Bean | ||
@Primary | ||
fun jteProperties(viewComponentProperties: ViewComponentProperties) = JteProperties().also { | ||
it.templateSuffix = ".kte" | ||
it.templateLocation = getViewComponentRootPath(viewComponentProperties) | ||
it.isDevelopmentMode = viewComponentProperties.localDevelopment | ||
fun jteProperties(viewComponentProperties: ViewComponentProperties) = | ||
JteProperties().also { | ||
it.templateSuffix = ".kte" | ||
it.templateLocation = getViewComponentRootPath(viewComponentProperties) | ||
it.isDevelopmentMode = viewComponentProperties.localDevelopment | ||
} | ||
|
||
override fun setBeanClassLoader(classLoader: ClassLoader) { | ||
this.classLoader = classLoader | ||
} | ||
|
||
private fun getViewComponentRootPath(viewComponentProperties: ViewComponentProperties): String = | ||
if (viewComponentProperties.viewComponentRoot == "src/main/java") "src/main/kotlin" else viewComponentProperties.viewComponentRoot | ||
|
||
|
||
} |
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
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
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