From b8821e100e0d8b02cde5392a2bb7d5f71428de87 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 15 Sep 2018 15:20:50 +0200 Subject: Disable thermoprint via flag --- Handler/List.hs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'Handler/List.hs') diff --git a/Handler/List.hs b/Handler/List.hs index 522f6f5..a2194ba 100644 --- a/Handler/List.hs +++ b/Handler/List.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE PatternGuards #-} - module Handler.List where import Import @@ -12,8 +10,18 @@ import qualified Data.Map as Map import qualified Data.Text as Text import qualified Data.Text.Lazy as Lazy.Text +#ifdef THERMOPRINT import Thermoprint.Client +mkPrintout :: Set (WithType Text) -> Printout +mkPrintout list = Printout ps + where + ps = Map.foldMapWithKey (fmap (pure . Paragraph . pure . Cooked) . toLines) $ group list + group = Map.fromListWith (<>) . fmap (\(kind `WithType` t) -> (t, Set.singleton kind)) . Set.toAscList + toLines t (Set.toAscList -> kinds) = either id Line . text . Lazy.Text.fromStrict . Text.unlines $ + pure t ++ map (" - " <>) kinds +#endif + list :: Handler (Set (WithType Text)) list = runDB $ do today <- liftIO $ utctDay <$> getCurrentTime @@ -34,14 +42,8 @@ list = runDB $ do return $ Set.map (fmap referenceKind) references' -mkPrintout :: Set (WithType Text) -> Printout -mkPrintout list = Printout ps - where - ps = Map.foldMapWithKey (fmap (pure . Paragraph . pure . Cooked) . toLines) $ group list - group = Map.fromListWith (<>) . fmap (\(kind `WithType` t) -> (t, Set.singleton kind)) . Set.toAscList - toLines t (Set.toAscList -> kinds) = either id Line . text . Lazy.Text.fromStrict . Text.unlines $ - pure t ++ map (" - " <>) kinds +#ifdef THERMOPRINT getListR, postListR :: Handler TypedContent getListR = postListR postListR = do @@ -99,3 +101,12 @@ postListR = do selectRep $ do provideJson $ typeToJSON "item" <$> Set.toAscList list provideRep $ defaultLayout $(widgetFile "list") +#else +getListR, postListR :: Handler TypedContent +getListR = postListR +postListR = do + list <- list + selectRep $ do + provideJson $ typeToJSON "item" <$> Set.toAscList list + provideRep $ defaultLayout $(widgetFile "list-no-thermoprint") +#endif -- cgit v1.2.3