packages feed

blaze-html-contrib 0.2.1 → 0.2.2

raw patch · 3 files changed

+60/−9 lines, 3 filesnew-uploader

Files

blaze-html-contrib.cabal view
@@ -1,14 +1,13 @@ Name:                blaze-html-contrib-Version:             0.2.1+Version:             0.2.2 Synopsis:            Some contributions to add handy things to blaze html. Description:         Some contributions to add handy things to blaze html. Please-                     send your contributions as pull requests to -                     https://github.com/chrisdone/blaze-html-contrib-Homepage:            https://github.com/chrisdone/blaze-html-contrib+                     send your contributions as pull requests. See homepage for basic usage.+Homepage:            https://github.com/egonSchiele/blaze-html-contrib License:             BSD3 License-file:        LICENSE-Author:              Chris Done-Maintainer:          chrisdone@gmail.com+Author:              Aditya Bhargava, Chris Done+Maintainer:          adit@adit.io Copyright:           2011 Chris Done Category:            Web Build-type:          Simple@@ -16,7 +15,7 @@  Library   Hs-source-dirs:    src-  Exposed-modules:   Text.Blaze.Extra, Text.Blaze.Pagination, Data.Pagination+  Exposed-modules:   Text.Blaze.Extra, Text.Blaze.Pagination, Data.Pagination, Network.URI.Params   Build-depends:     base > 4 && < 5,                      network,                      blaze-html,
+ src/Network/URI/Params.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE NamedFieldPuns #-}+{-# OPTIONS -fno-warn-missing-signatures #-}+module Network.URI.Params (updateUrlParam,updateUrlParams,uriParams,deleteQueryKey) where++import Control.Arrow+import Network.URI+import Data.List+import Data.Function+import Network.CGI++updateUrlParam :: String -> String -> URI -> URI+updateUrlParam this value uri@(URI{uriQuery}) =+  uri { uriQuery = updated uriQuery } where+  updated = editQuery $ ((this,value):) . deleteBy ((==) `on` fst) (this,"")++deleteQueryKey :: String -> URI -> URI+deleteQueryKey key uri =+  uri { uriQuery = editQuery (filter ((/=key).fst)) (uriQuery uri) }++editQuery :: ([(String,String)] -> [(String,String)]) -> String -> String+editQuery f = ('?':) . formEncodeUrl . f . formDecode . dropWhile (=='?')++formEncodeUrl = intercalate "&" . map keyval . map (esc *** esc)+  where keyval (key,val) = key ++ "=" ++ val+        esc = escapeURIString isAllowedInURI++updateUrlParams :: [(String,String)] -> URI -> URI+updateUrlParams = flip $ foldr $ uncurry updateUrlParam++uriParams :: URI -> [(String,String)]+uriParams = formDecode . dropWhile (=='?') . uriQuery
src/Text/Blaze/Extra.hs view
@@ -23,7 +23,7 @@ (!#) :: (Attributable h) => h -> AttributeValue -> h elem !# idName = elem ! A.id idName --- | Render a list of lines to HTML.+-- | Render a list of lines (separated by \n) to HTML. linesToHtml :: String -> Html linesToHtml str = forM_ (lines str) $ \line -> do toHtml line; br @@ -47,7 +47,28 @@ hrefURI uri = href (toValue (showURI uri)) where   showURI URI{..} = uriPath ++ uriQuery --- | Create a href from a a path and association list of parameters.+-- | Create an href from a path and association list of parameters.+-- Usage:+--+-- @hrefAssoc \"/search\" [(\"query\", \"foo\"), (\"mode\", \"bar\")]@+--+-- Creates: @href \"/search?query=foo&mode=bar\"@ hrefAssoc :: String -> [(String,String)] -> Attribute hrefAssoc path qs = href (toValue uri) where   uri = "/" ++ path ++ "?" ++ intercalate "&" (map (uncurry (printf "%s=%s")) qs)++-- | Link to a CSS stylesheet.+css :: H.AttributeValue -> H.Html+css link = H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href link++-- | Link to a javscript file.+js :: H.AttributeValue -> H.Html+js link = H.script ! A.type_ "text/JavaScript" ! A.src link $ ""++-- | Create a link.+linkTo :: H.AttributeValue -> H.Html -> H.Html+linkTo url = H.a ! A.href url++-- | Create a form with method = \"POST\" that posts to the given url.+postForm :: String -> H.Html -> H.Html+postForm uri = H.form ! A.action (H.toValue uri) ! A.method "post"