packages feed

themplate 1.1 → 1.2

raw patch · 4 files changed

+25/−20 lines, 4 filesdep +transformers-compatdep ~errorsdep ~optparse-applicativedep ~transformers

Dependencies added: transformers-compat

Dependency ranges changed: errors, optparse-applicative, transformers

Files

.travis.yml view
@@ -1,17 +1,20 @@-# The following enables several GHC versions to be tested; often it's enough to test only against the last release in a major GHC version. Feel free to omit lines listings versions you don't need/want testing for. env:  - GHCVER=7.4.2 CABALVER=1.16  - GHCVER=7.6.3 CABALVER=1.18- - GHCVER=head CABALVER=1.18 # see section about GHC HEAD snapshots+ - GHCVER=7.8.3 CABALVER=1.20+ - GHCVER=7.8.4 CABALVER=1.22+ - GHCVER=7.10.1 CABALVER=1.22+ - GHCVER=head   CABALVER=1.22  before_install:  - sudo add-apt-repository -y ppa:hvr/ghc  - sudo apt-get update- - sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER happy hlint- - export PATH=/opt/ghc/$GHCVER/bin:$PATH+ - sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER hlint+ - cabal-$CABALVER update+ - cabal-$CABALVER install happy -j+ - export PATH=/opt/ghc/$GHCVER/bin:~/.cabal/bin:$PATH  install:- - cabal-$CABALVER update  - cabal-$CABALVER install --only-dependencies --enable-tests --enable-benchmarks -j  script:@@ -20,5 +23,5 @@  matrix:   allow_failures:-   - env: GHCVER=head CABALVER=1.18+   - env: GHCVER=head CABALVER=1.22   fast_finish: true
src/Main.hs view
@@ -25,8 +25,8 @@ -- | Command line argument parser for the 'init' subcommand. The init command can be used to instantiate templates. initCmd :: ParserInfo Cmd initCmd = info (helper <*> parser) (fullDesc <> progDesc "Use an installed template.")-  where nameOpt = argument Just (metavar "NAME" <> help "The project name")-        templatesOpt = argument Just (metavar "TEMPLATE" <> help "Name of the template which to use for this project")+  where nameOpt = strArgument (metavar "NAME" <> help "The project name")+        templatesOpt = strArgument (metavar "TEMPLATE" <> help "Name of the template which to use for this project")         amendOpt = switch (short 'a' <> long "amend" <> help "Don't fail when a file exists. Instead, ignore it and continue.")         parser = Init <$> nameOpt <*> templatesOpt <*> amendOpt @@ -59,7 +59,7 @@ -- | Instantiate a template, copying the files and resolving all conditionals and variables. -- The first argument is the project name, the second argument the directory of the template and the third argument is -- the target directory, to which the files get copied.-instantiateTemplate :: String -> Bool -> Config -> FilePath -> FilePath -> EitherT T.Text IO ()+instantiateTemplate :: String -> Bool -> Config -> FilePath -> FilePath -> ExceptT T.Text IO () instantiateTemplate proj amend c temp target = do   contents <- lift $ filter (not . flip elem [".",".."]) <$> getDirectoryContents temp   dirs <- lift $ filterM (doesDirectoryExist . (temp </>)) contents@@ -75,7 +75,7 @@     file' <- fmap T.unpack $ substitute $ T.pack file      e <- lift $ doesFileExist (target </> file')-    when (e && not amend) $ left $ ":Error: Target file " <> T.pack (target </> file') <> " does already exist."+    when (e && not amend) $ throwE $ ":Error: Target file " <> T.pack (target </> file') <> " does already exist."     unless e $ lift $ do       T.writeFile (target </> file') content'       perm <- getPermissions (temp </> file)@@ -109,7 +109,7 @@   targetExists <- doesDirectoryExist proj   unless targetExists $ createDirectory proj   projPath <- canonicalizePath proj-  res <- runEitherT (instantiateTemplate proj amend c (appData </> temp) projPath) `E.catch` \(exc :: E.SomeException) ->+  res <- runExceptT (instantiateTemplate proj amend c (appData </> temp) projPath) `E.catch` \(exc :: E.SomeException) ->     unless targetExists (removeDirectoryRecursive projPath) >> E.throwIO exc   case res of     Left m -> do
src/Pattern.hs view
@@ -3,11 +3,12 @@  import           Control.Applicative import           Control.Monad.Trans.Class-import           Control.Monad.Trans.Either+import           Control.Monad.Trans.Except import           Control.Monad.Trans.Maybe import           Data.Maybe import           Data.Monoid import qualified Data.Text as T+import           Prelude  -- | Apply a function to replace the text between a given start and end tag. -- Example:@@ -27,7 +28,7 @@ -- --   - $$a$$ will be replaced with @f a@, returning Left a if @f@ returns Nothing --   - ??a?? will be replaced with @f a@, returning an empty string if @f@ returns Nothing-evalPattern :: Monad f => (T.Text -> f (Maybe T.Text)) -> T.Text -> EitherT T.Text f T.Text+evalPattern :: (Applicative f, Monad f) => (T.Text -> f (Maybe T.Text)) -> T.Text -> ExceptT T.Text f T.Text evalPattern f t = replaceRequiredVar . fromMaybe T.empty =<< runMaybeT (replaceOptionalVar t)-  where replaceRequiredVar = substituteBetween "$$" "$$" (\x -> maybe (left x) return =<< lift (f x))+  where replaceRequiredVar = substituteBetween "$$" "$$" (\x -> maybe (throwE x) return =<< lift (f x))         replaceOptionalVar = substituteBetween "??" "??" (MaybeT . lift . f)
themplate.cabal view
@@ -1,5 +1,5 @@ name:          themplate-version:       1.1+version:       1.2 license:       BSD3 cabal-version: >= 1.10 license-file:  LICENSE@@ -9,8 +9,8 @@ homepage:      http://github.com/bennofs/themplate/ bug-reports:   http://github.com/bennofs/themplate/issues copyright:     Copyright (C) 2013-2014 Benno Fünfstück-synopsis:      themplate-description:   themplate+synopsis:      Project templating tool+description:   Themplate is a tool to generate projects from templates. The templating language is described at https://github.com/bennofs/themplate. build-type:    Simple category:      Application, Console, Development, Template @@ -36,8 +36,9 @@     , filepath     , directory     , text-    , transformers+    , transformers >= 0.2+    , transformers-compat >= 0.3     , either-    , optparse-applicative+    , optparse-applicative >= 0.10     , configurator-    , errors+    , errors >= 2