haste-perch: Create dynamic HTML in the browser using blaze-html-style notation with Haste

[ gpl, library, web ] [ Propose Tags ]

Perch defines builder elements (perchs) for Haste.DOM elements that are appendable, so that dynamic HTML can be created in the client in a natural way, like textual HTML, but programmatically and with the advantage of static type checking. It can be ported to other haskell-js compilers

Haste is a compiler that generates Javascript code from Haskell.

https://github.com/valderman/haste-compiler

The Haste.DOM module define a thin layer over the JavaScript DOM. The DOM is a low level HTML tree manipulation API. That makes the creation and manipulation of DOM elements almost as painful as in JavaScript.

This package makes the creation of DOM elements easy with a syntax similar to other haskell HTML generators, using monoids and monads, such is the case of the package blaze-html.

http://hackage.haskell.org/package/blaze-html

Since the creation is in the browser, that permit quite dynamic pages for data presentation, and interctive textual (a.k.a "serious") applications and in general the development of client-side web frameworks using haskell with the haste compiler.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.0.8, 0.1.0.9
Dependencies base (>=4.6 && <4.7), haste-compiler, mtl [details]
License BSD-3-Clause
Author Alberto G. Corona
Maintainer agocorona@gmail.com
Category Web
Home page https://github.com/agocorona/haste-perch
Uploaded by AlbertoCorona at 2014-06-18T13:54:14Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 7342 total (27 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed [all 1 reports]

Readme for haste-perch-0.1.0.0

[back to package description]

haskell-js-html-builder

A monad and monoid instance for Haste.DOM elements. It can be ported to other haskell-js compilers

Haste is a compiler that generates Javascript code from Haskell.

https://github.com/valderman/haste-compiler

The Haste.DOM module define a thin layer over the JavaScript DOM. That makes the creation and manipulation of DOM elements as painful as in JavaScript.

This package makes the creation of DOM elements easy with a syntax similar to other haskell HTML generators, using monoids and monads, such is the case of the package blaze-html.

This is an example. withElem is a Haste.DOM call that give the DOM object whose id is "idelem", that has been created "by hand" in Main.hs. The builder takes this element and add content to it:

  main= do
   withElem "idelem" $   build $ do
   div $ do
     div $ do
           p "hello"
           p ! atr "style" "color:red" $   "world"

   return ()

The equivalent monoid expression can also be used, by concatenating elements with the operator <>

How to run

install the ghc compiler

install Haste:

>cabal install haste-compiler

clone haskell-js-html-builder

>git clone http://github.com/agocorona/haskell-js-html-builder.git

compile

>hastec Main.hs

browse the Main.html file. In windows simply execute it in the command line:

>Main.html

Execute it in the same directory where Main.js is, since it references it assuming that it is in the current folder

Status

Standard tags and attributes are not defined except div, p and b. Define your owns. For example:

div cont= nelem "div" child cont

p cont = nelem "p" child cont

b cont = nelem "b" child cont

onclick= atr "onclick"

How it works

The basic element is a "builder" that has a "hole" parameter and a IO action about what element will be created. The hole will receive the parent (Elem) of the element/s that will be created by the builder. Upon created, an elem is added to the parent and return itself as parent of the next elements. To append two elements, both are added to the parent.

The Monad instance is there in order to use the do notation, that add a new level of syntax, in the style of the package blaze-html. This monad invokes the same appending mechanism.