Commit 8c45a68a authored by Henrik Tramberend's avatar Henrik Tramberend
Browse files

Use a map to store files for write back

parent d0cfecb2
......@@ -47,6 +47,7 @@ import Data.Dynamic
import qualified Data.HashMap.Strict as HashMap
import Data.IORef
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Text.Lens
import Data.Typeable
......@@ -77,7 +78,7 @@ data MutableActionState = MutableActionState
{ _server :: IORef (Maybe Server)
, _watch :: IORef Bool
, _publicResource :: Shake.Resource
, _writeBack :: IORef [(FilePath, Pandoc)]
, _writeBack :: IORef (M.Map FilePath Pandoc)
} deriving (Show)
makeLenses ''MutableActionState
......@@ -94,7 +95,7 @@ makeLenses ''ActionContext
initMutableActionState = do
server <- newIORef Nothing
watch <- newIORef False
writeBack <- newIORef []
writeBack <- newIORef M.empty
public <- newResourceIO "public" 1
return $ MutableActionState server watch public writeBack
......@@ -197,14 +198,14 @@ markForWriteBack :: FilePath -> Pandoc -> Action ()
markForWriteBack filepath pandoc = do
putNormal $ "marked for write back: (" ++ filepath ++ ")"
ref <- _writeBack . _state <$> actionContext
liftIO $ modifyIORef ref ((:) (filepath, pandoc))
liftIO $ modifyIORef ref (M.insert filepath pandoc)
writeBackMarkdown :: MutableActionState -> IO ()
writeBackMarkdown state = do
let ref = _writeBack state
writeBack <- readIORef ref
mapM_ (uncurry writeToMarkdownFile) writeBack
writeIORef ref []
mapM_ (uncurry writeToMarkdownFile) (M.toList writeBack)
writeIORef ref M.empty
publicResourceA = _publicResource . _state <$> actionContext
......
---
decker-slide-ids: True
history: True
subtitle: High Quality Slide Annotations
title: Sketch Pad
---
------
# Automatic Slide Id Generation {#cgzk}
## Id Generation
- If meta data attribute `decker-slide-ids` is set
1. If a slide has an id, it is not changed
2. Otherwise a 4-digit id is generated
3. **The markdown source is written back to file**
## Markdown Write Back
- Only makes sense if the text editor has auto-reload enabled
- Forces a rigid formatting of the slide source code
- Not everybody will like this
------
# First Slide {#myslide-dont-touch}
Some body text.
- This slide has a hand-crafted id
- It will not change during further id generation
- It can be used in links (See [two slides up](#s5zu)) as usual
------
# {#sc58j}
# {#tjp3}
- This slide has no header, but a generated id
------
# Third Slide {#s85zu}
# Third Slide {#s5zu}
Some body text.
- This slide has a generated id
- It will not change during further id generation
- It can be used in links (See [two slides down](#myslide-dont-touch)) as usual
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment