File: Signature.hs

package info (click to toggle)
gitit 0.12.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,008 kB
  • sloc: haskell: 4,942; xml: 245; sh: 65; makefile: 16
file content (23 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Signature (plugin) where

-- This plugin replaces $SIG$ with the username and timestamp
-- of the last edit, prior to saving the page in the repository.

import Network.Gitit.Interface
import Data.DateTime (getCurrentTime, formatDateTime)

plugin :: Plugin
plugin = PreCommitTransform replacedate

replacedate :: String -> PluginM String
replacedate [] = return ""
replacedate ('$':'S':'I':'G':'$':xs) = do
  datetime <- liftIO getCurrentTime
  mbuser <- askUser
  let username = case mbuser of
                   Nothing  -> "???"
                   Just u   -> uUsername u
  let sig = concat ["-- ", username, " (", formatDateTime "%c" datetime, ")"]
  fmap (sig ++ ) $ replacedate xs
replacedate (x:xs) = fmap (x : ) $ replacedate xs