Signature.hs 745 B

123456789101112131415161718192021222324
  1. module Signature (plugin) where
  2. -- This plugin replaces $SIG$ with the username and timestamp
  3. -- of the last edit, prior to saving the page in the repository.
  4. import Network.Gitit.Interface
  5. import Data.DateTime (getCurrentTime, formatDateTime)
  6. plugin :: Plugin
  7. plugin = PreCommitTransform replacedate
  8. replacedate :: String -> PluginM String
  9. replacedate [] = return ""
  10. replacedate ('$':'S':'I':'G':'$':xs) = do
  11. datetime <- liftIO getCurrentTime
  12. mbuser <- askUser
  13. let username = case mbuser of
  14. Nothing -> "???"
  15. Just u -> uUsername u
  16. let sig = concat ["-- ", username, " (", formatDateTime "%c" datetime, ")"]
  17. fmap (sig ++ ) $ replacedate xs
  18. replacedate (x:xs) = fmap (x : ) $ replacedate xs