diff --git a/Data/Object/Html.hs b/Data/Object/Html.hs index 720280c0..ca3fcbd7 100644 --- a/Data/Object/Html.hs +++ b/Data/Object/Html.hs @@ -35,6 +35,7 @@ module Data.Object.Html import Data.Generics import Data.Object.Text +import Data.Object.String import Data.Object.Json import qualified Data.Text.Lazy as TL import qualified Data.Text as TS @@ -75,6 +76,8 @@ instance ConvertSuccess [(String, HtmlObject)] HtmlObject where convertSuccess = Mapping instance ConvertSuccess [(String, Html)] HtmlObject where convertSuccess = Mapping . map (second cs) +instance ConvertSuccess StringObject HtmlObject where + convertSuccess = mapKeysValues cs cs toHtmlObject :: ConvertSuccess x HtmlObject => x -> HtmlObject toHtmlObject = cs diff --git a/Yesod/Form.hs b/Yesod/Form.hs index 49cad8df..65417850 100644 --- a/Yesod/Form.hs +++ b/Yesod/Form.hs @@ -10,6 +10,7 @@ module Yesod.Form , applyForm -- * Specific checks , required + , optional , notEmpty , checkDay , checkBool @@ -21,7 +22,7 @@ module Yesod.Form import Yesod.Request import Yesod.Response (ErrorResponse) import Yesod.Handler -import Control.Applicative +import Control.Applicative hiding (optional) import Data.Time (Day) import Data.Convertible.Text import Data.Attempt @@ -92,6 +93,13 @@ required = applyForm $ \pvs -> case pvs of [] -> Left "No value for required field" _ -> Left "Multiple values for required field" +optional :: Form [ParamValue] -> Form (Maybe ParamValue) +optional = applyForm $ \pvs -> case pvs of + [""] -> Right Nothing + [x] -> Right $ Just x + [] -> Right Nothing + _ -> Left "Multiple values for optional field" + notEmpty :: Form ParamValue -> Form ParamValue notEmpty = applyForm $ \pv -> if null pv diff --git a/Yesod/Helpers/Auth.hs b/Yesod/Helpers/Auth.hs index a43e5e2e..68c1a8eb 100644 --- a/Yesod/Helpers/Auth.hs +++ b/Yesod/Helpers/Auth.hs @@ -38,6 +38,8 @@ import Data.Typeable (Typeable) import Control.Exception (Exception) import Control.Applicative ((<$>)) +-- FIXME check referer header to determine destination + class YesodApproot a => YesodAuth a where -- | The following breaks DRY, but I cannot think of a better solution -- right now. diff --git a/Yesod/Template.hs b/Yesod/Template.hs index 83050395..03c073a3 100644 --- a/Yesod/Template.hs +++ b/Yesod/Template.hs @@ -31,6 +31,7 @@ class Yesod y => YesodTemplate y where getTemplateGroup :: y -> TemplateGroup defaultTemplateAttribs :: y -> Request -> HtmlTemplate -> IO HtmlTemplate + defaultTemplateAttribs _ _ = return getTemplateGroup' :: YesodTemplate y => Handler y TemplateGroup getTemplateGroup' = getTemplateGroup `fmap` getYesod diff --git a/examples/tweedle-templates/category-details.st b/examples/tweedle-templates/category-details.st new file mode 100644 index 00000000..e1c8f3e1 --- /dev/null +++ b/examples/tweedle-templates/category-details.st @@ -0,0 +1,26 @@ +$layout( + title={Category $name$}; + content={ +
+