Skip to content

Commit

Permalink
Refactor out Comments module
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Jan 3, 2025
1 parent 85013c5 commit 9a24b4e
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 148 deletions.
8 changes: 4 additions & 4 deletions lib/Patat/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import qualified Patat.EncodingFallback as EncodingFallback
import qualified Patat.Eval as Eval
import qualified Patat.Images as Images
import Patat.Presentation
import qualified Patat.Presentation.Comments as Comments
import qualified Patat.Presentation.SpeakerNotes as SpeakerNotes
import qualified Patat.PrettyPrint as PP
import Patat.PrettyPrint.Matrix (hPutMatrix)
import Patat.Transition
Expand Down Expand Up @@ -127,7 +127,7 @@ assertAnsiFeatures = do
data App = App
{ aOptions :: Options
, aImages :: Maybe Images.Handle
, aSpeakerNotes :: Maybe Comments.SpeakerNotesHandle
, aSpeakerNotes :: Maybe SpeakerNotes.Handle
, aCommandChan :: Chan AppCommand
, aPresentation :: Presentation
, aView :: AppView
Expand Down Expand Up @@ -175,7 +175,7 @@ main = do
withMaybeHandle Images.withHandle (psImages settings) $ \images ->

-- (Maybe) initialize speaker notes.
withMaybeHandle Comments.withSpeakerNotesHandle
withMaybeHandle SpeakerNotes.withHandle
(psSpeakerNotes settings) $ \speakerNotes ->

-- Read presentation commands
Expand Down Expand Up @@ -206,7 +206,7 @@ main = do
--------------------------------------------------------------------------------
loop :: App -> IO ()
loop app@App {..} = do
for_ aSpeakerNotes $ \sn -> Comments.writeSpeakerNotes sn
for_ aSpeakerNotes $ \sn -> SpeakerNotes.write sn
(pEncodingFallback aPresentation)
(activeSpeakerNotes aPresentation)

Expand Down
97 changes: 0 additions & 97 deletions lib/Patat/Presentation/Comments.hs

This file was deleted.

4 changes: 2 additions & 2 deletions lib/Patat/Presentation/Display.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import qualified Data.List as L
import Data.Maybe (fromMaybe, maybeToList)
import qualified Data.Sequence.Extended as Seq
import qualified Data.Text as T
import qualified Patat.Presentation.Comments as Comments
import Patat.Presentation.Display.CodeBlock
import Patat.Presentation.Display.Internal
import Patat.Presentation.Display.Table
import Patat.Presentation.Internal
import Patat.Presentation.Settings
import qualified Patat.Presentation.SpeakerNotes as SpeakerNotes
import Patat.Presentation.Syntax
import Patat.PrettyPrint ((<$$>), (<+>))
import qualified Patat.PrettyPrint as PP
Expand Down Expand Up @@ -167,7 +167,7 @@ dumpPresentation pres@Presentation {..} =
dumpSpeakerNotes slide = do
guard (slideSpeakerNotes slide /= mempty)
pure $ PP.text $ "{speakerNotes: " <>
Comments.speakerNotesToText (slideSpeakerNotes slide) <> "}"
SpeakerNotes.toText (slideSpeakerNotes slide) <> "}"

dumpFragment :: Index -> [PP.Doc]
dumpFragment idx =
Expand Down
28 changes: 14 additions & 14 deletions lib/Patat/Presentation/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ module Patat.Presentation.Internal


--------------------------------------------------------------------------------
import qualified Data.Aeson.Extended as A
import qualified Data.HashMap.Strict as HMS
import qualified Data.HashSet as HS
import Data.Maybe (fromMaybe)
import Data.Sequence.Extended (Seq)
import qualified Data.Sequence.Extended as Seq
import Patat.EncodingFallback (EncodingFallback)
import qualified Patat.Eval.Internal as Eval
import qualified Patat.Presentation.Comments as Comments
import qualified Data.Aeson.Extended as A
import qualified Data.HashMap.Strict as HMS
import qualified Data.HashSet as HS
import Data.Maybe (fromMaybe)
import Data.Sequence.Extended (Seq)
import qualified Data.Sequence.Extended as Seq
import Patat.EncodingFallback (EncodingFallback)
import qualified Patat.Eval.Internal as Eval
import Patat.Presentation.Settings
import qualified Patat.Presentation.SpeakerNotes as SpeakerNotes
import Patat.Presentation.Syntax
import Patat.Size
import Patat.Transition (TransitionGen)
import Patat.Transition (TransitionGen)
import Patat.Unique
import Prelude
import qualified Skylighting as Skylighting
import qualified Text.Pandoc as Pandoc
import qualified Skylighting as Skylighting
import qualified Text.Pandoc as Pandoc


--------------------------------------------------------------------------------
Expand Down Expand Up @@ -108,7 +108,7 @@ margins ps = Margins

--------------------------------------------------------------------------------
data Slide = Slide
{ slideSpeakerNotes :: !Comments.SpeakerNotes
{ slideSpeakerNotes :: !SpeakerNotes.SpeakerNotes
, slideSettings :: !(Either String PresentationSettings)
, slideContent :: !SlideContent
} deriving (Show)
Expand Down Expand Up @@ -164,7 +164,7 @@ activeFragment presentation = do


--------------------------------------------------------------------------------
activeSpeakerNotes :: Presentation -> Comments.SpeakerNotes
activeSpeakerNotes :: Presentation -> SpeakerNotes.SpeakerNotes
activeSpeakerNotes presentation = fromMaybe mempty $ do
let (sidx, _) = pActiveFragment presentation
slide <- getSlide sidx presentation
Expand Down
59 changes: 30 additions & 29 deletions lib/Patat/Presentation/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@ module Patat.Presentation.Read


--------------------------------------------------------------------------------
import Control.Monad (guard)
import Control.Monad.Except (ExceptT (..), runExceptT,
throwError)
import Control.Monad.Trans (liftIO)
import qualified Data.Aeson.Extended as A
import qualified Data.Aeson.KeyMap as AKM
import Data.Bifunctor (first)
import Data.Maybe (fromMaybe)
import Data.Sequence.Extended (Seq)
import qualified Data.Sequence.Extended as Seq
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Traversable (for)
import qualified Data.Yaml as Yaml
import Patat.EncodingFallback (EncodingFallback)
import qualified Patat.EncodingFallback as EncodingFallback
import qualified Patat.Eval as Eval
import qualified Patat.Presentation.Comments as Comments
import Control.Monad (guard)
import Control.Monad.Except (ExceptT (..), runExceptT,
throwError)
import Control.Monad.Trans (liftIO)
import qualified Data.Aeson.Extended as A
import qualified Data.Aeson.KeyMap as AKM
import Data.Bifunctor (first)
import Data.Maybe (fromMaybe)
import Data.Sequence.Extended (Seq)
import qualified Data.Sequence.Extended as Seq
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Traversable (for)
import qualified Data.Yaml as Yaml
import Patat.EncodingFallback (EncodingFallback)
import qualified Patat.EncodingFallback as EncodingFallback
import qualified Patat.Eval as Eval
import Patat.Presentation.Fragment
import Patat.Presentation.Internal
import qualified Patat.Presentation.SpeakerNotes as SpeakerNotes
import Patat.Presentation.Syntax
import Patat.Transition (parseTransitionSettings)
import Patat.Transition (parseTransitionSettings)
import Patat.Unique
import Prelude
import qualified Skylighting as Skylighting
import System.Directory (XdgDirectory (XdgConfig),
doesFileExist, getHomeDirectory,
getXdgDirectory)
import System.FilePath (splitFileName, takeExtension,
(</>))
import qualified Text.Pandoc.Error as Pandoc
import qualified Text.Pandoc.Extended as Pandoc
import qualified Skylighting as Skylighting
import System.Directory (XdgDirectory (XdgConfig),
doesFileExist,
getHomeDirectory,
getXdgDirectory)
import System.FilePath (splitFileName, takeExtension,
(</>))
import qualified Text.Pandoc.Error as Pandoc
import qualified Text.Pandoc.Extended as Pandoc


--------------------------------------------------------------------------------
Expand Down Expand Up @@ -242,7 +243,7 @@ splitSlides slideLevel blocks0
mkContentSlide :: [Block] -> [Slide]
mkContentSlide bs0 = do
let bs1 = filter (not . isComment) bs0
sns = Comments.SpeakerNotes [s | SpeakerNote s <- bs0]
sns = SpeakerNotes.SpeakerNotes [s | SpeakerNote s <- bs0]
cfgs = concatCfgs [cfg | Config cfg <- bs0]
guard $ not $ null bs1 -- Never create empty slides
pure $ Slide sns cfgs $ ContentSlide bs1
Expand All @@ -259,7 +260,7 @@ splitSlides slideLevel blocks0
mkContentSlide (reverse acc) ++ splitAtHeaders [b] bs0
| otherwise =
let (cmnts, bs1) = break (not . isComment) bs0
sns = Comments.SpeakerNotes [s | SpeakerNote s <- cmnts]
sns = SpeakerNotes.SpeakerNotes [s | SpeakerNote s <- cmnts]
cfgs = concatCfgs [cfg | Config cfg <- cmnts] in
mkContentSlide (reverse acc) ++
[Slide sns cfgs $ TitleSlide i txt] ++
Expand Down
38 changes: 37 additions & 1 deletion lib/Patat/Presentation/Settings.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--------------------------------------------------------------------------------
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
Expand All @@ -22,12 +23,14 @@ module Patat.Presentation.Settings
, SpeakerNotesSettings (..)

, TransitionSettings (..)

, parseSlideSettings
) where


--------------------------------------------------------------------------------
import Control.Applicative ((<|>))
import Control.Monad (mplus)
import Control.Monad (mplus, unless)
import qualified Data.Aeson.Extended as A
import qualified Data.Aeson.TH.Extended as A
import qualified Data.Foldable as Foldable
Expand Down Expand Up @@ -296,3 +299,36 @@ instance A.FromJSON TransitionSettings where
$(A.deriveFromJSON A.dropPrefixOptions ''MarginSettings)
$(A.deriveFromJSON A.dropPrefixOptions ''SpeakerNotesSettings)
$(A.deriveFromJSON A.dropPrefixOptions ''PresentationSettings)


--------------------------------------------------------------------------------
data Setting where
Setting :: String -> (PresentationSettings -> Maybe a) -> Setting


--------------------------------------------------------------------------------
unsupportedSlideSettings :: [Setting]
unsupportedSlideSettings =
[ Setting "incrementalLists" psIncrementalLists
, Setting "autoAdvanceDelay" psAutoAdvanceDelay
, Setting "slideLevel" psSlideLevel
, Setting "pandocExtensions" psPandocExtensions
, Setting "images" psImages
, Setting "eval" psEval
, Setting "speakerNotes" psSpeakerNotes
]


--------------------------------------------------------------------------------
parseSlideSettings :: PresentationSettings -> Either String PresentationSettings
parseSlideSettings settings = do
unless (null unsupported) $ Left $
"the following settings are not supported in slide config blocks: " ++
intercalate ", " unsupported
pure settings
where
unsupported = do
setting <- unsupportedSlideSettings
case setting of
Setting name f | Just _ <- f settings -> [name]
Setting _ _ -> []
Loading

0 comments on commit 9a24b4e

Please sign in to comment.