~alcinnz/bureaucromancy

ref: 703b307333f90115a7512efcd660615a64a75700 bureaucromancy/src/Text/HTML/Form/Query.hs -rw-r--r-- 666 bytes
703b3073 — Adrian Cochrane Implement radio inputs, upload missing files, make space for descriptions & richer form controls to use. 1 year, 3 months ago
                                                                                
703b3073 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Text.HTML.Form.Query(
    renderQueryString, renderQueryString', renderQuery') where

import Text.HTML.Form (Form(..), Input(..))
import Network.URI (escapeURIString, isUnescapedInURIComponent)
import Data.List (intercalate)
import Data.Text (unpack)

renderQueryString :: Form -> String
renderQueryString = renderQueryString' . renderQuery'
renderQueryString' query = intercalate "&" [
    escape key ++ '=':escape value | (key, value) <- query
  ]

renderQuery' :: Form -> [(String, String)]
renderQuery' form = [(unpack $ inputName input, unpack $ value input)
    | input <- inputs form, checked input]

escape = escapeURIString isUnescapedInURIComponent