Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
--
-- Hello-World of the cordova/phonegap application using Haskell.
--
-- here is the screenshoot
--
-- https://twitter.com/AGoCorona/status/532948528621178880
--
-- So that Haste-Haskell can be used to create hybrid smartphone applications
--
-- The original cordova JavaScript hello world is installed following the instructions of this page
--
-- http://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html
--
-- follow the instructions in the above page to install cordova and the hello world app.
--
-- install the browser platform, the simplest one:
--
-- $ cordova platform add browser
--
-- build and run the native application to verify that it run. In the folder of the installed demo:
--
-- $ cordova build
--
-- $ cordova run
--
-- within another folder, install Haskell, Haste and the last version of the Perch library
-- At https://github.com/agocorona/haste-perch you can find the instructions:
--
-- $ cabal install haste
--
-- $ git clone https://github.com/agocorona/haste-perch
--
-- compile this program
--
-- $ hastec cordova.hs
--
-- rename the generated JavaScript file and use it instead of the original index.js file of the native application
--
-- rebuild and run again:
--
-- $ cordova build
--
-- $ cordova run
--
import Haste
import Haste.Perch
main :: IO ()
main = do
doc <- getDocument
-- equivalent to document.addEventListener ('deviceready',doit,false)
listen doc "deviceready" doit
body <- getBody
-- some message at the body
(flip build) body $ b "cordova/phonegap hello-world demo. Read the instructions in the source code"
return ()
doit :: IO ()
doit = do
-- hide the listening message locating it by his class attribute, defined in the HTML template
forElems' ".listening" $ this ! style "display:none"
-- make visible the "ready" message locating it by his class attribute, and add some additional rendering
forElems' ".received" $ do
this ! style "display:block"
br
i "RUNNING a HASKELL program"
br
i "compiled with the HASTE compiler"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment