zwilias / elm-html-string

Drop in elm-lang/html replacement which can serialize to a pretty `String`
http://package.elm-lang.org/packages/zwilias/elm-html-string/latest
BSD 3-Clause "New" or "Revised" License
25 stars 9 forks source link

elm-html-string Build Status

Write code resembling elm/html and serialize to either a string or actual HTML

This package copies the entire API of elm/html, but adds 2 functions:

Two caveats:

Show me an example!

import Html.String as Html exposing (Html)
import Html.String.Attributes as Attr
import Html.String.Events as Events

type Msg = Increment | Decrement

counter : Int -> Html Msg
counter count =
    Html.div
        [ Attr.classList [ ( "below-zero" = count < 0 ), ( "counter" = True ) ] ]
        [ Html.button [ Events.onClick Decrement ] [ Html.text "-" ]
        , Html.text <| toString count
        , Html.button [ Events.onClick Increment ] [ Html.text "+" ]
        ]

counterAsString : String
counterAsString =
    Html.toString 2 <| counter -5

{- Expected output:

    <div class="below-zero counter">
      <button>
        -
      </button>
      -5
      <button>
        +
      </button>
    </div>
-}

Cool, anything else I should be aware of?

Yes.

Alright, coolbeans

Made with ❤️ and licensed under BSD-3. Fork me and send me some pull-requests!