https://github.com/nosix/thymeleaf-dialect
Thymeleaf Dialect for custom tags in Kotlin.
https://github.com/nosix/thymeleaf-dialect
Last synced: 2 months ago
JSON representation
Thymeleaf Dialect for custom tags in Kotlin.
- Host: GitHub
- URL: https://github.com/nosix/thymeleaf-dialect
- Owner: nosix
- License: apache-2.0
- Created: 2016-12-14T15:06:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-03T10:09:07.000Z (almost 8 years ago)
- Last Synced: 2025-01-02T11:09:14.620Z (4 months ago)
- Language: Kotlin
- Size: 88.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# thymeleaf-dialect
Thymeleaf Dialect for custom tags in Kotlin.
For example, when you want to use Thymeleaf with AngularJS 1 and UI Bootstrap, this library may be useful.
## Testing Version
Thymeleaf : 2.1.5
## Usage
build.gradle :
```
repositories {
mavenCentral()
maven {
url 'http://nosix.github.io/thymeleaf-dialect/'
}
}dependencies {
compile 'org.musyozoku:thymeleaf-dialect:0.0.2'
}
```WebApplication.kt :
```
@SpringBootApplication
open class WebApplication {private val TEMPLATE_MODE = "LOOSE_HTML5"
private val POOL_SIZE = Runtime.getRuntime().availableProcessors().let {
Math.min(if (it <= 2) it else it - 1, 24) // see StandardTemplateModeHandlers
}@Bean
open fun viewResolver() = ThymeleafViewResolver().apply {
templateEngine = templateEngine()
}@Bean
open fun templateEngine() = SpringTemplateEngine().apply {
templateResolvers = setOf(templateResolver())
templateModeHandlers = setOf(TemplateModeHandler(
TEMPLATE_MODE,
LegacyHtml5TemplateParser(TEMPLATE_MODE, POOL_SIZE),
SingleQuoteUnEscapeTemplateWriter())) // ' is not escaped to '
setDialect(CustomSpringDialect.Builder()
.enableAngularJS1()
.enableUIBootstrap()
.toBeModified("my-attr")
.toBeRenamed("my-tag")
.build())
}@Bean
open fun templateResolver() = SpringResourceTemplateResolver().apply {
templateMode = TEMPLATE_MODE
prefix = "classpath:/templates/"
suffix = ".html"
isCacheable = false // TODO: make it true before release
}
}
```If you want to escape `'` to `'`, see below.
```
@SpringBootApplication
open class WebApplication {private val TEMPLATE_MODE = "LOOSE_HTML5"
@Bean
open fun viewResolver() = ThymeleafViewResolver().apply {
templateEngine = templateEngine()
}@Bean
open fun templateEngine() = SpringTemplateEngine().apply {
templateResolvers = setOf(templateResolver())
setDialect(CustomSpringDialect.Builder()
.enableAngularJS1()
.enableUIBootstrap()
.toBeModified("my-attr")
.toBeRenamed("my-tag")
.build())
}@Bean
open fun templateResolver() = SpringResourceTemplateResolver().apply {
templateMode = TEMPLATE_MODE
prefix = "classpath:/templates/"
suffix = ".html"
isCacheable = false // TODO: make it true before release
}
}
```## Sample
```
- required
```## List of prepared attributes
[SupportAttributes.kt](https://github.com/nosix/thymeleaf-dialect/blob/master/src/main/kotlin/org/musyozoku/thymeleaf/dialect/SupportAttributes.kt)
## Extensions
[BuilderExtensions.kt](https://github.com/nosix/thymeleaf-dialect/blob/master/src/main/kotlin/org/musyozoku/thymeleaf/dialect/BuilderExtensions.kt)
- enableAngularJS1()
- add ANGULAR_JS_1 attributes
- add `script` tag
- enableUIBootstrap()
- add UI_BOOTSTRAP attributes