An open API service indexing awesome lists of open source software.

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.

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