packages feed

slick 1.0.0.0 → 1.0.1.0

raw patch · 3 files changed

+61/−25 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Slick.Pandoc: makePandocReaderWithMetaWriter :: PandocReader textType -> PandocWriter -> textType -> Action (Pandoc, Value)
+ Slick.Pandoc: makePandocReaderWithMetaWriter' :: FromJSON a => PandocReader textType -> PandocWriter -> textType -> Action (Pandoc, a)
- Slick.Pandoc: flattenMeta :: Meta -> Value
+ Slick.Pandoc: flattenMeta :: PandocWriter -> Meta -> Action Value

Files

ChangeLog.md view
@@ -1,4 +1,7 @@-# Changelog for sitepipe-shake+# Changelog for slick++## 1.0.1.0+- Add `makePandocReaderWithMetaWriter` and `makePandocReaderWithMetaWriter'` for reading in resources with custom Pandoc Writers for metadata.  ## 1.0.0.0 - Deprecate Slick.Caching, Simplify all other exports down.
slick.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 0def596009a546aa4cc3a910ba96020819375b351a32b7ff351c592cb3813f17+-- hash: f0f250c963e4f6345648991c39e8eee43d66c1fe739aeac8e9e349ad2ce3d9c6  name:           slick-version:        1.0.0.0+version:        1.0.1.0 synopsis:       A quick & easy static site builder built with shake and pandoc. description:    Please see the README on GitHub at <https://github.com/ChrisPenner/slick#readme> category:       Web
src/Slick/Pandoc.hs view
@@ -13,6 +13,8 @@   , markdownToHTMLWithOpts'    , makePandocReader   , makePandocReader'+  , makePandocReaderWithMetaWriter+  , makePandocReaderWithMetaWriter'   , PandocReader   , PandocWriter   , loadUsing@@ -27,7 +29,6 @@ import Development.Shake import Text.Pandoc import Text.Pandoc.Highlighting-import Text.Pandoc.Shared import Slick.Utils import Data.HashMap.Strict as HM @@ -109,22 +110,54 @@  -- | Given a reader from 'Text.Pandoc.Readers' this creates a loader which --   given the source document will read its metadata into a 'Value'---   returning both the 'Pandoc' object and the metadata within an 'Action'+--   returning both the 'Pandoc' object and the metadata within an 'Action'.+--   The metadata values will be read as Markdown but rendered as plain text,+--   removing any links, pictures, and inline formatting. makePandocReader :: PandocReader textType                  -> textType                  -> Action (Pandoc, Value)-makePandocReader readerFunc text = do+makePandocReader readerFunc text =+  makePandocReaderWithMetaWriter readerFunc (writePlain def) text++-- | Given a reader from 'Text.Pandoc.Readers', and a writer from+--   'Text.Pandoc.Writers', this creates a loader which given the source+--   document will read its metadata as Markdown, then render it into a+--   'Value' using the writer, returning both the 'Pandoc' object and the+--   metadata within an 'Action'+makePandocReaderWithMetaWriter+    :: PandocReader textType+    -> PandocWriter+    -> textType+    -> Action (Pandoc, Value)+makePandocReaderWithMetaWriter readerFunc writerFunc text = do   pdoc@(Pandoc meta _) <- unPandocM $ readerFunc text-  return (pdoc, flattenMeta meta)+  meta' <- flattenMeta writerFunc meta+  return (pdoc, meta') --- | Like 'makePandocReader' but will deserialize the metadata into any object---   which implements 'FromJSON'. Failure to deserialize will fail the Shake---   build.-makePandocReader' :: (FromJSON a) => PandocReader textType-                  -> textType-                  -> Action (Pandoc, a)-makePandocReader' readerFunc text = do-  (pdoc, meta)  <- makePandocReader readerFunc text+-- | Like 'makePandocReader' but will deserialize the metadata+--   into any object which implements 'FromJSON'. Failure to deserialize will+--   fail the Shake build. Metadata values will be read as Markdown but+--   rendered as plain text, removing any links, pictures, and inline+--   formatting.+makePandocReader'+    :: (FromJSON a)+    => PandocReader textType+    -> textType+    -> Action (Pandoc, a)+makePandocReader' readerFunc text =+  makePandocReaderWithMetaWriter' readerFunc (writePlain def) text++-- | Like 'makePandocReaderWithMetaWriter' but will deserialize the metadata+--   into any object which implements 'FromJSON'. Failure to deserialize will+--   fail the Shake build.+makePandocReaderWithMetaWriter'+    :: (FromJSON a)+    => PandocReader textType+    -> PandocWriter+    -> textType+    -> Action (Pandoc, a)+makePandocReaderWithMetaWriter' readerFunc writerFunc text = do+  (pdoc, meta)  <- makePandocReaderWithMetaWriter readerFunc writerFunc text   convertedMeta <- convert meta   return (pdoc, convertedMeta) @@ -139,7 +172,7 @@           -> textType           -> Action Value loadUsing reader writer text = do-  (pdoc, meta) <- makePandocReader reader text+  (pdoc, meta) <- makePandocReaderWithMetaWriter reader writer text   outText      <- unPandocM $ writer pdoc   withContent <- case meta of       Object m -> return . Object $ HM.insert "content" (String outText) m@@ -162,13 +195,13 @@  -- | Flatten a Pandoc 'Meta' into a well-structured JSON object, rendering Pandoc --   text objects into plain strings along the way.-flattenMeta :: Meta -> Value-flattenMeta (Meta meta) = toJSON $ fmap go meta+flattenMeta :: PandocWriter -> Meta -> Action Value+flattenMeta writer (Meta meta) = toJSON <$> traverse go meta  where-  go :: MetaValue -> Value-  go (MetaMap     m) = toJSON $ fmap go m-  go (MetaList    m) = toJSONList $ fmap go m-  go (MetaBool    m) = toJSON m-  go (MetaString  m) = toJSON m-  go (MetaInlines m) = toJSON $ stringify m-  go (MetaBlocks  m) = toJSON $ stringify m+  go :: MetaValue -> Action Value+  go (MetaMap     m) = toJSON <$> traverse go m+  go (MetaList    m) = toJSONList <$> traverse go m+  go (MetaBool    m) = pure $ toJSON m+  go (MetaString  m) = pure $ toJSON m+  go (MetaInlines m) = toJSON <$> (unPandocM . writer . Pandoc mempty . (:[]) . Plain $ m)+  go (MetaBlocks  m) = toJSON <$> (unPandocM . writer . Pandoc mempty $ m)