gdritter repos inf-dict / f6ecd17
Bump base version and allow for some library changes Getty Ritter 4 years ago
3 changed file(s) with 13 addition(s) and 10 deletion(s). Collapse all Expand all
1818 default-extensions: OverloadedStrings,
1919 ScopedTypeVariables
2020 ghc-options: -Wall
21 build-depends: base >=4.7 && <4.9,
22 Spock,
21 build-depends: base >=4.7 && <5,
22 Spock >=0.10,
2323 lucid,
2424 sqlite-simple,
2525 text,
88 import Network.Wai.Middleware.Static (staticPolicy, hasPrefix)
99 import System.Environment (lookupEnv)
1010 import Web.Spock
11 import Web.Spock.Config
1112
1213 import Render
1314 import Types
1415
15 respondWith :: [Entry] -> ActionCtxT ctx IO ()
16 respondWith :: MonadIO m => [Entry] -> ActionCtxT ctx m ()
1617 respondWith es = do
1718 pref <- preferredFormat
1819 case pref of
1920 PrefJSON -> json es
2021 _ -> html (rPage (rEntries es))
2122
22 db :: DB a -> ActionCtxT Connection IO a
23 db :: MonadIO m => DB a -> ActionCtxT Connection m a
2324 db mote = do
2425 conn <- getContext
2526 liftIO (mote conn)
2627
27 unwrap :: Maybe a -> (a -> ActionCtxT ctx IO ()) -> ActionCtxT ctx IO ()
28 unwrap :: MonadIO m => Maybe a -> (a -> ActionCtxT ctx m ()) -> ActionCtxT ctx m ()
2829 unwrap Nothing _ = setStatus status404
2930 unwrap (Just x) f = f x
3031
3334 dbLoc <- maybe "test.db" id `fmap` lookupEnv "DB_LOC"
3435 port <- maybe 8080 read `fmap` lookupEnv "PORT"
3536 conn <- open dbLoc
36 runSpock port $ spockT id $ prehook (return conn) $ do
37 spockCfg <- defaultSpockCfg () PCNoDatabase ()
38 runSpock port $ spock spockCfg $ prehook (return conn) $ do
3739 middleware $ staticPolicy (mempty <> hasPrefix "static")
3840
3941 get root $ do
1 {-# LANGUAGE GADTs #-}
2
13 module Markup where
24
35 import Data.List (intersperse)
68 import qualified Data.Text as T
79 import Lucid
810 import Text.Megaparsec
9 import Text.Megaparsec.Text
11 import Text.Megaparsec.Char
1012
1113 data Chunk
1214 = Bold Text
3032 Left _ -> [Chunk t]
3133 Right cs -> cs
3234
33 parseF :: Parser [Chunk]
35 parseF :: (Stream s, Token s ~ Char) => Parsec () s [Chunk]
3436 parseF = many go
3537 where go = Bold <$> delim '*'
3638 <|> Italic <$> delim '_'
3739 <|> Code <$> delim '`'
3840 <|> Strike <$> delim '~'
3941 <|> (Chunk . T.pack) <$> pChunk
40 delim :: Char -> Parser Text
4142 delim c = (T.pack . (<> " ")) <$>
42 (char c *> manyTill anyChar (try (char c >> space)))
43 (char c *> manyTill asciiChar (try (char c >> space)))
4344 pChunk = some (noneOf ("*_`~" :: String))
4445
4546 build :: [Chunk] -> Html ()