Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 2.17 KB

css_dsl.md

File metadata and controls

51 lines (35 loc) · 2.17 KB

Required dependencies: io.ktor:ktor-server-html-builder, org.jetbrains.kotlin-wrappers:kotlin-css

CSS DSL extends HTML DSL and allows you to author stylesheets in Kotlin by using the kotlin-css wrapper.

Learn how to serve stylesheets as static content from .

Add dependencies {id="add_dependencies"}

CSS DSL doesn't need installation, but requires including the following artifacts in the build script:

  1. The ktor-server-html-builder artifact for HTML DSL:

  2. The kotlin-css-jvm artifact for building CSS: You can replace $kotlin_css_version with the required version of the kotlin-css artifact, for example, %kotlin_css_version%.

Use CSS DSL {id="use_css"}

To send a CSS response, you need to extend ApplicationCall by adding the respondCss method to serialize a stylesheet into a string and send it to the client with the CSS content type:

{src="snippets/caching-headers/src/main/kotlin/com/example/Application.kt" lines="64-66"}

Then, you can provide CSS inside the required route:

{src="snippets/caching-headers/src/main/kotlin/com/example/Application.kt" lines="46-56"}

Finally, you can use the specified CSS for an HTML document created with HTML DSL:

{src="snippets/caching-headers/src/main/kotlin/com/example/Application.kt" lines="34-45"}

You can find the full example here: caching-headers.