Skip to content
Browse files

Added links to full pastes

  • Loading branch information...
1 parent 28727d3 commit 23c9baf5c0e4d57e7c270dafb6ec04e0740b6055 @Palmik committed Apr 14, 2011
Showing with 44 additions and 10 deletions.
  1. +19 −0 log/access.log
  2. +8 −0 log/error.log
  3. +1 −1 pastie.cabal
  4. +1 −1 resources/templates/full-paste.tpl
  5. +7 −4 src/Controller/Paste.hs
  6. +5 −2 src/Model/Paste.hs
  7. +3 −2 src/Site.hs
View
19 log/access.log
@@ -621,3 +621,22 @@
127.0.0.1 - - [11/Apr/2011:16:45:42 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
127.0.0.1 - - [11/Apr/2011:16:45:52 +0200] "GET / HTTP/1.1" 200 - "http://0.0.0.0:8000/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
127.0.0.1 - - [11/Apr/2011:16:45:52 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:16:51:52 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:16:51:52 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:16:51:55 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:16:51:55 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:19:03:01 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:19:03:01 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:19:03:52 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [11/Apr/2011:19:03:52 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:14 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:14 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:16 +0200] "GET /paste/4da31414-900faa17c6000000 HTTP/1.1" 200 - "http://0.0.0.0:8000/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:16 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:18 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:20 +0200] "GET /paste/4d8f4d3a-900faa26f7000000 HTTP/1.1" 200 - "http://0.0.0.0:8000/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:20 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:22 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:24 +0200] "GET /paste/4d8f290c-900faa2121000000 HTTP/1.1" 200 - "http://0.0.0.0:8000/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:24 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
+127.0.0.1 - - [14/Apr/2011:09:49:26 +0200] "GET /favicon.ico HTTP/1.1" 404 3 - "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
View
8 log/error.log
@@ -209,3 +209,11 @@
[11/Apr/2011:16:45:28 +0200] Server.httpServe: SHUTDOWN
[11/Apr/2011:16:45:28 +0200] Server.httpServe: BACKEND STOPPED
[11/Apr/2011:16:45:30 +0200] Server.httpServe: START (EventLoopSimple)
+[11/Apr/2011:16:51:44 +0200] Server.httpServe: SHUTDOWN
+[11/Apr/2011:16:51:44 +0200] Server.httpServe: BACKEND STOPPED
+[11/Apr/2011:16:51:45 +0200] Server.httpServe: START (EventLoopSimple)
+[11/Apr/2011:19:35:23 +0200] Server.httpServe: SHUTDOWN
+[11/Apr/2011:19:35:23 +0200] Server.httpServe: BACKEND STOPPED
+[14/Apr/2011:09:49:09 +0200] Server.httpServe: START (EventLoopSimple)
+[14/Apr/2011:20:15:12 +0200] Server.httpServe: SHUTDOWN
+[14/Apr/2011:20:15:12 +0200] Server.httpServe: BACKEND STOPPED
View
2 pastie.cabal
@@ -30,7 +30,7 @@ Executable pastie
text >= 0.11 && < 0.12,
time >= 1.1 && < 1.3,
xmlhtml == 0.1.*,
- snap-extension-mongodb,
+ snap-extension-mongodb >= 0.3.3,
bson,
compact-string-fix,
digestive-functors,
View
2 resources/templates/full-paste.tpl
@@ -1,5 +1,5 @@
<div class="full-paste">
- <h3><title/></h3>
+ <a href="/paste/$(paste-id)"><h3><title/></h3></a>
<pre class="$(language)">
<code>
<source-code/>
View
11 src/Controller/Paste.hs
@@ -11,12 +11,12 @@ module Controller.Paste
import qualified Data.Text as T
import Data.Text (Text)
+import Data.Maybe
import qualified Data.Text.Encoding as T (decodeUtf8)
import qualified Text.XmlHtml as X
import Control.Monad.Trans
import Control.Monad (mzero)
import qualified Data.ByteString.Char8 as BS (unpack)
-import Debug.Trace (trace)
import Snap.Types
import Text.Digestive.Forms.Snap
@@ -41,15 +41,18 @@ pasteParts :: Paste -> [(Text, Text)]
pasteParts p = map applyAndPack [ ("title", pasteTitle)
, ("source-code", pasteCode)
, ("description", pasteDescription)
- , ("language", pasteLanguage) ]
+ , ("language", pasteLanguage)
+ , ("paste-id", pasteLink) ]
where applyAndPack (x, f) = (x, f p)
+ pasteLink p = maybe "#" id $ pasteIDText p
+
singlePasteSplice :: Maybe ObjectId -> Splice Application
-singlePasteSplice Nothing = (return . (:[]) . X.TextNode) "404"
+singlePasteSplice Nothing = textSplice "There is no such paste."
singlePasteSplice (Just pid) = do
mp <- lift $ getPaste pid
case mp of
- Nothing -> (return . (:[]) . X.TextNode) "404"
+ Nothing -> textSplice "There is no such paste"
Just p -> runChildrenWithText $ pasteParts p
View
7 src/Model/Paste.hs
@@ -10,16 +10,16 @@ module Model.Paste
, getPaste
, pastesTable
, insertPaste
-
+, pasteIDText
, ObjectId
) where
import Data.Either
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.Text as T
+import qualified Data.Text.Encoding as T (decodeUtf8)
import Data.Text (Text)
-import Debug.Trace
import Snap.Extension.DB.MongoDB
import Snap.Extension.DB.MongoDB.Generics
@@ -48,6 +48,9 @@ getRecentPastes = do
res <- withDB $ rest =<< (find (select [] "pastes") {sort = ["$natural" =: (-1 :: Int)]})
return $ either (const []) (fromDocList) res
+pasteIDText :: Paste -> Maybe Text
+pasteIDText p = maybe Nothing (Just . T.decodeUtf8 . objid2bs) (unRK $ pasteID p)
+
getPaste :: ObjectId -> Application (Maybe Paste)
getPaste pid = do
res <- withDB $ findOne (select ["_id" =: pid] "pastes")
View
5 src/Site.hs
@@ -54,7 +54,8 @@ paste = do
-- | The main entry point handler.
site :: Application ()
site = route [ ("/paste/:oid", paste)
- , ("/", methods [GET, HEAD] pastes)
- , ("/", method POST addPasteHandler)
+ , ("/pastes", pastes)
+ , ("/", method POST addPasteHandler)
+ , ("/", methods [GET, HEAD] index)
]
<|> serveDirectory "resources/static"

0 comments on commit 23c9baf

Please sign in to comment.
Something went wrong with that request. Please try again.