Skip to content

Commit

Permalink
Replace usage js with WasmJs in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Feb 6, 2024
1 parent b6baa5f commit f73f0bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
47 changes: 32 additions & 15 deletions README.md
Expand Up @@ -6,34 +6,51 @@

# kotlinx.html

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.
A kotlinx.html library provides a 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.

# Get started

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

# DOM
You can build DOM tree with JVM and JS naturally
You can build a DOM tree with JVM, JS, and WASM naturally

See example for JavaScript-targeted Kotlin
See example for WasmJs-targeted Kotlin:

```kotlin
window.setInterval({
val myDiv = document.create.div("panel") {
p {
+"Here is "
a("https://kotlinlang.org") { +"official Kotlin site" }
}
}

document.getElementById("container")!!.appendChild(myDiv)
import kotlinx.browser.document
import kotlinx.browser.window
import kotlinx.html.a
import kotlinx.html.div
import kotlinx.html.dom.append
import kotlinx.html.dom.create
import kotlinx.html.p

document.getElementById("container")!!.append {
fun main() {
val body = document.body ?: error("No body")
body.append {
div {
+"added it"
p {
+"Here is "
a("https://kotlinlang.org") { +"official Kotlin site" }
}
}
}
}, 1000L)

val timeP = document.create.p {
+"Time: 0"
}

body.append(timeP)

var time = 0
window.setInterval({
time++
timeP.textContent = "Time: $time"

return@setInterval null
}, 1000)
}
```

# Stream
Expand Down
36 changes: 2 additions & 34 deletions build.gradle.kts
Expand Up @@ -4,8 +4,8 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

/**
* This build script supports following parameters:
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
* This build script supports the following parameters:
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
*/
plugins {
kotlin("multiplatform") version "1.9.22"
Expand Down Expand Up @@ -206,38 +206,6 @@ tasks.register<Task>("generate") {
}
}

tasks.register<Copy>("jsPackagePrepare") {
dependsOn("jsLegacyMainClasses")
tasks["assemble"].dependsOn(this)

group = "build"
description = "Assembles NPM package (result is placed into 'build/tmp/jsPackage')."

val baseTargetDir = "$buildDir/tmp/jsPackage"

from("README-JS.md")
from("$buildDir/js/packages/${project.name}/kotlin")
into(baseTargetDir)

rename("README-JS.md", "README.md")

doLast {
var npmVersion = version as String
if (npmVersion.endsWith("-SNAPSHOT")) {
npmVersion = npmVersion.replace("-SNAPSHOT", "-${System.currentTimeMillis()}")
}

val organization = when {
project.hasProperty("branch-build") -> "kotlinx-branch-build"
project.hasProperty("master-build") -> "kotlinx-master-build"
else -> null
}

File(baseTargetDir, "package.json").writeText(packageJson(npmVersion, organization))
file("$baseTargetDir/kotlinx-html-js").renameTo(File("$buildDir/js-module/kotlinx-html-js"))
}
}

publishing {
publications {
configureEach {
Expand Down

0 comments on commit f73f0bd

Please sign in to comment.