type-of-html 0.4.0.1 → 0.4.1.1
raw patch · 4 files changed
+45/−32 lines, 4 filesdep −ghc-primPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: ghc-prim
API changes (from Hackage documentation)
- Html: convert :: Convert a => a -> Converted Builder
+ Html: convert :: Convert a => a -> Converted
- Html: data Converted a
+ Html: data Converted
Files
- src/Html/Attribute.hs +2/−3
- src/Html/Convert.hs +42/−25
- src/Html/Type.hs +0/−2
- type-of-html.cabal +1/−2
src/Html/Attribute.hs view
@@ -1,6 +1,5 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE MagicHash #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE MagicHash #-} module Html.Attribute where
src/Html/Convert.hs view
@@ -1,20 +1,21 @@-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE LambdaCase #-}-{-# LANGUAGE MagicHash #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE FlexibleInstances #-}+ module Html.Convert where +import Data.Word import Data.Proxy import Data.String import GHC.TypeLits import Html.Type-import GHC.Prim (Addr#) import Data.Char (ord) +import qualified Data.Monoid as M+import qualified Data.Semigroup as S+ import qualified Data.ByteString.Internal as U import qualified Data.ByteString.Unsafe as U import qualified Data.ByteString.Builder as B@@ -24,13 +25,15 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T +import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.Encoding as TL+ {-# INLINE unsafe #-}-unsafe :: Int -> Addr# -> U.ByteString unsafe i addr = U.accursedUnutterablePerformIO (U.unsafePackAddressLen i addr) {-# INLINE escape #-}-escape :: T.Text -> B.Builder-escape = T.encodeUtf8BuilderEscaped $+escape :: BP.BoundedPrim Word8+escape = BP.condB (> c2w '>' ) (BP.liftFixedToBounded BP.word8) $ BP.condB (== c2w '<' ) (fixed4 (c2w '&',(c2w 'l',(c2w 't',c2w ';')))) $ -- < BP.condB (== c2w '>' ) (fixed4 (c2w '&',(c2w 'g',(c2w 't',c2w ';')))) $ -- >@@ -56,29 +59,32 @@ @ {\-\# LANGUAGE RecordWildCards \#-\}+{\-\# LANGUAGE OverloadedStrings \#-\} module Main where import Html +import Data.Text (Text)+import Data.Monoid+ data Person = Person- { name :: String+ { name :: Text , age :: Int , vegetarian :: Bool } --- | This is not efficient, but understandable.--- The call to convertText is needed for escaping.--- This is enforced by a newtype. Wrap it in Raw if you don't want to escape.+-- | This is already very efficient.+-- Wrap the Strings in Raw if you don't want to escape them.+ instance Convert Person where- convertText (Person{..})- = convertText- $ name- ++ " is "- ++ show age- ++ " years old and likes "- ++ if vegetarian then "oranges." else "meat."+ convert (Person{..})+ = convert name+ <> " is "+ <> convert age+ <> " years old and likes "+ <> if vegetarian then "oranges." else "meat." john :: Person john = Person {name = "John", age = 52, vegetarian = True}@@ -87,8 +93,14 @@ main = print (div_ john) @ -}++newtype Converted = Converted {unConv :: B.Builder} deriving (M.Monoid,S.Semigroup)++instance IsString Converted where+ fromString = convert+ class Convert a where- convert :: a -> Converted B.Builder+ convert :: a -> Converted instance Convert (Raw String) where {-# INLINE convert #-}@@ -96,12 +108,18 @@ instance Convert (Raw T.Text) where {-# INLINE convert #-} convert (Raw x) = Converted (T.encodeUtf8Builder x)+instance Convert (Raw TL.Text) where+ {-# INLINE convert #-}+ convert (Raw x) = Converted (TL.encodeUtf8Builder x) instance Convert String where {-# INLINE convert #-}- convert = Converted . escape . fromString+ convert = convert . T.pack instance Convert T.Text where {-# INLINE convert #-}- convert = Converted . escape+ convert = Converted . T.encodeUtf8BuilderEscaped escape+instance Convert TL.Text where+ {-# INLINE convert #-}+ convert = Converted . TL.encodeUtf8BuilderEscaped escape instance Convert Int where {-# INLINE convert #-} convert = Converted . B.intDec@@ -120,4 +138,3 @@ instance KnownSymbol a => Convert (Proxy a) where {-# INLINE convert #-} convert = Converted . U.byteStringCopy . fromString . symbolVal-
src/Html/Type.hs view
@@ -260,8 +260,6 @@ -- | Wrapper for types which won't be escaped. newtype Raw a = Raw a -newtype Converted a = Converted {unConv :: a}- ------------------- -- internal code -- -------------------
type-of-html.cabal view
@@ -1,5 +1,5 @@ name: type-of-html-version: 0.4.0.1+version: 0.4.1.1 synopsis: High performance type driven html generation. description: This library makes most invalid html documents compile time errors and uses advanced type level features to realise compile time computations. license: BSD3@@ -31,7 +31,6 @@ build-depends: base >= 4.10 && < 4.11 , text , bytestring- , ghc-prim test-suite test type: exitcode-stdio-1.0