diff --git a/json-builder/kotlin/proguard-rules.pro b/json-builder/kotlin/proguard-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Property.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Property.kt index 3f25abdf0..2ee896a0b 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Property.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Property.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl sealed class Property diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Root.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Root.kt index 4f1fc2a63..2dbb40ef5 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Root.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/Root.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl /** diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardContext.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardContext.kt index 28eb00ebf..1015e5422 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardContext.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardContext.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.context import com.fasterxml.jackson.annotation.JsonIgnore @@ -11,6 +8,7 @@ import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract +@Deprecated("Use divkit.dsl framework") class CardContext { @JvmField @@ -27,6 +25,7 @@ class CardContext { } @OptIn(ExperimentalContracts::class) +@Deprecated("Use divkit.dsl framework") fun card( initialize: CardContext.() -> Root ): CardContext { diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardWithTemplates.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardWithTemplates.kt index 3f73be985..6a1446a1d 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardWithTemplates.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/CardWithTemplates.kt @@ -4,4 +4,5 @@ import com.fasterxml.jackson.annotation.JsonInclude import com.yandex.div.dsl.model.Div @JsonInclude(JsonInclude.Include.NON_NULL) +@Deprecated("Use divkit.dsl framework") data class CardWithTemplates(val card: CardContext, val templates: TemplateContext
? = null) diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/TemplateContext.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/TemplateContext.kt index aba645934..7e0a9992d 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/TemplateContext.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/TemplateContext.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.context import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -12,6 +9,7 @@ import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract +@Deprecated("Use divkit.dsl framework") class TemplateContext { @JvmField @@ -42,6 +40,7 @@ class TemplateContext { } @OptIn(ExperimentalContracts::class) +@Deprecated("Use divkit.dsl framework") fun templates(initialize: TemplateContext.() -> Unit): TemplateContext { contract { callsInPlace(initialize, InvocationKind.EXACTLY_ONCE) diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/Templates.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/Templates.kt index a506a5f80..5cf461282 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/Templates.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/context/Templates.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.context import com.yandex.div.dsl.Property diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/BoolIntSerializer.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/BoolIntSerializer.kt index 333d9f9e9..638b1b183 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/BoolIntSerializer.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/BoolIntSerializer.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.serializer import com.fasterxml.jackson.core.JsonGenerator diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/ColorSerializer.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/ColorSerializer.kt index 41a2659a4..aeda2c29f 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/ColorSerializer.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/ColorSerializer.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.serializer import com.fasterxml.jackson.core.JsonGenerator diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/Contexts.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/Contexts.kt index 4343e685d..974762ffb 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/Contexts.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/serializer/Contexts.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.serializer import com.fasterxml.jackson.annotation.JsonInclude diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/BoolInt.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/BoolInt.kt index 377710a51..df6a58425 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/BoolInt.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/BoolInt.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.type import com.fasterxml.jackson.databind.annotation.JsonSerialize diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/Color.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/Color.kt index ae675ee9c..2a2895a30 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/Color.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/type/Color.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.type import com.fasterxml.jackson.databind.annotation.JsonSerialize diff --git a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/util/PropertyMap.kt b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/util/PropertyMap.kt index d2e6b9416..379562e24 100644 --- a/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/util/PropertyMap.kt +++ b/json-builder/kotlin/src/main/kotlin/com/yandex/div/dsl/util/PropertyMap.kt @@ -1,6 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. -// Author: Anton Gulevsky . - package com.yandex.div.dsl.util import com.yandex.div.dsl.ExpressionProperty diff --git a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/CardWithTemplatesTest.kt b/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/CardWithTemplatesTest.kt index 5a435030e..701489c00 100644 --- a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/CardWithTemplatesTest.kt +++ b/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/CardWithTemplatesTest.kt @@ -1,5 +1,3 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. - package com.yandex.div.dsl import com.fasterxml.jackson.databind.node.JsonNodeFactory @@ -9,7 +7,6 @@ import com.yandex.div.dsl.context.define import com.yandex.div.dsl.context.override import com.yandex.div.dsl.context.resolve import com.yandex.div.dsl.context.templates -import com.yandex.div.dsl.model.Div import com.yandex.div.dsl.model.DivContainer import com.yandex.div.dsl.model.DivSizeUnit import com.yandex.div.dsl.model.divAction @@ -22,17 +19,18 @@ import com.yandex.div.dsl.model.divWrapContentSize import com.yandex.div.dsl.model.state import com.yandex.div.dsl.model.template import com.yandex.div.dsl.serializer.toJsonNode +import divkit.dsl.readResource import java.net.URI import org.junit.jupiter.api.Test import org.skyscreamer.jsonassert.JSONAssert.assertEquals import org.skyscreamer.jsonassert.JSONCompareMode -internal class CardWithTemplatesTest { +class CardWithTemplatesTest { @Test - internal fun renderCard() { + fun renderCard() { val titleRef = reference("title") - val templates = templates
{ + val templates = templates { define ("title_text", divText( width = divFixedSize( @@ -42,30 +40,6 @@ internal class CardWithTemplatesTest { text = titleRef ) ) - define("header", - divContainer( - orientation = enum(DivContainer.Orientation.VERTICAL), - items = listOf( - divText( - width = divWrapContentSize(), - height = divFixedSize( - value = int(60), - ), - text = titleRef - ), - template( - type = "title_text", - override("width", divWrapContentSize()) - ) - ) - ) - ) - define("subtitle_text", - template( - type = "title_text", - override("width", divWrapContentSize()) - ) - ) } val card = card { divData( diff --git a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/DistrictCardTest.kt b/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/DistrictCardTest.kt index ec16ecc45..b18006779 100644 --- a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/DistrictCardTest.kt +++ b/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/DistrictCardTest.kt @@ -2,7 +2,6 @@ package com.yandex.div.dsl import com.fasterxml.jackson.databind.node.JsonNodeFactory import com.fasterxml.jackson.databind.node.ObjectNode -import com.yandex.div.dsl.context.TemplateContext import com.yandex.div.dsl.context.card import com.yandex.div.dsl.context.define import com.yandex.div.dsl.context.override @@ -37,6 +36,7 @@ import com.yandex.div.dsl.model.template import com.yandex.div.dsl.serializer.toJsonNode import com.yandex.div.dsl.type.BoolInt import com.yandex.div.dsl.type.color +import divkit.dsl.readResource import org.junit.jupiter.api.Test import org.skyscreamer.jsonassert.JSONAssert import org.skyscreamer.jsonassert.JSONCompareMode @@ -59,7 +59,7 @@ class DistrictCardTest { val galleryTailActionLinkRef = reference("gallery_tail_action_link") val tailTextLinkRef = reference("tail_text_link") - val templates: TemplateContext
= templates
{ + val templates = templates { define( "title_text", divText( diff --git a/json-builder/kotlin/src/test/kotlin/divkit/dsl/DivanTest.kt b/json-builder/kotlin/src/test/kotlin/divkit/dsl/DivanTest.kt new file mode 100644 index 000000000..a3825bd3c --- /dev/null +++ b/json-builder/kotlin/src/test/kotlin/divkit/dsl/DivanTest.kt @@ -0,0 +1,65 @@ +package divkit.dsl + +import com.fasterxml.jackson.databind.json.JsonMapper +import divkit.dsl.core.bind +import divkit.dsl.core.reference +import org.junit.jupiter.api.Test +import org.skyscreamer.jsonassert.JSONAssert.assertEquals +import org.skyscreamer.jsonassert.JSONCompareMode + +class DivanTest { + + @Test + fun buildCardWithTemplate() { + val titleRef = reference("title") + + val titleTemplate = template("title_text") { + text( + width = fixedSize( + value = 120, + unit = dp + ) + ) + textRefs(text = titleRef) + } + + val divan = divan { + data( + logId = "layout", + states = singleRoot( + div = container( + width = fixedSize( + value = 320 + ), + height = fixedSize( + value = 320 + ), + orientation = vertical, + items = listOf( + render( + titleTemplate, + titleRef bind "Good news, everyone!" + ) + textProps( + width = matchParentSize() + ), + text( + width = wrapContentSize(), + height = wrapContentSize(), + text = "Hello, Everyone!", + actions = listOf( + action( + logId = "tap_action", + url = url("https://yandex.ru") + ) + ) + ) + ) + ) + ) + ) + } + + val expected = readResource("/json/card_with_templates.json") + val actual = JsonMapper.builder().build().writeValueAsString(divan) + assertEquals(expected, actual, JSONCompareMode.STRICT) + } +} diff --git a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/Resources.kt b/json-builder/kotlin/src/test/kotlin/divkit/dsl/Utils.kt similarity index 51% rename from json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/Resources.kt rename to json-builder/kotlin/src/test/kotlin/divkit/dsl/Utils.kt index ef9de3321..e66385365 100644 --- a/json-builder/kotlin/src/test/kotlin/com/yandex/div/dsl/Resources.kt +++ b/json-builder/kotlin/src/test/kotlin/divkit/dsl/Utils.kt @@ -1,10 +1,8 @@ -// Copyright (c) 2022 Yandex LLC. All rights reserved. - -package com.yandex.div.dsl +package divkit.dsl import java.nio.file.Files import java.nio.file.Path -internal fun readResource(path: String): String { +fun readResource(path: String): String { return Files.readString(Path.of(object {}.javaClass.getResource(path).toURI())) } diff --git a/json-builder/kotlin/src/test/resources/json/card_with_templates.json b/json-builder/kotlin/src/test/resources/json/card_with_templates.json index 8b7d95996..4b6a669cc 100644 --- a/json-builder/kotlin/src/test/resources/json/card_with_templates.json +++ b/json-builder/kotlin/src/test/resources/json/card_with_templates.json @@ -8,35 +8,6 @@ "unit": "dp", "value": 120 } - }, - "header": { - "type": "container", - "items": [ - { - "type": "text", - "height": { - "type": "fixed", - "value": 60 - }, - "$text": "title", - "width": { - "type": "wrap_content" - } - }, - { - "type": "title_text", - "width": { - "type": "wrap_content" - } - } - ], - "orientation": "vertical" - }, - "subtitle_text": { - "type": "title_text", - "width": { - "type": "wrap_content" - } } }, "card": {