Permalink
Browse files

Port input, textarea and password functions

  • Loading branch information...
1 parent 184ec1d commit 5d985f87d15ed830c0dfdddcae152a1f2c49f2cf @jaspervdj jaspervdj committed Sep 26, 2010
Showing with 48 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +44 −0 Text/Blaze/Html5/Formlets.hs
  3. +3 −2 formlets.cabal
View
1 .gitignore
@@ -0,0 +1 @@
+dist/
View
44 Text/Blaze/Html5/Formlets.hs
@@ -0,0 +1,44 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Text.Blaze.Html5.Formlets ( input, textarea, password
+ , Html5Form, Html5Formlet
+ , module Text.Formlets
+ ) where
+
+import Text.Formlets hiding (massInput)
+import qualified Text.Formlets as F
+import Text.Blaze.Html5 ((!))
+import qualified Text.Blaze.Html5 as H
+import qualified Text.Blaze.Html5.Attributes as A
+import Data.Monoid (mappend)
+
+import Control.Applicative
+import Control.Applicative.Error
+import Data.List (elemIndex)
+
+type Html5Form m a = Form H.Html m a
+type Html5Formlet m a = Formlet H.Html m a
+
+-- | An input field with an optional value
+--
+input :: Monad m => Html5Formlet m String
+input = input' $ \n v -> H.input ! A.type_ "text"
+ ! A.name (H.stringValue n)
+ ! A.id (H.stringValue n)
+ ! A.value (H.stringValue v)
+
+-- | A textarea with optional rows and columns, and an optional value
+--
+textarea :: Monad m => Maybe Int -> Maybe Int -> Html5Formlet m String
+textarea r c = input' $ \n v -> (applyAttrs n H.textarea) (H.string v)
+ where
+ applyAttrs n = (! A.name (H.stringValue n)) . rows r . cols c
+ rows = maybe id $ \x -> (! A.rows (H.stringValue $ show x))
+ cols = maybe id $ \x -> (! A.cols (H.stringValue $ show x))
+
+-- | A password field with an optional value
+--
+password :: Monad m => Html5Formlet m String
+password = input' $ \n v -> H.input ! A.type_ "password"
+ ! A.name (H.stringValue n)
+ ! A.id (H.stringValue n)
+ ! A.value (H.stringValue v)
View
5 formlets.cabal
@@ -1,5 +1,5 @@
Name: formlets
-Version: 0.7.2
+Version: 0.7.3
Synopsis: Formlets implemented in Haskell
Description: A modular way to build forms based on applicative functors,
based on the work described in:
@@ -25,7 +25,8 @@ Library
mtl,
xhtml,
applicative-extras >= 0.1.3,
- bytestring
+ bytestring,
+ blaze-html >= 0.2
if flag(base4)
Build-Depends: base >= 4 && < 5, syb
else

0 comments on commit 5d985f8

Please sign in to comment.