diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 6 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Template.kt | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index 3a15a4d0..ae26c5de 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -126,7 +126,11 @@ open class Tag( /** * Handlebars template. */ - override var template: (Any?) -> String by refreshOnUpdate() + override var template: ((Any?) -> String)? by refreshOnUpdate() + /** + * Handlebars templates for i18n. + */ + override var templates: Map<String, (Any?) -> String>? by refreshOnUpdate() init { @Suppress("LeakingThis") diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt index a042fc3c..31155209 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt @@ -21,17 +21,26 @@ */ package pl.treksoft.kvision.html +import pl.treksoft.kvision.i18n.I18n + +/** + * Handlebars templates helper interface. + */ interface Template { var content: String? var rich: Boolean - var template: (Any?) -> String + var template: ((Any?) -> String)? + val templates: Map<String, (Any?) -> String>? + /** + * Handlebars template data object. + */ var templateData: Any? get() { return null } set(value) { if (!rich) rich = true - content = template(value) + content = template?.invoke(value) ?: templates?.get(I18n.language)?.invoke(value) } } |