Skip to content

Commit 6c926dd

Browse files
authored
Replace usage js with WasmJs in README.md (#257)
1 parent b6baa5f commit 6c926dd

File tree

2 files changed

+44
-51
lines changed

2 files changed

+44
-51
lines changed

README.md

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,61 @@
66

77
# kotlinx.html
88

9-
A kotlinx.html library provides DSL to build HTML to [Writer](https://docs.oracle.com/javase/8/docs/api/java/io/Writer.html)/[Appendable](https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html) or DOM. Available to all Kotlin Multiplatform targets and browser(or other JavaScript engine) for better [Kotlin programming](https://kotlinlang.org) for Web.
9+
The kotlinx.html library provides a DSL
10+
to build HTML
11+
to [Writer](https://docs.oracle.com/javase/8/docs/api/java/io/Writer.html)/[Appendable](https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html)
12+
or DOM.
13+
Available to all Kotlin Multiplatform targets and browsers (or other WasmJS or JavaScript engines)
14+
for better [Kotlin programming](https://kotlinlang.org) for Web.
1015

1116
# Get started
1217

13-
See [Getting started](https://github.com/kotlin/kotlinx.html/wiki/Getting-started) page for details how to include the library.
18+
See [Getting started](https://github.com/kotlin/kotlinx.html/wiki/Getting-started) page for details how to include the
19+
library.
1420

1521
# DOM
16-
You can build DOM tree with JVM and JS naturally
1722

18-
See example for JavaScript-targeted Kotlin
23+
You can build a DOM tree with JVM, JS, and WASM.
24+
The following example shows how to build the DOM for WasmJs-targeted Kotlin:
1925

2026
```kotlin
21-
window.setInterval({
22-
val myDiv = document.create.div("panel") {
23-
p {
24-
+"Here is "
25-
a("https://kotlinlang.org") { +"official Kotlin site" }
26-
}
27-
}
28-
29-
document.getElementById("container")!!.appendChild(myDiv)
27+
import kotlinx.browser.document
28+
import kotlinx.browser.window
29+
import kotlinx.html.a
30+
import kotlinx.html.div
31+
import kotlinx.html.dom.append
32+
import kotlinx.html.dom.create
33+
import kotlinx.html.p
3034

31-
document.getElementById("container")!!.append {
35+
fun main() {
36+
val body = document.body ?: error("No body")
37+
body.append {
3238
div {
33-
+"added it"
39+
p {
40+
+"Here is "
41+
a("https://kotlinlang.org") { +"official Kotlin site" }
42+
}
3443
}
3544
}
36-
}, 1000L)
45+
46+
val timeP = document.create.p {
47+
+"Time: 0"
48+
}
49+
50+
body.append(timeP)
51+
52+
var time = 0
53+
window.setInterval({
54+
time++
55+
timeP.textContent = "Time: $time"
56+
57+
return@setInterval null
58+
}, 1000)
59+
}
3760
```
3861

3962
# Stream
63+
4064
You can build HTML directly to Writer (JVM) or Appendable (Multiplatform)
4165

4266
```kotlin
@@ -56,6 +80,7 @@ System.out.appendHTML().html {
5680

5781
See [wiki](https://github.com/kotlin/kotlinx.html/wiki) pages
5882

59-
# Building
83+
# Building
84+
6085
See [development](https://github.com/kotlin/kotlinx.html/wiki/Development) page for details.
6186

build.gradle.kts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
44
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
55

66
/**
7-
* This build script supports following parameters:
8-
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
7+
* This build script supports the following parameters:
8+
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
99
*/
1010
plugins {
1111
kotlin("multiplatform") version "1.9.22"
@@ -206,38 +206,6 @@ tasks.register<Task>("generate") {
206206
}
207207
}
208208

209-
tasks.register<Copy>("jsPackagePrepare") {
210-
dependsOn("jsLegacyMainClasses")
211-
tasks["assemble"].dependsOn(this)
212-
213-
group = "build"
214-
description = "Assembles NPM package (result is placed into 'build/tmp/jsPackage')."
215-
216-
val baseTargetDir = "$buildDir/tmp/jsPackage"
217-
218-
from("README-JS.md")
219-
from("$buildDir/js/packages/${project.name}/kotlin")
220-
into(baseTargetDir)
221-
222-
rename("README-JS.md", "README.md")
223-
224-
doLast {
225-
var npmVersion = version as String
226-
if (npmVersion.endsWith("-SNAPSHOT")) {
227-
npmVersion = npmVersion.replace("-SNAPSHOT", "-${System.currentTimeMillis()}")
228-
}
229-
230-
val organization = when {
231-
project.hasProperty("branch-build") -> "kotlinx-branch-build"
232-
project.hasProperty("master-build") -> "kotlinx-master-build"
233-
else -> null
234-
}
235-
236-
File(baseTargetDir, "package.json").writeText(packageJson(npmVersion, organization))
237-
file("$baseTargetDir/kotlinx-html-js").renameTo(File("$buildDir/js-module/kotlinx-html-js"))
238-
}
239-
}
240-
241209
publishing {
242210
publications {
243211
configureEach {

0 commit comments

Comments
 (0)