Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 26 lines (20 sloc) 0.766 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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.Maybe (fromMaybe)
import Data.DateTime
import Control.Monad

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 = "-- " ++ username ++ " (" ++ formatDateTime "%c" datetime ++ ")"
  liftM (sig ++ ) $ replacedate xs
replacedate (x:xs) = liftM (x : ) $ replacedate xs

Something went wrong with that request. Please try again.