packages feed

lucid 2.9.0 → 2.9.1

raw patch · 3 files changed

+46/−63 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Lucid.Base: newtype Attribute
+ Lucid.Base: data Attribute
- Lucid: runHtmlT :: HtmlT m a -> m (HashMap Text Text -> Builder -> Builder, a)
+ Lucid: runHtmlT :: HtmlT m a -> m (HashMap Text Text -> Builder, a)
- Lucid.Base: Attribute :: (Text, Text) -> Attribute
+ Lucid.Base: Attribute :: !Text -> !Text -> Attribute
- Lucid.Base: runHtmlT :: HtmlT m a -> m (HashMap Text Text -> Builder -> Builder, a)
+ Lucid.Base: runHtmlT :: HtmlT m a -> m (HashMap Text Text -> Builder, a)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## 2.9.1++* Small performance tweaks.+* Make svg_ an element.+ ## 2.6  * Restrict monoid instance's a to ~ () (means you can use mempty
lucid.cabal view
@@ -1,5 +1,5 @@ name:                lucid-version:             2.9.0+version:             2.9.1 synopsis:            Clear to write, read and edit DSL for HTML description:         Clear to write, read and edit DSL for HTML. See the 'Lucid' module                      for description and documentation.
src/Lucid/Base.hs view
@@ -1,11 +1,7 @@ {-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE ExtendedDefaultRules #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE GADTs #-}  -- | Base types and combinators. @@ -50,7 +46,6 @@ import           Data.Monoid import           Data.String import           Data.Text (Text)-import qualified Data.Text as T import qualified Data.Text.Lazy as LT import qualified Data.Text.Lazy.Encoding as LT @@ -58,7 +53,7 @@ -- Types  -- | A simple attribute. Don't use the constructor, use 'makeAttribute'.-newtype Attribute = Attribute (Text,Text)+data Attribute = Attribute !Text !Text   deriving (Show,Eq)  -- | Simple HTML builder type. Defined in terms of 'HtmlT'. Check out@@ -71,23 +66,17 @@ -- | A monad transformer that generates HTML. Use the simpler 'Html' -- type if you don't want to transform over some other monad. newtype HtmlT m a =-  HtmlT {runHtmlT :: m (HashMap Text Text -> Builder -> Builder,a)+  HtmlT {runHtmlT :: m (HashMap Text Text -> Builder,a)          -- ^ This is the low-level way to run the HTML transformer,          -- finally returning an element builder and a value. You can-         -- pass 'mempty' for both arguments for a top-level call. See+         -- pass 'mempty' for this argument for a top-level call. See          -- 'evalHtmlT' and 'execHtmlT' for easier to use functions.          }  -- | Monoid is right-associative, a la the 'Builder' in it. instance (a ~ (),Monad m) => Monoid (HtmlT m a) where-  mempty = HtmlT (return (\_ _ -> mempty,mempty))-  mappend (HtmlT get_f_a) (HtmlT get_g_b) =-    HtmlT (do ~(f,a) <- get_f_a-              ~(g,b) <- get_g_b-              return (\attr inner ->-                        f attr inner <>-                        g attr inner-                     ,a <> b))+  mempty  = return mempty+  mappend = liftM2 mappend  -- | Based on the monad instance. instance Monad m => Applicative (HtmlT m) where@@ -100,21 +89,17 @@  -- | Basically acts like Writer. instance Monad m => Monad (HtmlT m) where-  return a = HtmlT (return (\_ _ -> mempty,a))-  HtmlT get_g_a >>= f =-    HtmlT (do ~(g,a) <- get_g_a-              let HtmlT get_f'_b = f a-              ~(f',b) <- get_f'_b-              return (\attr inner ->-                        g attr inner <>-                        f' attr inner-                     ,b))+  return a = HtmlT (return (mempty,a))+  m >>= f =+    HtmlT (do ~(g,a) <- runHtmlT m+              ~(h,b) <- runHtmlT (f a)+              return (g <> h,b))  -- | Used for 'lift'. instance MonadTrans HtmlT where   lift m =     HtmlT (do a <- m-              return (\_ _ -> mempty,a))+              return (\_ -> mempty,a))  -- | If you want to use IO in your HTML generation. instance MonadIO m => MonadIO (HtmlT m) where@@ -123,8 +108,7 @@ -- | We pack it via string. Could possibly encode straight into a -- builder. That might be faster. instance (Monad m,a ~ ()) => IsString (HtmlT m a) where-  fromString m' =-    HtmlT (return (\_ _ -> encode (T.pack m'),()))+  fromString = toHtml  -- | Just calls 'renderText'. instance (m ~ Identity) => Show (HtmlT m a) where@@ -136,17 +120,22 @@   toHtmlRaw :: Monad m => a -> HtmlT m ()  instance ToHtml String where-  toHtml = fromString-  toHtmlRaw m = HtmlT (return ((\_ _ -> Blaze.fromString m),()))+  toHtml    = build . Blaze.fromHtmlEscapedString+  toHtmlRaw = build . Blaze.fromString  instance ToHtml Text where-  toHtml m = HtmlT (return ((\_ _ -> encode m),()))-  toHtmlRaw m = HtmlT (return ((\_ _ -> Blaze.fromText m),()))+  toHtml    = build . Blaze.fromHtmlEscapedText+  toHtmlRaw = build . Blaze.fromText  instance ToHtml LT.Text where-  toHtml m = HtmlT (return ((\_ _ -> encodeLazy m),()))-  toHtmlRaw m = HtmlT (return ((\_ _ -> Blaze.fromLazyText m),()))+  toHtml    = build . Blaze.fromHtmlEscapedLazyText+  toHtmlRaw = build . Blaze.fromLazyText +-- | Create an 'HtmlT' directly from a 'Builder'.+build :: Monad m => Builder -> HtmlT m ()+build b = HtmlT (return (const b,()))+{-# INLINE build #-}+ -- | Used to construct HTML terms. -- -- Simplest use: p_ = term "p" yields 'Lucid.Html5.p_'.@@ -236,20 +225,20 @@   with f =     \attr ->       HtmlT (do ~(f',a) <- runHtmlT f-                return (\attr' m' ->-                          f' (unionArgs (M.fromListWith (<>) (map toPair attr)) attr') m'+                return (\attr' ->+                          f' (unionArgs (M.fromListWith (<>) (map toPair attr)) attr')                        ,a))-    where toPair (Attribute x) = x+    where toPair (Attribute x y) = (x,y)  -- | For the contentful elements: 'Lucid.Html5.div_' instance (Monad m) => With (HtmlT m a -> HtmlT m a) where   with f =     \attr inner ->       HtmlT (do ~(f',a) <- runHtmlT (f inner)-                return ((\attr' m' ->-                           f' (unionArgs (M.fromListWith (<>) (map toPair attr)) attr') m')+                return ((\attr'  ->+                           f' (unionArgs (M.fromListWith (<>) (map toPair attr)) attr') )                        ,a))-    where toPair (Attribute x) = x+    where toPair (Attribute x y) = (x,y)  -- | Union two sets of arguments and append duplicate keys. unionArgs :: HashMap Text Text -> HashMap Text Text -> HashMap Text Text@@ -317,7 +306,7 @@           -> m Builder  -- ^ The @a@ is discarded. execHtmlT m =   do (f,_) <- runHtmlT m-     return (f mempty mempty)+     return (f mempty)  -- | Evaluate the HTML to its return value. Analogous to @evalState@. --@@ -343,7 +332,7 @@ makeAttribute :: Text -- ^ Attribute name.               -> Text -- ^ Attribute value.               -> Attribute-makeAttribute x y = Attribute (x,y)+makeAttribute x y = Attribute x y  -- | Make an HTML builder. makeElement :: Monad m@@ -353,9 +342,9 @@ makeElement name =   \m' ->     HtmlT (do ~(f,a) <- runHtmlT m'-              return (\attr m -> s "<" <> Blaze.fromText name+              return (\attr  -> s "<" <> Blaze.fromText name                               <> foldlMapWithKey buildAttr attr <> s ">"-                              <> m <> f mempty mempty+                              <> f mempty                               <> s "</" <> Blaze.fromText name <> s ">",                       a)) @@ -364,8 +353,8 @@                  => Text       -- ^ Name.                  -> HtmlT m () -- ^ A parent element. makeElementNoEnd name =-  HtmlT (return (\attr _ -> s "<" <> Blaze.fromText name-                            <> foldlMapWithKey buildAttr attr <> s ">",+  HtmlT (return (\attr -> s "<" <> Blaze.fromText name+                          <> foldlMapWithKey buildAttr attr <> s ">",                  ()))  -- | Make an XML builder for elements which have no ending tag.@@ -373,8 +362,8 @@                     => Text       -- ^ Name.                     -> HtmlT m () -- ^ A parent element. makeXmlElementNoEnd name =-  HtmlT (return (\attr _ -> s "<" <> Blaze.fromText name-                            <> foldlMapWithKey buildAttr attr <> s "/>",+  HtmlT (return (\attr -> s "<" <> Blaze.fromText name+                          <> foldlMapWithKey buildAttr attr <> s "/>",                  ()))  -- | Build and encode an attribute.@@ -384,7 +373,7 @@   Blaze.fromText key <>   if val == mempty      then mempty-     else s "=\"" <> encode val <> s "\""+     else s "=\"" <> Blaze.fromHtmlEscapedText val <> s "\""  -- | Folding and monoidally appending attributes. foldlMapWithKey :: Monoid m => (k -> v -> m) -> HashMap k v -> m@@ -394,14 +383,3 @@ s :: String -> Builder s = Blaze.fromString {-# INLINE s #-}------------------------------------------------------------------------------------- Encoding---- | Encode the given strict plain text to an encoded HTML builder.-encode :: Text -> Builder-encode = Blaze.fromHtmlEscapedText---- | Encode the given strict plain text to an encoded HTML builder.-encodeLazy :: LT.Text -> Builder-encodeLazy = Blaze.fromHtmlEscapedLazyText