dixi 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+38/−17 lines, 5 filesdep +timedep +time-locale-compat
Dependencies added: time, time-locale-compat
Files
- Dixi/Database.hs +11/−10
- Dixi/Markup.hs +17/−1
- Dixi/Page.hs +4/−3
- Main.hs +3/−2
- dixi.cabal +3/−1
Dixi/Database.hs view
@@ -23,6 +23,7 @@ import Data.Patch (Patch) import Data.SafeCopy hiding (Version) import Data.Text (Text)+import Data.Time import Data.Typeable import qualified Data.Compositions.Snoc as C@@ -65,30 +66,30 @@ let y = patchToVector (C.composed (C.take v1 b) ^. body) return $ fmap (\z -> P.hunks z y) (C.dropComposed v1 (C.take v2 b)) -amendPatch :: Key -> Version -> Patch Char -> Maybe Text -> Update Database (Version)-amendPatch k v q com = do+amendPatch :: Key -> Version -> Patch Char -> Maybe Text -> UTCTime -> Update Database (Version)+amendPatch k v q com tim = do (db . at k) %= \mb -> let b = fromMaybe mempty mb p = C.dropComposed v b ^. body r = snd $ P.transformWith P.theirs p q- in Just (C.snoc b (Page r (Last com)))+ in Just (C.snoc b (Page r (Last com) (Last $ Just tim))) C.length <$> use (db . ix k) -amend :: Key -> Version -> Text -> Maybe Text -> Update Database (Version)-amend k v new com = do+amend :: Key -> Version -> Text -> Maybe Text -> UTCTime -> Update Database (Version)+amend k v new com tim = do b <- use (db . ix k) let n = V.fromList (T.unpack new) o = C.composed (C.take v b) ^. body . to patchToVector q = P.diff o n- amendPatch k v q com+ amendPatch k v q com tim -revert :: Key -> (Version, Version) -> Maybe Text -> Update Database Version-revert k (v1,v2) com | v2 < v1 = revert k (v2, v1) com-revert k (v1,v2) com = do+revert :: Key -> (Version, Version) -> Maybe Text -> UTCTime -> Update Database Version+revert k (v1,v2) com tim | v2 < v1 = revert k (v2, v1) com tim+revert k (v1,v2) com tim = do b <- use (db . ix k) let p = C.dropComposed v1 (C.take v2 b) ^. body- amendPatch k (max v1 v2) (P.inverse p) com+ amendPatch k (max v1 v2) (P.inverse p) com tim makeAcidic ''Database ['getLatest, 'getVersion, 'getHistory, 'getDiff, 'amend, 'revert]
Dixi/Markup.hs view
@@ -16,9 +16,11 @@ import Data.Monoid import Data.Patch (Hunks, HunkStatus(..)) import Data.Proxy+import Data.Time import Data.Text (Text) import Servant.API import Servant.HTML.Blaze+import Data.Time.Locale.Compat import Text.Blaze import Text.Cassius import Text.Hamlet (shamlet, Html)@@ -36,6 +38,10 @@ link :: (IsElem endpoint Dixi, HasLink endpoint) => Proxy endpoint -> MkLink endpoint link = safeLink dixi +renderTime :: Last UTCTime -> String+renderTime (Last Nothing) = "(never)"+renderTime (Last (Just t)) = formatTime defaultTimeLocale "%T, %F (%Z)" t+ renderTitle :: Text -> Text renderTitle = T.pack . map (\c -> if c == '_' then ' ' else c) . T.unpack @@ -154,7 +160,12 @@ text-decoration: line-through; .hunk-replaced background: #F3E686-+ .timestamp+ color: #444444+ font-size: small+ div.timestamp+ margin-left: 0.5em+ margin-top: 2em |] undefined outerMatter :: Text -> Html -> Html@@ -233,6 +244,7 @@ <th .histh-fromto> From/To <th .histh-changes> Changes <th .histh-comment> Comment+ <th .histh-comment> Time $forall (v, p) <- ps' <tr> <td .hist-version>@@ -244,6 +256,8 @@ #{(p ^. body)} <td> <a .histlink href="/#{link prettyUrl k v}">#{guardText "no comment" (unlast "no comment" (p ^. comment))}+ <td>+ <span .timestamp>#{renderTime (p ^. time)} <tr> <td> <tr>@@ -286,6 +300,7 @@ toMarkup (PP k v p) = let com = p ^. comment . traverse+ tim = renderTime $ p ^. time bod = case readOrg def (filter (/= '\r') . T.unpack $ p ^. body) of Left err -> [shamlet|#{err}|] Right pd -> writeHtml def pd@@ -294,6 +309,7 @@ #{versionHeader k v com} <div .body> #{bod}+ <div .timestamp> This version was last edited at #{tim} |] instance ToMarkup RawPage where
Dixi/Page.hs view
@@ -10,10 +10,11 @@ import Data.Monoid import Data.SafeCopy import Data.Text+import Data.Time import Dixi.Database.Orphans () -data Page b = Page { _body :: b, _comment :: Last Text }+data Page b = Page { _body :: b, _comment :: Last Text, _time :: Last UTCTime } deriving (Functor, Data, Typeable, Show) deriveSafeCopy 0 'base ''Page@@ -21,5 +22,5 @@ makeLenses ''Page instance Monoid b => Monoid (Page b) where- mempty = Page mempty mempty- mappend (Page a a') (Page b b') = Page (a <> b) (a' <> b')+ mempty = Page mempty mempty mempty+ mappend (Page a a' a'') (Page b b' b'') = Page (a <> b) (a' <> b') (a'' <> b'')
Main.hs view
@@ -14,6 +14,7 @@ import Control.Monad.IO.Class import Control.Monad.Trans.Either import Data.Acid+import Data.Time import Data.Text (Text) import Network.Wai.Handler.Warp import Servant@@ -52,11 +53,11 @@ |: reversion reversion (DR v1 v2 com) = do- _ <- liftIO $ update db $ Revert key (v1, v2) com+ _ <- liftIO (getCurrentTime >>= update db . Revert key (v1, v2) com) latestQ PP version v = (versionQ PP v |: versionQ RP v) |: updateVersion v- updateVersion v (NB t c) = do _ <- liftIO $ update db $ Amend key v t c+ updateVersion v (NB t c) = do _ <- liftIO $ (getCurrentTime >>= update db . Amend key v t c) latestQ PP latestQ :: (Key -> Version -> Page Text -> a) -> EitherT ServantErr IO a
dixi.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: dixi-version: 0.1.0.0+version: 0.2.0.0 synopsis: A wiki implemented with a firm theoretical foundation. description: This project is a simple wiki developed based on a firm theoretical foundation.@@ -65,6 +65,8 @@ , yaml >= 0.8 && < 0.9 , aeson >= 0.8 && < 0.11 , directory >= 1.0 && < 1.3+ , time >= 1.4 && < 1.6+ , time-locale-compat >= 0.1 && < 0.2 -- hs-source-dirs: default-language: Haskell2010