ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - phenax/h: Html templating library for kotlin
Html templating library for kotlin. Contribute to phenax/h development by creating an account on GitHub.
Visit Site

GitHub - phenax/h: Html templating library for kotlin

GitHub - phenax/h: Html templating library for kotlin

h

Build Status Codecov branch release License

Html templating library for kotlin.

Get started

Download

  • Download the latest release. (View releases)
  • Clone the repo for the source code git clone https://github.com/phenax/h.
  • Test it with ./gradlew test. Generated test report -> build/reports/tests/test.

Examples

Simple component examples in /examples

Create a component

import io.github.phenax.h.Component
import io.github.phenax.h.Layout
import io.github.phenax.h.node.DOMNode
import io.github.phenax.h.layouts.EmptyLayout

class CardComponent(val myTitle: String): Component() {

  // Layout(EmptyLayout is no wrapper. You can use a custom layout)
  override val layout = EmptyLayout()

  // This renders a div card component
  // <div class="card">
  //   <h1 class="card--title">Card title</h1>
  //   <p class="card--description">Card description</p>
  // </div>
  override fun render(): DOMNode {
    return div( mapOf( "class" to "card" ),
      listOf(
        h1( mapOf( "class" to "card--title" ), myTitle),
        p( mapOf( "class" to "card--description" ), "Card description" )
      )
    )
  }
}

val helloWorldCard = CardComponent("Hello world")

OR

import io.github.phenax.h.*

fun createCard(myTitle: String) = component {
  div( mapOf( "class" to "card" ),
    listOf(
      h1( mapOf( "class" to "card--title" ), myTitle),
      p( mapOf( "class" to "card--description" ), "Card description")
    )
  )
}

val helloWorldCard = createCard("Hello world")

Create a layout

import io.github.phenax.h.Component
import io.github.phenax.h.Layout
import io.github.phenax.h.node.DOMNode

class HtmlLayout(val title: String = "Moosic"): Layout() {
  override fun render(component: AbstractComponent): DOMNode {
    return (
      html(null, listOf(
        head(null, listOf(
          h("title", null, listOf( text(title) ) ),
          style("/css/style.css"),                               // External stylesheet
          style(null, "html, body { background-color: red; }")   // Inline style
        )),
        body(null, listOf(
          div(null, h(component)),
          script("/js/script.js", mapOf( "defer" to "defer", "async" to "async" ))
        ))
      ))
    )
  }
}

Use components inside other components

class UserCardComponent(user: User): Component() {
  override val layout = EmptyLayout()
  override fun render(): DOMNode {
    return div(null, listOf(
      div(null, listOf( text(user.name) )),
      div(null, listOf( text('@' + user.nickname) )),
    ))
  }
}

class UserListComponent(usersList: List<User>): Component() {
  override val layout = EmptyLayout()
  override fun render(): DOMNode {
    return div(null,
      usersList.map { user ->
        div(null, listOf( h(UserCardComponent(user)) ))
      }
    )
  }
}

Render to html string

val component = CardComponent()
println(component.renderToHtml())

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory