packages feed

hi 0.0.8.1 → 0.0.8.2

raw patch · 7 files changed

+76/−34 lines, 7 filesdep +doctestdep ~basedep ~temporary-rcPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: doctest

Dependency ranges changed: base, temporary-rc

API changes (from Hackage documentation)

+ Hi.Template: isTemplate :: FilePath -> Bool
+ Hi.Types: RegularFile :: FilePath -> ByteString -> File
+ Hi.Types: TemplateFile :: FilePath -> ByteString -> File
+ Hi.Types: data File
+ Hi.Types: getFileContents :: File -> ByteString
+ Hi.Types: getFilePath :: File -> FilePath
- Hi.Types: type Files = [(FilePath, String)]
+ Hi.Types: type Files = [File]

Files

hi.cabal view
@@ -1,5 +1,5 @@ name:                hi-version:             0.0.8.1+version:             0.0.8.2 synopsis:            Generate scaffold for cabal project license:             BSD3 license-file:        LICENSE@@ -66,16 +66,16 @@   hs-source-dirs:       src   build-depends:-        base       == 4.*+        base          == 4.*       , bytestring       , directory       , filepath       , parsec       , process       , split-      , template   == 0.2.*-      , temporary-rc  == 1.2.0.3-      , text       > 1.0+      , template      == 0.2.*+      , temporary-rc  >= 1.2.0.3+      , text          > 1.0       , time  executable hi@@ -113,6 +113,7 @@       , HUnit       , bytestring       , directory+      , doctest       , filepath       , hspec       >= 1.7.2       , parsec@@ -122,6 +123,19 @@       , temporary-rc   == 1.2.0.3       , text       > 1.0       , time++test-suite doctests+  type:+      exitcode-stdio-1.0+  ghc-options:+      -threaded+  hs-source-dirs:+      src+    , test+  main-is:+      doctests.hs+  build-depends:+      base, doctest >= 0.8, process  source-repository head   type:     git
src/Hi.hs view
@@ -4,23 +4,25 @@   , process   ) where -import           Hi.Directory        (inDirectory)-import           Hi.FilePath         (rewritePath)-import qualified Hi.Git              as Git-import           Hi.Template         (readTemplates)+import           Hi.Directory             (inDirectory)+import           Hi.FilePath              (rewritePath)+import qualified Hi.Git                   as Git+import           Hi.Template              (readTemplates) import           Hi.Types import           Hi.Utils  import           Control.Applicative import           Control.Monad-import           Data.List           (isSuffixOf)-import           Data.Maybe          (fromJust)-import qualified Data.Text           as T-import qualified Data.Text.Lazy      as LT-import           Data.Text.Template  (Context, substitute)-import           System.Directory    (createDirectoryIfMissing)-import           System.FilePath     (dropFileName)-import           System.Process      (system)+import qualified Data.ByteString          as BS (writeFile, concat)+import qualified Data.ByteString.Lazy     as LBS (toChunks)+import           Data.Maybe               (fromJust)+import qualified Data.Text                as T (pack, unpack)+import           Data.Text.Encoding       (decodeUtf8)+import           Data.Text.Lazy.Encoding  (encodeUtf8)+import           Data.Text.Template       (Context, substitute)+import           System.Directory         (createDirectoryIfMissing)+import           System.FilePath          (dropFileName)+import           System.Process           (system)  -- | Run 'hi'. run :: [Option] -> IO ()@@ -33,15 +35,18 @@  -- |Write given 'Files' to filesystem. writeFiles :: Files -> IO ()-writeFiles = mapM_ (uncurry write)-  where-    write :: FilePath -> String -> IO ()-    write path content = createDirectoryIfMissing True (dropFileName path) >> writeFile path content+writeFiles = mapM_ write +write :: File -> IO ()+write f = let path = getFilePath f+              contents = getFileContents f+          in createDirectoryIfMissing True (dropFileName path) >>+               BS.writeFile path contents+ -- | Show 'Files' to stdout. showFileList :: Files -> IO Files showFileList files = do-    mapM_ (showFile . fst) files+    mapM_ (showFile . getFilePath) files     return files   where     showFile :: FilePath -> IO ()@@ -57,11 +62,11 @@ process :: [Option] -> Files -> Files process options = map go   where-    go (path, content) = if ".template" `isSuffixOf` path-                           then (rewritePath' path, substitute' content)-                           else (rewritePath' path, content)+    go (TemplateFile path content) = TemplateFile (rewritePath' path) (substitute' content)+    go (RegularFile  path content) = RegularFile  (rewritePath' path) content     rewritePath'     = rewritePath options-    substitute' text = LT.unpack $ substitute (T.pack text) (context options)+    substitute' text = BS.concat . LBS.toChunks . encodeUtf8 $+                        substitute (decodeUtf8 text) (context options)  -- | Return 'Context' obtained by given 'Options' context :: [Option] -> Context
src/Hi/Git.hs view
@@ -5,9 +5,6 @@     , expandUrl     ) where -import           Hi.Types-import           Hi.Utils- import           Control.Applicative import           Data.List           (isPrefixOf) import           System.Exit         (ExitCode)
src/Hi/Template.hs view
@@ -1,6 +1,7 @@ module Hi.Template     (-      readTemplates+      isTemplate+    , readTemplates     , untemplate     ) where @@ -8,6 +9,10 @@ import qualified Hi.Git              as Git import           Hi.Types +import           Control.Applicative ((<$>))++import qualified Data.ByteString     as BS (readFile)+import           Data.List           (isSuffixOf) import           Data.List.Split     (splitOn)  -- | Read templates in given 'FilePath'@@ -17,8 +22,19 @@         -- TODO Handle error         _ <- Git.clone $ Git.expandUrl repo         paths <- Git.lsFiles-        contents <- mapM readFile paths-        return $ zip paths contents+        mapM fetchFile paths++fetchFile :: FilePath -> IO File+fetchFile fp | isTemplate fp = TemplateFile fp <$> BS.readFile fp+             | otherwise     = RegularFile  fp <$> BS.readFile fp++-- | Determine if a given filepath is a template file based on its extension+-- >>> isTemplate "Example.hs.template"+-- True+-- >>> isTemplate "NotATemplate.hs"+-- False+isTemplate :: FilePath -> Bool+isTemplate = isSuffixOf ".template"  -- | Remove \".template\" from 'FilePath' untemplate :: FilePath -> FilePath
src/Hi/Types.hs view
@@ -4,11 +4,16 @@     ( Label     , Option(..)     , Mode(..)+    , File(..)     , Files     , Error     ) where -type Files = [(FilePath, String)]+import Data.ByteString (ByteString)++data File = TemplateFile { getFilePath :: FilePath, getFileContents :: ByteString } | RegularFile { getFilePath :: FilePath, getFileContents :: ByteString }++type Files = [File]  type Error = String 
src/Hi/Version.hs view
@@ -4,4 +4,4 @@     ) where  version :: String-version = "0.0.8.1"+version = "0.0.8.2"
+ test/doctests.hs view
@@ -0,0 +1,5 @@+import           Control.Applicative+import           System.Process+import           Test.DocTest++main = doctest =<< lines <$> readProcess "git" ["ls-files", "src"] []