refactor(pandoc): avoid unnecessary explicit dependency for doctemplates, which is now a hidden dependency of pandoc again

This commit is contained in:
Steffen Jost 2022-07-06 08:56:15 +02:00
parent 249019189f
commit 0eb165da9b
4 changed files with 35 additions and 7 deletions

View File

@ -146,8 +146,7 @@ dependencies:
- wai-middleware-prometheus
- extended-reals
- rfc5051
- unidecode
- doctemplates
- unidecode
- pandoc
- pandoc-types
- insert-ordered-containers

View File

@ -46,6 +46,25 @@ formToMetaValues MetaPinRenewal{..} = P.Meta . mconcat $ catMaybes
where
toMeta k = singletonMap k . P.toMetaValue
formToMetaValues2 :: MetaPinRenewal -> P.Meta
formToMetaValues2 MetaPinRenewal{..} = P.Meta $ mconcat
[ mbMeta "opening" mppOpening
, mbMeta "closing" mppClosing
, mbMeta "date" mppDate
, mbMeta "url" mppURL
, toMeta "login" mppLogin
, toMeta "pin" mppPin
, toMeta "recipient" mppRecipient
, toMeta "address" mppAddress
, toMeta "lang" mppLang
, toMeta "is-de" mppIsDe
]
where
mbMeta _ Nothing = mempty
mbMeta k (Just x) = toMeta k x
toMeta k = singletonMap k . P.toMetaValue
{-
makePrintForm :: Maybe MetaPinRenewal -> Form MetaPinRenewal
makePrintForm tmpl = identifyForm FIDLmsLetter . validateForm validateMetaPinRenewal $ \html ->

View File

@ -663,6 +663,14 @@ partMap = Map.fromListWith mappend
invertMap :: (Ord k, Ord v) => Map k v -> Map v (Set k)
invertMap = groupMap . map swap . Map.toList
maybeMap :: IsMap p => ContainerKey p -> Maybe (MapValue p) -> p
maybeMap _ Nothing = mempty
maybeMap k (Just v) = singletonMap k v
maybeMapWith :: IsMap p => (t -> MapValue p) -> ContainerKey p -> Maybe t -> p
maybeMapWith _ _ Nothing = mempty
maybeMapWith f k (Just v) = singletonMap k $ f v
-- | Counts how often a value appears in a map (not derived from invertMap for efficiency reasons)
countMapElems :: (Ord v) => Map k v -> Map v Int
countMapElems = Map.fromListWith (+) . map (\(_k,v)->(v,1)) . Map.toList

View File

@ -8,7 +8,6 @@ import Control.Monad.Except
import Import hiding (embedFile)
import Data.FileEmbed (embedFile)
import qualified Text.DocTemplates as P
import qualified Text.Pandoc as P
-- import qualified Text.Pandoc.PDF as P
import qualified Text.Pandoc.Builder as P
@ -34,12 +33,15 @@ addMeta :: P.Meta -> P.Pandoc -> P.Pandoc
addMeta m p = meta <> p
where meta = P.Pandoc m mempty
-- reTemplateLetter :: (P.PandocMonad m, P.TemplateMonad m, Foldable t, P.ToMetaValue a) => t (Text, a) -> StoredMarkup -> m Text
reTemplateLetter :: (P.TemplateMonad m, P.PandocMonad m) => P.Meta -> StoredMarkup -> m Text
-- | Apply StoredMarkup as a template to itself and return the resulting Markup
-- This is a hack to allow variable interpolation within a document.
-- Pandoc currently only allows interpolation within templates.
-- An alternative Route would be to use Builders, but this prevents User-edited Markup Templates
reTemplateLetter :: P.PandocMonad m => P.Meta -> StoredMarkup -> m Text
reTemplateLetter meta StoredMarkup{..} = do
let strictMarkupInput = toStrict markupInput
mdTemplate <- P.compileTemplate "" strictMarkupInput
partialPath = "" -- no partials used, see Text.DocTemplates
mdTemplate <- P.runWithDefaultPartials $ P.compileTemplate partialPath strictMarkupInput
case mdTemplate of
(Left err) -> throwError . P.PandocTemplateError $ pack err
(Right templ) -> do