packages feed

headergen 0.1.1.1 → 0.2.0.0

raw patch · 10 files changed

+172/−67 lines, 10 files

Files

+ README.md view
@@ -0,0 +1,27 @@+# headergen+An application written in Haskell for generating headers for Haskell source files.++# Usage++Usage: headergen {help [all|COMMAND]|init|create LANGUAGE TEMPLATE MODULE}++  headergen create LANGUAGE TEMPLATE MODULE </br>+    * creates a new module in current working directory. </br>+  headergen init </br>+    * initializes a new .headergen.def. </br>+  headergen help </br>+    * shows this help information </br>+  headergen help COMMAND </br>+    * shows detailed help information++# Supported Languages++As for now only Haskell is supported. It is planned to implement support for more languages in future releases.++# TODO+* Extract help message interface from command module level to avoid mutual recursion over module level.+* Implement reading of cabal files instead of using own setting files.+* Implement a parser for updating existing source files.+* Implement reading of file associations from file.+* Implement support for more languages.+
+ changelog.md view
@@ -0,0 +1,22 @@+# 0.2.0.0+* Implemented templating engine.+* Added two basic templates.++# 0.1.1.1+* Fixed a bug in the build scripts causing build of 0.1.1.0 to fail.++# 0.1.1.0+* Refactored all of the code and extracted major portions to own modules.+* Implemented command "help" for detailed help information.++# 0.1.0.0+* Implemented creation of a .headergen.def+* Implemented creation of new files via .headergen.def++## Disclaimer+This is a mere prototype providing basic functionalities. It's only use is to+provide it's functionality for further development of headergen. You can use it+but it won't be very pleasing to use as it's feature of automatic updating+headers in existing files is not implementet yet. Also the sources are very+unstructured and not splitted over several modules.+
headergen.cabal view
@@ -1,9 +1,12 @@ name:                 headergen-version:              0.1.1.1+version:              0.2.0.0 homepage:             https://github.com/aka-bash0r/headergen synopsis:             Creates a header for a haskell source file.-description:          The headergen package provides a small utility for-                      creating documentation headers for source files.+description:          The headergen application can generate+                      source file headers with default values+                      configured for a specific project. It+                      features a full templating engine under the+                      hood and can be highly customized. license:              MIT license-file:         LICENSE author:               Nils 'bash0r' Jonsson@@ -11,7 +14,13 @@ copyright:            (c) 2015 Nils 'bash0r' Jonsson category:             Development build-type:           Simple-data-dir:             share+data-files:           share/haskell/simple.template+          ,           share/haskell/main.template+extra-source-files:   LICENSE+                  ,   README.md+                  ,   changelog.md+                  ,   share/haskell/simple.template+                  ,   share/haskell/main.template cabal-version:        >=1.10  source-repository head@@ -21,7 +30,7 @@ source-repository this   type:               git   location:           https://github.com/aka-bash0r/headergen-  tag:                0.1.1.1+  tag:                0.2.0.0   executable headergen@@ -34,6 +43,7 @@                ,      Headergen.Template.Parser                ,      Headergen.Template                ,      Headergen.Utility+               ,      Paths_headergen   build-depends:      base         >=4.8     && <4.9                ,      aeson        >=0.9.0.1 && <0.10                ,      aeson-pretty >=0.7.2   && <0.8
+ share/haskell/main.template view
@@ -0,0 +1,21 @@+{- |+Module      :  $module+Description :  Entrypoint of the application.+Author      :  $author+Copyright   :  $copyright+License     :  $license++Maintainer  :  $maintainer+Stability   :  $stability+Portability :  $portability++The 'Main' module is the entrypoint of the application.+-}+module Main+( main+) where+++main :: IO ()+main = return ()+
+ share/haskell/simple.template view
@@ -0,0 +1,18 @@+{- |+Module      :  $module+Description :  $description+Author      :  $author+Copyright   :  $copyright+License     :  $license++Maintainer  :  $maintainer+Stability   :  $stability+Portability :  $portability++TODO: document module+-}+module $module.name+(+) where++
src/Headergen/Commands/Creation.hs view
@@ -16,6 +16,9 @@ , help ) where +import Control.Applicative+import Control.Monad+ import Data.Aeson import qualified Data.ByteString.Lazy as BS @@ -24,57 +27,82 @@ import System.IO  import Headergen.Configuration-import Headergen.Messages+import Headergen.Template+import Headergen.Template.Parser import Headergen.Utility (requestForAllowance, parentDirectory) +import Paths_headergen + command :: [String] -> IO ()-command [mod] = tryCreate (mod -<.> ".hs")-command _     = undefined -- TODO: implement help message+command [lang, temp, mod] = case findMapping lang of+  Just mapping -> do+    cwd <- getCurrentDirectory+    hdg <- headergenDef cwd+    template lang temp >>= \t -> case t of+      Right temp -> do+        h <- openFile temp ReadMode+        c <- hGetContents h+        let templ  = parseTemplate c+            dict   = ("module.name", mod)+                   : createDictionary hdg+            filled = fillTemplate dict templ+        case filled of+          Right text -> do+            m <- openFile (mod -<.> mapping) WriteMode+            hPutStrLn m text+            hClose m+          Left  err  -> do+            putStrLn err+            putStrLn ""+        hClose h+      Left err   -> do+        putStrLn err+        putStrLn ""+  Nothing      -> do+    putStrLn ("Language " ++ lang ++ " is unsupported.")+    putStrLn ""+command _     = help  help :: IO () help = do-  putStrLn "  headergen create MODULE"+  putStrLn "  headergen create LANGUAGE TEMPLATE MODULE"   putStrLn "    --> creates a new module in current working directory." --- | Try to create a new module file.-tryCreate mod = do-  cwd <- getCurrentDirectory-  traversePath mod cwd+template :: String -> String -> IO (Either String FilePath)+template lang temp = do+  template <- getDataFileName ("share" </> lang </> (temp -<.> ".template"))+  exists <- doesFileExist template+  if exists+     then (return . return) template+     else fail "Template does not exist." --- | Traverses the path up to root directory.-traversePath mod cwd = do-  putStrLn ("Checking " ++ cwd ++ " ...")-  let headerGenDef = cwd </> ".headergen.def"-  exists <- doesFileExist headerGenDef+-- | Get the filetype extension of supported languages.+findMapping lang = findMapping' lang fileMapping+  where+    findMapping' _    []         = Nothing+    findMapping' lang (x:xs) =+      let (l, f) = x+       in if l == lang+             then return f+             else findMapping' lang xs+    -- | A language / filetype mapping.+    fileMapping =+      [ ("haskell", "hs") ]++-- | Try to get the .headergen.def.+headergenDef cwd = do+  let file = cwd </> ".headergen.def"+  exists <- doesFileExist file   if exists      then do-       h  <- openFile headerGenDef ReadMode+       h <- openFile file ReadMode        cs <- BS.hGetContents h-       let hgd = decode cs :: Maybe Configuration +       let hgd = decode cs :: Maybe Configuration        case hgd of-         Just a  -> createHeader mod a-         Nothing -> putStrLn corruptedMessage-       hClose h +         Just a  -> return a+         Nothing -> empty      else case parentDirectory cwd of-       Just a  -> traversePath mod a-       Nothing -> putStrLn noHeadergenDefMessage---- | Create the header.-createHeader mod conf = do-  exists <- doesFileExist mod-  if exists-     then do-       v <- requestForAllowance-       if v-          then writeHeader mod conf-          else putStrLn noResourcesCreatedMessage-     else writeHeader mod conf---- | Write the header to file.-writeHeader modFile conf = do-  h <- openFile modFile WriteMode-  hPutStr h (template conf) -  hFlush h-  hClose h+            Just a  -> headergenDef a+            Nothing -> empty 
src/Headergen/Commands/Help.hs view
@@ -39,7 +39,7 @@   command []   help command _          = do-  putStrLn "Usage: headergen {help [all|COMMAND]|init|create MODULE}"+  putStrLn "Usage: headergen {help [all|COMMAND]|init|create LANGUAGE TEMPLATE MODULE}"   putStrLn ""  help :: IO ()
src/Headergen/Commands/Initialization.hs view
@@ -37,7 +37,7 @@  command :: [String] -> IO () command [] = initializeDefinition-command _  = undefined -- TODO: implement printing of help message.+command _  = help   help :: IO ()
src/Headergen/Configuration.hs view
@@ -38,6 +38,7 @@   , getStability   :: String   , getPortability :: String   }+  deriving (Show, Eq)  instance ToJSON Configuration where   toJSON (Configuration mod desc auth copyr lic maint stab portab) =
src/Headergen/Messages.hs view
@@ -11,7 +11,6 @@  This module defines some messages  -}- module Headergen.Messages ( corruptedMessage , noResourcesCreatedMessage@@ -26,12 +25,9 @@ , maintainerMessage , stabilityMessage , portabilityMessage--, template ) where  -import Headergen.Configuration import Headergen.Utility  @@ -90,22 +86,4 @@ -- | A message stating that input for portability definition is required. portabilityMessage   :: String portabilityMessage   = "Portability [non-port]: "----- | A template function creating a new header from a configuration.-template :: Configuration -> String-template (Configuration mod des aut cop lic mai sta por) =-  "{- |\n" ++-  "Module      :  " ++ mod ++ "\n" ++-  "Description :  " ++ des ++ "\n" ++-  "Author      :  " ++ aut ++ "\n" ++-  "Copyright   :  " ++ cop ++ "\n" ++-  "License     :  " ++ lic ++ "\n" ++-  "\n" ++-  "Maintainer  :  " ++ mai ++ "\n" ++-  "Stability   :  " ++ sta ++ "\n" ++-  "Portability :  " ++ por ++ "\n" ++-  "\n" ++-  "TODO: module description\n" ++-  "-}\n\n"