project-forge 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+39/−27 lines, 4 files
Files
- project-forge.cabal +1/−1
- src/ProjectForge/Actions.hs +19/−23
- src/ProjectForge/Get.hs +3/−3
- src/ProjectForge/Render.hs +16/−0
project-forge.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: project-forge-version: 0.1.0.0+version: 0.2.0.0 author: Bradley Saul maintainer: bsaul@novisci.com category: Development
src/ProjectForge/Actions.hs view
@@ -2,22 +2,27 @@ Functions for creating project initialization applications -} -{-# LANGUAGE OverloadedStrings #-} module ProjectForge.Actions ( createProjectTemplateAction , defaultTemplateActionOpts+ , TemplateLocation(..)+ , TemplateActionOpts(..) ) where -import Blammo.Logging.Simple-import Control.Monad.IO.Class-import Data.Aeson-import Data.Text.Lazy as TL-import qualified Data.Text.Lazy.IO as TL-import ProjectForge.Get+import Blammo.Logging.Simple (MonadLogger)+import Control.Monad.IO.Class (MonadIO)+import Data.Aeson (ToJSON (toJSON))+import ProjectForge.Get (getProjectTemplateFromDir,+ getProjectTemplateFromGit)+import ProjectForge.Get.Git (GitURL) import ProjectForge.Render-import System.Directory-import System.FilePath +-- | Location of template directory+data TemplateLocation =+ Local FilePath+ | Git GitURL+ deriving (Eq, Show)+ {-| Options for compiling, rendering and writing a a @'ProjectTemplate'@. -}@@ -35,28 +40,19 @@ -} createProjectTemplateAction :: (MonadLogger m, MonadIO m, ToJSON a) => TemplateActionOpts- -> FilePath -- ^ name of directory containing project template+ -> TemplateLocation -> a -- ^ type which when converted via @'Data.Aeson.toJSON'@ contains values -- to interpolate into the @'ProjectTemplate'@. -> m ()-createProjectTemplateAction opts d settings = do- let template = getProjectTemplateFromDir d+createProjectTemplateAction opts loc settings = do+ let template = case loc of+ Local dir -> getProjectTemplateFromDir dir+ Git url -> getProjectTemplateFromGit Nothing url Nothing values = toJSON settings results <- (\x -> renderProjectTemplate (renderOpts opts) x values) =<< template writeTemplateResult results -{--Utility for writing the results for @'renderProjectTemplate'@ to files.--}-writeTemplateResult :: (MonadLogger m, MonadIO m) => [(FilePath, TL.Text)] -> m ()-writeTemplateResult =- mapM_ (\(fn, cnts) -> do- liftIO $ createDirectoryIfMissing True (takeDirectory fn)-- logDebug $ "Writing template result to file" :# [ "path" .= fn ]- liftIO $ TL.writeFile fn cnts- )
src/ProjectForge/Get.hs view
@@ -51,7 +51,7 @@ Converts a list of @FilePath@ and @ByteString@ pairs to a @'ProjectTemplate'@. The @ByteString@ are decoded into @'Data.Text.Text'@ by-@'Data.Text.Encoding.decodeUtf8'@. +@'Data.Text.Encoding.decodeUtf8'@. If decoding results in a @Data.Text.Encoding.Error.UnicodeException@ for any value, then this is thrown as an exception.@@ -71,7 +71,7 @@ Right v -> pure v {-|-Convert a file to a @'FileTemplate'@. +Convert a file to a @'FileTemplate'@. A @GetProjectTemplateError@ exception is thrown if the input file does not exist. @@ -94,7 +94,7 @@ {-|-Convert a directory to a @'ProjectTemplate'@. +Convert a directory to a @'ProjectTemplate'@. A @GetProjectTemplateError@ exception is thrown if the input directory does not exist.
src/ProjectForge/Render.hs view
@@ -10,6 +10,7 @@ -- * Rendering templates renderFileTemplate , renderProjectTemplate+ , writeTemplateResult -- ** Rendering Options and Exception Handling , RenderTemplateOpts(..)@@ -29,7 +30,9 @@ import Data.Text import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TL+import qualified Data.Text.Lazy.IO as TL import ProjectForge.ProjectTemplate+import System.Directory import System.FilePath import Text.Mustache.Render import Text.Mustache.Type@@ -128,3 +131,16 @@ renderProjectTemplate opts (MkProjectTemplate t) v = traverse (`f` v) (Set.toList t) where f = renderFileTemplate opts+++{-|+Utility for writing the results for @'renderProjectTemplate'@ to files.+-}+writeTemplateResult :: (MonadLogger m, MonadIO m) => [(FilePath, TL.Text)] -> m ()+writeTemplateResult =+ mapM_ (\(fn, cnts) -> do+ liftIO $ createDirectoryIfMissing True (takeDirectory fn)++ logDebug $ "Writing template result to file" :# [ "path" .= fn ]+ liftIO $ TL.writeFile fn cnts+ )