packages feed

simple-form 0.1.1 → 0.2

raw patch · 8 files changed

+56/−8 lines, 8 files

Files

README view
@@ -1,2 +1,6 @@ Inspired by the RubyGem of the same name, this package allows you to easily build validating forms that infer defaults based on type.++Most users will want to both render 'Html' and parse input, and so+should use the SimpleForm.Digestive.Combined and SimpleForm.Combined+modules.
SimpleForm.hs view
@@ -1,4 +1,7 @@ -- | Forms that configure themselves based on type+--+-- This module is for constructing forms that only output to 'Html'.+-- For forms that also parse input, see SimpleForm.Combined module SimpleForm ( 	Widget, 	DefaultWidget(..),
SimpleForm/Combined.hs view
@@ -1,4 +1,6 @@ -- | Forms that configure themselves based on type+--+-- The Combined module both renders to 'Html' and also parses input. module SimpleForm.Combined ( 	Widget, 	DefaultWidget(..),
SimpleForm/Digestive.hs view
@@ -1,4 +1,7 @@ -- | SimpleForm implementation that works along with digestive-functors+--+-- This module is for constructing forms that only output to 'Html'.+-- For forms that also parse input, see SimpleForm.Digestive.Combined module SimpleForm.Digestive ( 	SimpleForm, 	simpleForm,@@ -117,4 +120,6 @@  -- | Like 'withFields', but also wrap in fieldset tag fieldset :: Maybe Text -> (r' -> r) -> SimpleForm r a -> SimpleForm r' a-fieldset n f = wrap HTML.fieldset . withFields n f+fieldset n f form = wrap HTML.fieldset $ do+	maybe (return ()) (toForm . HTML.legend . toHtml . humanize) n+	withFields n f form
SimpleForm/Digestive/Combined.hs view
@@ -1,9 +1,10 @@ -- | SimpleForm implementation that works along with digestive-functors+--+-- The Combined module both renders to 'Html' and also parses input. module SimpleForm.Digestive.Combined ( 	SimpleForm,-	getSimpleForm, 	postSimpleForm,-	simpleForm,+	getSimpleForm, 	simpleForm', 	-- * Create forms 	input,@@ -11,6 +12,7 @@ 	toForm, 	-- * Subforms 	withFields,+	withFields', 	wrap, 	fieldset ) where@@ -27,7 +29,8 @@ import Text.Digestive.View import Text.Digestive.Form import Text.Digestive.Types (Env)-import SimpleForm.Digestive (toForm, withFields, wrap, fieldset, simpleForm, simpleForm')+import SimpleForm.Digestive (toForm, wrap, simpleForm')+import qualified SimpleForm.Digestive (withFields, fieldset) import SimpleForm.Combined import SimpleForm.Digestive.Internal import SimpleForm.Digestive.Validation@@ -53,11 +56,13 @@  -- | Render a 'SimpleForm' to 'Html' in the presence of input ----- This produces the contents of the form, but you must still wrap it in+-- This also parses the input to the correct datatype.+--+-- The 'Html' is the contents of the form, but you must still wrap it in -- the actual \<form\> element. postSimpleForm :: (Monad m) => 	Renderer-	-> m (Env m)+	-> m (Env m)                    -- ^ The digestive-functors input environment 	-> SimpleForm a (Form Html m a) -- ^ The simple form to render 	-> m (Html, Maybe a) postSimpleForm render env form = do@@ -89,3 +94,27 @@ 	-> (r -> Maybe a)           -- ^ Get value from parsed data 	-> SimpleForm r (Form Html m a) input_ n sel = input n sel (wdef,vdef) mempty++-- | Project out some part of the parsed data (does not add name to subview)+withFields' ::+	Maybe Text     -- ^ Optional subview name+	-> (r' -> r)   -- ^ Projection function+	-> SimpleForm r a+	-> SimpleForm r' a+withFields' = SimpleForm.Digestive.withFields++-- | Project out some part of the parsed data and name the subview+withFields :: (Monad m) =>+	Text           -- ^ Subview name+	-> (r' -> r)   -- ^ Projection function+	-> SimpleForm r (Form Html m a)+	-> SimpleForm r' (Form Html m a)+withFields n f = fmap (n .:) . withFields' (Just n) f++-- | Like 'withFields'', but also wrap in fieldset tag+fieldset' :: Maybe Text -> (r' -> r) -> SimpleForm r a -> SimpleForm r' a+fieldset' = SimpleForm.Digestive.fieldset++-- | Like 'withFields', but also wrap in fieldset tag+fieldset :: (Monad m) => Text -> (r' -> r) -> SimpleForm r (Form Html m a) -> SimpleForm r' (Form Html m a)+fieldset n f = fmap (n .:) . fieldset' (Just n) f
SimpleForm/Digestive/Internal.hs view
@@ -32,7 +32,7 @@  type SimpleFormEnv r = (Maybe r, View Html, (RenderOptions -> Html)) --- | The type of a form+-- | A form for producing something of type r newtype SimpleForm r a = SimpleForm (ReaderT (SimpleFormEnv r) (Writer Html) a)  instance Functor (SimpleForm r) where
SimpleForm/Render.hs view
@@ -1,3 +1,4 @@+-- | These utilities are for writing 'Renderer's module SimpleForm.Render ( 	Renderer, 	Input(..),
simple-form.cabal view
@@ -1,5 +1,5 @@ name:            simple-form-version:         0.1.1+version:         0.2 cabal-version:   >= 1.8 license:         OtherLicense license-file:    COPYING@@ -16,6 +16,10 @@ description:         Inspired by the RubyGem of the same name, this package allows you to         easily build validating forms that infer defaults based on type.+        .+        Most users will want to both render 'Html' and parse input, and so+        should use the SimpleForm.Digestive.Combined and SimpleForm.Combined+        modules.  extra-source-files:         README