yesod-goodies 0.0.4.1.1 → 0.0.5
raw patch · 4 files changed
+62/−18 lines, 4 filesdep +blaze-htmldep ~bytestringdep ~pandocdep ~pureMD5
Dependencies added: blaze-html
Dependency ranges changed: bytestring, pandoc, pureMD5, text, yesod, yesod-form
Files
- Yesod/Goodies/Links.hs +5/−5
- Yesod/Goodies/Markdown.hs +44/−7
- Yesod/Goodies/Paginate.hs +8/−2
- yesod-goodies.cabal +5/−4
Yesod/Goodies/Links.hs view
@@ -21,7 +21,7 @@ , link' ) where -import Yesod (GWidget, Route, hamlet)+import Yesod (GWidget, Route, whamlet) import qualified Data.Text as T -- | An internal route or external url@@ -70,9 +70,9 @@ -- instance of 'YesodLinked'. link' :: Link m -> GWidget s m () #if __GLASGOW_HASKELL__ >= 700-link' (Link (Internal i) t x) = [hamlet|<a title="#{t}" href="@{i}">#{x}|]-link' (Link (External e) t x) = [hamlet|<a title="#{t}" href="#{e}">#{x}|]+link' (Link (Internal i) t x) = [whamlet|<a title="#{t}" href="@{i}">#{x}|]+link' (Link (External e) t x) = [whamlet|<a title="#{t}" href="#{e}">#{x}|] #else-link' (Link (Internal i) t x) = [$hamlet|<a title="#{t}" href="@{i}">#{x}|]-link' (Link (External e) t x) = [$hamlet|<a title="#{t}" href="#{e}">#{x}|]+link' (Link (Internal i) t x) = [$whamlet|<a title="#{t}" href="@{i}">#{x}|]+link' (Link (External e) t x) = [$whamlet|<a title="#{t}" href="#{e}">#{x}|] #endif
Yesod/Goodies/Markdown.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}@@ -30,17 +32,17 @@ -- * Option sets , yesodDefaultWriterOptions , yesodDefaultParserState- -- * Form helpers+ -- * Form helper , markdownField- , maybeMarkdownField ) where import Yesod-import Yesod.Form.Core+import Yesod.Form.Types import Yesod.Goodies.Shorten +import Text.Blaze (preEscapedString) import Text.Pandoc import Text.Pandoc.Shared @@ -56,12 +58,46 @@ instance Shorten Markdown where shorten n (Markdown s) = Markdown $ shorten n s -instance ToFormField Markdown y where- toFormField = markdownField+instance ToField Markdown master where+ toField = areq markdownField -instance ToFormField (Maybe Markdown) y where- toFormField = maybeMarkdownField+instance ToField (Maybe Markdown) master where+ toField = aopt markdownField +markdownField :: RenderMessage master FormMessage => Field sub master Markdown+markdownField = Field+ { fieldParse = blank $ Right . Markdown . unlines . lines' . T.unpack+ , fieldView = \theId name val _isReq -> addHamlet+#if __GLASGOW_HASKELL__ >= 700+ [hamlet|+#else+ [$hamlet|+#endif+ <textarea id="#{theId}" name="#{name}">#{either id unMarkdown val}+ |]+ }++ where+ unMarkdown :: Markdown -> T.Text+ unMarkdown (Markdown s) = T.pack s++ lines' :: String -> [String]+ lines' = map go . lines++ go [] = []+ go ('\r':xs) = go xs+ go (x:xs) = x : go xs+++blank :: (Monad m, RenderMessage master FormMessage)+ => (T.Text -> Either FormMessage a)+ -> [T.Text]+ -> m (Either (SomeMessage master) (Maybe a))+blank _ [] = return $ Right Nothing+blank _ ("":_) = return $ Right Nothing+blank f (x:_) = return $ either (Left . SomeMessage) (Right . Just) $ f x++{- markdownField :: (IsForm f, FormType f ~ Markdown) => FormFieldSettings -> Maybe Markdown -> f markdownField = requiredFieldHelper markdownFieldProfile @@ -89,6 +125,7 @@ go [] = [] go ('\r':xs) = go xs go (x:xs) = x : go xs+ -} -- | Converts markdown directly to html using the yesod default option -- sets
Yesod/Goodies/Paginate.hs view
@@ -17,8 +17,14 @@ -- ------------------------------------------------------------------------------- module Yesod.Goodies.Paginate- ( PageOptions(..)+ ( + -- * automatic+ PageOptions(..) , paginate++ -- * manual+ , Page(..)+ , determinePage ) where import Yesod@@ -86,7 +92,7 @@ -- current GET params rgps <- lift $ return . reqGetParams =<< getRequest - [hamlet|+ [whamlet| ^{doShow items} <ul .pagination>
yesod-goodies.cabal view
@@ -1,5 +1,5 @@ name: yesod-goodies-version: 0.0.4.1.1+version: 0.0.5 description: A collection of various small helpers useful in any yesod application. synopsis: A collection of various small helpers useful in any yesod application. homepage: http://github.com/pbrisbin/yesod-goodies@@ -23,10 +23,11 @@ build-depends: base >= 4 && < 5 , text >= 0.11 && < 0.12- , bytestring >= 0.9.1 && < 10.0+ , bytestring >= 0.9.1 && < 0.10 , pandoc >= 1.8.1 && < 1.9- , yesod >= 0.8 && < 0.9- , yesod-form >= 0.1 && < 0.2+ , yesod >= 0.9 && < 1.0+ , yesod-form >= 0.3 && < 0.4+ , blaze-html >= 0.4 && < 0.5 , pureMD5 < 3 , HTTP , directory