packages feed

lambdatex 0.1.0.1 → 0.1.0.2

raw patch · 4 files changed

+48/−13 lines, 4 filesdep +async

Dependencies added: async

Files

lambdatex.cabal view
@@ -1,5 +1,5 @@ name:                lambdatex-version:             0.1.0.1+version:             0.1.0.2 synopsis:            Type-Safe LaTeX EDSL description:            ΛTeX, pronounced 'LambdaTeX' is a Haskell EDSL that adds type-safety to LaTeX.@@ -20,6 +20,7 @@ library   hs-source-dirs:      src   exposed-modules:     Text.LaTeX.LambdaTeX+                       Text.LaTeX.LambdaTeX.Action                        Text.LaTeX.LambdaTeX.Error                        Text.LaTeX.LambdaTeX.Package                        Text.LaTeX.LambdaTeX.Package.Internal@@ -40,6 +41,7 @@                      , containers       >= 0.5      && < 0.6                      , transformers     >= 0.4      && < 0.5                      , directory        >= 1.2      && < 1.3+                     , async            >= 2.0      && < 2.1   ghc-options:        -Wall                       -fwarn-unused-imports                       -fwarn-incomplete-patterns
src/Text/LaTeX/LambdaTeX.hs view
@@ -15,19 +15,25 @@     -- ** Packages dependencies     , module Text.LaTeX.LambdaTeX.Package +    -- ** IO dependencies+    , module Text.LaTeX.LambdaTeX.Action+     -- ** Re-exports     , module Text.LaTeX.LambdaTeX.Types      ) where +import           Control.Monad                           (forM_) import           Control.Monad.IO.Class                  (MonadIO (..)) +import           Control.Concurrent.Async                (async, wait)+ import qualified Data.Set                                as S-import qualified Data.Text                               as T import qualified Data.Text.IO                            as T  import           Text.LaTeX.Base                         (LaTeX, renderFile) +import           Text.LaTeX.LambdaTeX.Action import           Text.LaTeX.LambdaTeX.Package import           Text.LaTeX.LambdaTeX.Package.Internal import           Text.LaTeX.LambdaTeX.Reference@@ -46,20 +52,31 @@ --      * LaTeX file generation --      * Automatic bibtex file generation --      * All safety provided by 'execLambdaTeXT' (in the form of textual errors)---      * TODO(kerckhove) Automatic asynchronic resolution of figure dependencies on graphviz or tikz figures+--      * Automatic asynchronic resolution of IO dependencies for graphviz or tikz figures buildLaTeXProject :: MonadIO m => ΛTeXT m a -> ProjectConfig -> m (Either [ΛError] ()) buildLaTeXProject func conf = do-    (errs, (latex, refs)) <- execLambdaTeXT func $ projectGenerationConfig conf+    (errs, latex, refs, actions) <- execLambdaTeXT func $ projectGenerationConfig conf +     -- Render tex file-    let mainTexFile = projectTexFileName conf ++ ".tex"-    liftIO $ renderFile mainTexFile latex+    let renderTex = do+            let mainTexFile = projectTexFileName conf ++ ".tex"+            renderFile mainTexFile latex      -- Render bib file-    let mainBibFile = projectBibFileName conf ++ ".bib"-    liftIO $ removeIfExists mainBibFile-    liftIO $ T.appendFile mainBibFile $ renderReferences refs+    let renderMain = do+            let mainBibFile = projectBibFileName conf ++ ".bib"+            removeIfExists mainBibFile+            T.appendFile mainBibFile $ renderReferences refs +    let performAction (name, action) = do+            action+            putStrLn $ "Job " ++ name ++ " done."++    -- Perform all the IO actions asynchronously+    as <- liftIO $ mapM async $ renderTex : renderMain : map performAction actions+    liftIO $ forM_ as wait+     return $ if null errs         then Right ()         else Left errs@@ -74,11 +91,12 @@ --      * Internal dependency safety. No more '??' for external references in the internal pdf. --      * Package dependency resolution, TODO(kerckhove) with packages in the right order --      * Dependency selection of figure dependencies on graphviz or tikz figures-execLambdaTeXT :: Monad m => ΛTeXT m a -> GenerationConfig -> m ([ΛError], (LaTeX, [Reference]))+execLambdaTeXT :: Monad m => ΛTeXT m a -> GenerationConfig -> m ([ΛError], LaTeX, [Reference], [(String, IO ())]) execLambdaTeXT func conf = do     ((_,latex), _, output) <- runΛTeX func (ΛConfig $ generationSelection conf) initState     let result = injectPackageDependencies (S.toList $ outputPackageDependencies output) latex     let refs = S.toList $ outputExternalReferences output+    let actions = outputActions output      -- Check reference errors     let made = outputLabelsMade output@@ -87,7 +105,7 @@      let referss = map ReferenceMissing $ S.toList diff -    return (referss, (result, refs))+    return (referss, result, refs, actions)    where     initState :: ΛState
+ src/Text/LaTeX/LambdaTeX/Action.hs view
@@ -0,0 +1,12 @@+{-# LANGUAGE OverloadedStrings #-}+module Text.LaTeX.LambdaTeX.Action where++import           Text.LaTeX.LambdaTeX.Types++-- | Register an IO action (with a given name) that needs to be completed before the pdf can be built.+--+-- Use this to generate and build external resources that are included with @includegraphics@ for example.+registerAction :: Monad m => String -- ^ Name of the job+                          -> IO () -- ^ Job+                          -> ΛTeXT m ()+registerAction name func = λtell $ mempty { outputActions = [(name, func)] }
src/Text/LaTeX/LambdaTeX/Types.hs view
@@ -140,14 +140,16 @@     , outputExternalReferences  :: Set Reference     , outputLabelsMade          :: Set Text     , outputLabelsNeeded        :: Set Text+    , outputActions             :: [(String, IO ())]     }  instance Monoid ΛOutput where     mempty = ΛOutput {             outputPackageDependencies   = S.empty           , outputExternalReferences    = S.empty-          , outputLabelsMade = S.empty-          , outputLabelsNeeded = S.empty+          , outputLabelsMade            = S.empty+          , outputLabelsNeeded          = S.empty+          , outputActions               = []         }      mappend o1 o2 = ΛOutput {@@ -167,6 +169,7 @@                 S.union                     (outputLabelsNeeded o1)                     (outputLabelsNeeded o2)+          , outputActions = outputActions o1 ++ outputActions o2         }  -- | Internal ΛTeXT configration state