packages feed

herringbone 0.0.3 → 0.0.4

raw patch · 3 files changed

+48/−11 lines, 3 filesdep +mtl

Dependencies added: mtl

Files

Web/Herringbone/BuildAsset.hs view
@@ -2,6 +2,7 @@ -- if necessary, and copy to destination directory). module Web.Herringbone.BuildAsset where +import Control.Monad.Reader import Data.Time import Filesystem.Path.CurrentOS (FilePath, (</>)) import qualified Filesystem as F@@ -24,7 +25,7 @@     compileNeeded <- shouldCompile sourceModifiedTime destPath      result <- if compileNeeded-                then compileAsset sourcePath destPath pps+                then compileAsset hb logPath sourcePath destPath pps                 else return $ Right ()      either (return . Left)@@ -50,14 +51,24 @@  -- | Compile the given asset by invoking any preprocessors on the source path, -- and copying the result to the destination path.-compileAsset :: FilePath -- ^ Source path+compileAsset :: Herringbone+             -> LogicalPath+             -> FilePath -- ^ Source path              -> FilePath -- ^ Dest path              -> [PP]     -- ^ List of preprocessors to apply              -> IO (Either CompileError ())-compileAsset sourcePath destPath pps = do+compileAsset hb logPath sourcePath destPath pps = do     sourceData <- F.readFile sourcePath -    result <- chainEither (map ppAction pps) sourceData+    let computation = chainEither (map ppAction pps) sourceData+    let readerData = PPReader+            { ppReaderHb          = hb+            , ppReaderLogicalPath = logPath+            , ppReaderSourcePath  = sourcePath+            , ppReaderPPs         = pps+            }+    result <- runPPM computation readerData+     either (return . Left)            (\resultData -> do F.writeFile destPath resultData                               return (Right ()))
Web/Herringbone/Types.hs view
@@ -1,5 +1,6 @@ module Web.Herringbone.Types where +import Control.Monad.Reader import Data.Char import Data.Time.Clock import Data.Time.Format@@ -29,6 +30,27 @@                 | AmbiguousSources [FilePath]                 deriving (Show, Eq) +-- | Data which is given to preprocessors on the off-chance that they need it+-- (eg, Fay)+data PPReader = PPReader+    { ppReaderHb          :: Herringbone +    -- ^ The Herringbone which was used to build the asset+    , ppReaderLogicalPath :: LogicalPath+    -- ^ The Logical path of the requested asset.+    , ppReaderSourcePath  :: FilePath+    -- ^ The file path to the source file+    , ppReaderPPs         :: [PP]+    -- ^ Preprocessors being invoked.+    }+    deriving (Show, Eq)++-- | A monad in which preprocessor actions happen.+newtype PPM a = PPM { unPPM :: ReaderT PPReader IO a }+    deriving (Monad, MonadIO, (MonadReader PPReader))++runPPM :: PPM a -> PPReader -> IO a+runPPM comp readerData = runReaderT (unPPM comp) readerData+ -- | A string which should contain information about why an asset failed to -- compile. type CompileError = B.ByteString@@ -47,7 +69,7 @@     { ppExtension :: Text     -- ^ The file extension this preprocessor acts upon, eg \"sass\" or     -- \"hamlet\"-    , ppAction    :: B.ByteString -> IO (Either CompileError B.ByteString)+    , ppAction    :: B.ByteString -> PPM (Either CompileError B.ByteString)     -- ^ Perform the preprocessing.     } @@ -64,7 +86,7 @@  -- | A collection of preprocessors. newtype PPs = PPs { unPPs :: M.Map Text PP }-    deriving (Show)+    deriving (Show, Eq)  noPPs :: PPs noPPs = PPs M.empty@@ -98,12 +120,12 @@     , hbPPs        :: PPs     -- ^ Preprocessors     }-    deriving (Show)+    deriving (Show, Eq)  -- | All assets in Herringbone are referenced by their logical path. This is -- the path to an asset, relative to any of the source directories. newtype LogicalPath = LogicalPath { fromLogicalPath :: [Text] }-    deriving (Show)+    deriving (Show, Eq)  -- | Create a LogicalPath from a list of Text values. This returns Nothing if -- the path would be unsafe (that is, if it contains \"..\"), to prevent
herringbone.cabal view
@@ -1,5 +1,5 @@ name:                herringbone-version:             0.0.3+version:             0.0.4 synopsis:            A library for compiling and serving static web assets. description:         A library for compiling and serving static web assets. For more information, please see <https://github.com/hdgarrood/herringbone>. license:             MIT@@ -25,6 +25,7 @@                         text,                         bytestring,                         containers,+                        mtl,                         system-filepath,                         system-fileio,                         directory,@@ -38,7 +39,8 @@   default-extensions:   OverloadedStrings,                         TypeSynonymInstances,                         FlexibleInstances,-                        RankNTypes+                        RankNTypes,+                        GeneralizedNewtypeDeriving   default-language:     Haskell2010  library@@ -56,6 +58,7 @@                         text,                         bytestring,                         containers,+                        mtl,                         system-filepath,                         system-fileio,                         directory,@@ -66,5 +69,6 @@   default-extensions:   OverloadedStrings,                         TypeSynonymInstances,                         FlexibleInstances,-                        RankNTypes+                        RankNTypes,+                        GeneralizedNewtypeDeriving   default-language:     Haskell2010