reflex-dom-th: reflex-dom-th transpiles HTML templates to haskell code for reflex-dom

[ bsd3, frp, gui, html, javascript, library, reactive, reactivity, user-interface, user-interfaces, web ] [ Propose Tags ]

Reflex-DOM is a very powerful web framework for functional reactive programming (FRP). Web pages itself are written in HTML.

reflex-dom-th combines the power of these two techniques by transpiling HTML templates to Haskell for the reflex-dom library.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.3.2, 0.3.3, 0.3.4
Change log CHANGELOG.md
Dependencies array, base (>=4 && <5), containers, megaparsec, mtl, reflex-dom-core, template-haskell, text, th-lift-instances [details]
License BSD-3-Clause
Author Christoph Bauer
Maintainer mail@christoph-bauer.net
Category FRP, Web, GUI, HTML, Javascript, Reactive, Reactivity, User Interfaces, User-interface
Home page https://github.com/chrbauer/reflex-dom-th
Bug tracker https://github.com/chrbauer/reflex-dom-th/issues
Uploaded by ChristophBauer at 2022-06-11T14:40:25Z
Distributions NixOS:0.3.4
Downloads 344 total (18 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-06-11 [all 1 reports]

Readme for reflex-dom-th-0.3.2

[back to package description]

reflex-dom-th

Do you develop for the web? And you know functional reactive programming is the way to go. So you must use Reflex-DOM. But how can you integrate all these HTML snippet, which you found. You are tired in converting everything to to el, elAttr' etc, right?

From this day on this reflex-dom-th library will automate the task of converting your HTML templates to Reflex-Dom.

Examples

The basic example

[dom|<div>hello</div>|]

is equivalent to

el "div" $ text "hello"

You can also put the html in a external file and include it with

$(domFile "template.html")

It it possible to have multiple elements and attributes

[dom|<ul class="list">
       <li>Item1</div>
       <li>Item1</div>
     </ul> |]

Dynamic content can be injected between two curly braces. It will reference an unbound variable. It is not a haskell expression. Keeping haskell out of the template will give you better error messages.

[dom|<ul class="list">
      <li>{{item1}}</div>
      <li>{{item2}}</div>
    </ul> |]
  where item1, item2 :: MonadWidget t m =>  m ()
        item1 = text "Item1"
        item2 = text "Item2"

It is also possible to bind additionally a `Dynamic t (Map Text Text)' to the attributes

divWithAttrs :: MonadWidget t m => Dynamic t (Map Text Text) -> m ()
divWithAttrs dynAttrs = [dom|<div class="list" {{attr}}></div> |]

To bind events to the elements it is possible to extract get the elements as a result. The reference number is the position in the result tuple.

(li1, li2, ul, w) <- [dom|<ul #2 class="list">
                           <li #0>Item1</div>
                           <li #1>Item1</div>
	                   <li>{{widget #3}}</div>
                          </ul> |]