File: README.md

package info (click to toggle)
haskell-js-jquery 3.3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 436 kB
  • sloc: javascript: 6,690; haskell: 37; makefile: 7
file content (65 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# js-jquery [![Hackage version](https://img.shields.io/hackage/v/js-jquery.svg?label=Hackage)](https://hackage.haskell.org/package/js-jquery) [![Build Status](https://img.shields.io/travis/ndmitchell/js-jquery.svg)](https://travis-ci.org/ndmitchell/js-jquery)

This package bundles the minified [jQuery](http://jquery.com/) code into a Haskell package,
so it can be depended upon by Cabal packages. The first three components of
the version number match the upstream jQuery version. The package is designed
to meet the redistribution requirements of downstream users (e.g. Debian).
As an example:

```haskell
import qualified Language.Javascript.JQuery as JQuery

main = do
    putStrLn $ "jQuery version " ++ show JQuery.version ++ " source:"
    putStrLn =<< readFile =<< JQuery.file
```

This package installs data files containing the jQuery sources, which must be available at runtime. If you want to produce an executable with no dependency on associated data files, you can use the [`file-embed`](https://hackage.haskell.org/package/file-embed) library:

```haskell
{-# LANGUAGE TemplateHaskell #-}

import Data.FileEmbed
import qualified Data.ByteString as BS
import qualified Language.Javascript.JQuery as JQuery
import Language.Haskell.TH.Syntax

main = print jQueryContents

jQueryContents :: BS.ByteString
jQueryContents = $(embedFile =<< runIO JQuery.file)
```

Or, within the Yesod framework, [yesod-static](https://hackage.haskell.org/package/yesod-static):

```haskell
{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies #-}

import Yesod
import Yesod.EmbeddedStatic
import qualified Language.Javascript.JQuery as JQuery

data MySite = MySite {
    ...
    , getStatic :: EmbeddedStatic
    ...
    }

-- Create a Route `jquery_js` to a statically-serveable version of the local jQuery lib.
mkEmbeddedStatic False "myStatic" . pure . embedFileAt "jquery.js" =<< runIO JQuery.file

mkYesod "PresentationServer" [parseRoutes|
/ HomeR Get
...
/static StaticR EmbeddedStatic getStatic
|]
instance Yesod PresentationServer where
  addStaticContent = embedStaticContent getStatic StaticR Right

getHomeR :: Handler Html
getHomeR = defaultLayout $ do
   addScript $ StaticR jquery_js
   ...

```
(See also [`sample-embed.hs`](https://github.com/yesodweb/yesod/blob/master/yesod-static/sample-embed.hs).)