1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-26 03:08:37 +03:00

Add section separators to Guide.Utils

This commit is contained in:
Artyom 2017-01-30 03:31:48 +03:00
parent 08090b5075
commit eb5e896e33
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710

View File

@ -103,6 +103,10 @@ import Language.Haskell.Meta (parseExp)
import Data.Generics.Uniplate.Data (transform)
----------------------------------------------------------------------------
-- Lists
----------------------------------------------------------------------------
-- | Move the -1st element that satisfies the predicate- up.
moveUp :: (a -> Bool) -> [a] -> [a]
moveUp p (x:y:xs) = if p y then y : x : xs else x : moveUp p (y:xs)
@ -129,9 +133,17 @@ ordNub = go mempty
go s (x:xs) | x `S.member` s = go s xs
| otherwise = x : go (S.insert x s) xs
----------------------------------------------------------------------------
-- Eq
----------------------------------------------------------------------------
equating :: Eq b => (a -> b) -> (a -> a -> Bool)
equating f = (==) `on` f
----------------------------------------------------------------------------
-- Urls
----------------------------------------------------------------------------
type Url = Text
sanitiseUrl :: Url -> Maybe Url
@ -150,6 +162,10 @@ makeSlug =
T.toLower .
T.map (\x -> if x == '_' || x == '/' then '-' else x)
----------------------------------------------------------------------------
-- IP
----------------------------------------------------------------------------
deriveSafeCopySimple 0 'base ''IPv4
deriveSafeCopySimple 0 'base ''IPv6
deriveSafeCopySimple 0 'base ''IP
@ -159,6 +175,10 @@ sockAddrToIP (Network.SockAddrInet _ x) = Just (IPv4 (fromHostAddress x))
sockAddrToIP (Network.SockAddrInet6 _ _ x _) = Just (IPv6 (fromHostAddress6 x))
sockAddrToIP _ = Nothing
----------------------------------------------------------------------------
-- Uid
----------------------------------------------------------------------------
-- | Unique id, used for many things categories, items, and anchor ids.
newtype Uid a = Uid {uidToText :: Text}
deriving (Eq, Ord, Show, PathPiece, T.Buildable, Hashable, A.ToJSON)
@ -206,17 +226,29 @@ data Node
uid_ :: Uid Node -> Attribute
uid_ = id_ . uidToText
----------------------------------------------------------------------------
-- Lucid
----------------------------------------------------------------------------
includeJS :: Monad m => Url -> HtmlT m ()
includeJS url = with (script_ "") [src_ url]
includeCSS :: Monad m => Url -> HtmlT m ()
includeCSS url = link_ [rel_ "stylesheet", type_ "text/css", href_ url]
----------------------------------------------------------------------------
-- Spock
----------------------------------------------------------------------------
atomFeed :: MonadIO m => Atom.Feed -> ActionCtxT ctx m ()
atomFeed feed = do
setHeader "Content-Type" "application/atom+xml; charset=utf-8"
bytes $ T.encodeUtf8 (T.pack (XML.ppElement (Atom.xmlFeed feed)))
----------------------------------------------------------------------------
-- Template Haskell
----------------------------------------------------------------------------
hs :: QuasiQuoter
hs = QuasiQuoter {
quoteExp = either fail TH.lift . parseExp,
@ -235,6 +267,10 @@ dumpSplices x = do
bangNotStrict :: Q Bang
bangNotStrict = bang noSourceUnpackedness noSourceStrictness
----------------------------------------------------------------------------
-- SafeCopy
----------------------------------------------------------------------------
{- |
A change from one version of a record (one constructor, several fields) to
another version. We only record the latest version, so we have to be able to
@ -544,5 +580,9 @@ migrateVer tyName ver constructors = do
lam1E (varP arg) (caseE (varE arg) (map return branches'))
----------------------------------------------------------------------------
-- Orphan instances
----------------------------------------------------------------------------
instance MonadThrow m => MonadThrow (HtmlT m) where
throwM e = lift $ throwM e