By | Chris Done;Chris Done |
At | 2011-08-07; 2011-08-07 |
Title | Added flo annotations. |
Description |
Edit file src/Main.hs 33188 → 33188
30 30 import Control.Concurrent.Chan (Chan)
31 31 import Data.Text.Lazy (Text)
32 32 import Database.PostgreSQL.Simple (Pool,newPool)
33 33 import System.Environment
34 34 + 35 -- @ label main
+ 36 -- @ do Main entry point.
+ 37 -- @ trigger readConfig
+ 38 -- @ trigger connectToIRC
+ 39 -- @ trigger createConnectionPool
+ 40 -- @ next server
35 41 -- | Main entry point.
36 42 main :: IO ()
37 43 main = do
38 44 cpath:_ <- getArgs
+ 45 -- @ label readConfig
+ 46 -- @ task Read config file.
39 47 config <- getConfig cpath
+ 48 -- @ label connectToIRC
+ 49 -- @ task Connect to IRC.
40 50 announces <- newAnnouncer (configAnnounce config)
+ 51 -- @ label createConnectionPool
+ 52 -- @ task Create connection pool.
41 53 pool <- newPool (configPostgres config)
42 54 cache <- newCache
43 55 setUnicodeLocale "en_US"
44 56 httpServe server (serve config pool cache announces)
45 57 where server = addListen (ListenHttp "0.0.0.0" 10000) defaultConfig
46 58 + 59 -- @ label server
+ 60 -- @ do Web server.
+ 61 -- @ trigger serve
47 62 -- | Serve the controllers.
48 63 serve :: Config -> Pool -> Cache -> Chan Text -> Snap ()
49 64 serve conf p cache ans = route routes where
- 50 routes = [("/css/amelie.css", run Style.handle)
+ 65 -- @ label serve
+ 66 -- @ if Static?
+ 67 -- @ then staticServe
+ 68 -- @ else pageServe
+ 69 routes = [
+ 70 -- @ label staticServe
+ 71 -- @ do Serve static content.
+ 72 ("/css/amelie.css", run Style.handle)
51 73 ,("/js/amelie.js", run Script.handle)
52 74 ,("/css/",serveDirectory "wwwroot/css")
53 75 ,("/js/",serveDirectory "wwwroot/js")
54 76 ,("/hs/",serveDirectory "wwwroot/hs")
+ 77 -- @ label pageServe
+ 78 -- @ do Serve page.
55 79 ,("",run Home.handle)
+ 80 -- @ next homePage
56 81 ,("/:id",run Paste.handle)
+ 82 -- @ next pastePage
57 83 ,("/steps/:id",run Steps.handle)
+ 84 -- @ next stepsPage
58 85 ,("/raw/:id",run Raw.handle)
+ 86 -- @ next rawPastePage
59 87 ,("/new",run New.handle)
+ 88 -- @ next newPastePage
60 89 ,("/edit/:id",run New.handle)
+ 90 -- @ next annotatePage
61 91 ,("/new/:channel",run New.handle)
+ 92 -- @ next browsePage
62 93 ,("/browse/page/:page/offset/:offset",run Browse.handle)
63 94 ,("/browse/page/:page",run Browse.handle)
64 95 ,("/browse",run Browse.handle)
+ 96 -- @ next activityPage
65 97 ,("/activity",run Activity.handle)
+ 98 -- @ next diffPage
66 99 ,("/diff/:this/:that",run Diff.handle)
+ 100 -- @ next stepEvalRawPage
67 101 ,("/stepeval/raw",run Stepeval.handleRaw)
+ 102 -- @ next stepEvalPage
68 103 ,("/stepeval",run Stepeval.handle)
69 104 ]
70 105 run = runHandler conf p cache ans
… … … … Edit file src/Amelie/Model/Activity.hs 33188 → 33188
16 16 import Data.Time
17 17 import Network.Curl.Download
18 18 import System.Locale
19 19 import Text.Feed.Query
20 20 + 21 -- @ label getCommits
+ 22 -- @ task Get commits from feed.
21 23 -- | Get commits of this project from a commit feed.
22 24 getCommits :: String -> Model [Commit]
23 25 getCommits uri = io $ do
24 26 result <- openAsFeed uri
25 27 case result of
… … … … Edit file src/Amelie/Model/Paste.hs 33188 → 33188
47 47 countPublicPastes = do
48 48 rows <- singleNoParams ["SELECT COUNT(*)"
49 49 ,"FROM public_toplevel_paste"]
50 50 return $ fromMaybe 0 rows
51 51 + 52 -- @ label getLatestPastes
+ 53 -- @ task Get latest pastes.
52 54 -- | Get the latest pastes.
53 55 getLatestPastes :: Model [Paste]
54 56 getLatestPastes =
55 57 queryNoParams ["SELECT *"
56 58 ,"FROM public_toplevel_paste"
57 59 ,"ORDER BY id DESC"
58 60 ,"LIMIT 20"]
59 61 - 60 -- | Get the latest pastes.
+ 62 -- @ label getPastes
+ 63 -- @ task Get some pastes.
+ 64 -- | Get some paginated pastes.
61 65 getSomePastes :: Pagination -> Model [Paste]
62 66 getSomePastes Pagination{..} =
63 67 queryNoParams ["SELECT *"
64 68 ,"FROM public_toplevel_paste"
65 69 ,"ORDER BY id DESC"
66 70 ,"OFFSET " ++ show (max 0 (pnPage - 1) * pnLimit)
67 71 ,"LIMIT " ++ show pnLimit]
68 72 + 73 -- @ label getPasteById
+ 74 -- @ task Get paste by id.
69 75 -- | Get a paste by its id.
70 76 getPasteById :: PasteId -> Model (Maybe Paste)
71 77 getPasteById pid =
72 78 listToMaybe <$> query ["SELECT *"
73 79 ,"FROM public_paste"
… … … … 89 95 case pasteSubmitId of
90 96 Nothing -> createPaste langs chans paste
91 97 Just pid -> do updatePaste pid paste
92 98 return $ Just pid
93 99 + 100 -- @ label createPaste
+ 101 -- @ task Create paste.
94 102 -- | Create a new paste (possibly editing an existing one).
95 103 createPaste :: [Language] -> [Channel] -> PasteSubmit -> Model (Maybe PasteId)
96 104 createPaste langs chans ps@PasteSubmit{..} = do
97 105 res <- single ["INSERT INTO paste"
98 106 ,"(title,author,content,channel,language,annotation_of)"
… … … … 193 201 query ["SELECT type,content"
194 202 ,"FROM hint"
195 203 ,"WHERE paste = ?"]
196 204 (Only pid)
197 205 + 206 -- @ label updatePaste
+ 207 -- @ task Update paste.
198 208 -- | Update an existing paste.
199 209 updatePaste :: PasteId -> PasteSubmit -> Model ()
200 210 updatePaste pid PasteSubmit{..} = do
201 211 _ <- exec (["UPDATE paste"
202 212 ,"SET"]
… … … … Edit file src/Amelie/Controller/Activity.hs 33188 → 33188
14 14 import Amelie.Types.Cache as Key
15 15 import Amelie.View.Activity (page)
16 16 17 17 import Control.Monad.Env (env)
18 18 + 19 -- @ label activityPage
+ 20 -- @ do Show Amelie project commit activity.
+ 21 -- @ trigger getCommits
19 22 handle :: Controller ()
20 23 handle = do
21 24 html <- cache Key.Activity $ do
22 25 uri <- env $ configCommits . controllerStateConfig
23 26 repourl <- env $ configRepoURL . controllerStateConfig
… … … … Edit file src/Amelie/Controller/Browse.hs 33188 → 33188
12 12 import Amelie.Model.Channel (getChannels)
13 13 import Amelie.Model.Language (getLanguages)
14 14 import Amelie.Model.Paste (getSomePastes,countPublicPastes)
15 15 import Amelie.View.Browse (page)
16 16 + 17 -- @ label browsePage
+ 18 -- @ do Browse pastes.
+ 19 -- @ trigger getPastes
+ 20 -- @ next pastePage
+ 21 -- @ next browsePage
17 22 handle :: Controller ()
18 23 handle = do
19 24 pn <- getPagination
20 25 total <- model countPublicPastes
21 26 pastes <- model $ getSomePastes pn
… … … … Edit file src/Amelie/Controller/Diff.hs 33188 → 33188
11 11 import Amelie.Controller
12 12 import Amelie.Controller.Paste (withPasteKey)
13 13 import Amelie.Model
14 14 import Amelie.View.Diff (page)
15 15 + 16 -- @ label diffPage
+ 17 -- @ do Diff two pastes.
+ 18 -- @ trigger getPasteById
+ 19 -- @ trigger getPasteById
16 20 handle :: Controller ()
17 21 handle = do
18 22 withPasteKey "this" $ \this ->
19 23 withPasteKey "that" $ \that ->
20 24 output $ page this that
… … … … Edit file src/Amelie/Controller/Home.hs 33188 → 33188
15 15 import Amelie.Model.Language (getLanguages)
16 16 import Amelie.Model.Paste (getLatestPastes)
17 17 import Amelie.Types.Cache as Key
18 18 import Amelie.View.Home (page)
19 19 + 20 -- @ label homePage
+ 21 -- @ do Home page.
+ 22 -- @ trigger getLatestPastes
+ 23 -- @ next pastePage
+ 24 -- @ next newPastePage
+ 25 -- @ next activityPage
20 26 handle :: Controller ()
21 27 handle = do
22 28 html <- cache Key.Home $ do
23 29 pastes <- model $ getLatestPastes
24 30 chans <- model $ getChannels
… … … … Edit file src/Amelie/Controller/New.hs 33188 → 33188
18 18 19 19 import Control.Applicative
20 20 import Data.Text.Encoding (decodeUtf8)
21 21 import Snap.Types
22 22 + 23 -- @ label annotatePage
+ 24 -- @ do Annotate a paste.
+ 25 -- @ trigger getPasteById
+ 26 -- @ trigger updatePaste
+ 27 -- @ next pastePage
+ 28 + 29 -- @ label newPastePage
+ 30 -- @ do Create a new paste.
+ 31 -- @ trigger createPaste
+ 32 -- @ next pastePage
+ 33 23 34 handle :: Controller ()
24 35 handle = do
25 36 chans <- model $ getChannels
26 37 langs <- model $ getLanguages
27 38 defChan <- fmap decodeUtf8 <$> getParam "channel"
… … … … Edit file src/Amelie/Controller/Paste.hs 33188 → 33188
35 35 import Safe
36 36 import Snap.Types
37 37 import Text.Blaze.Html5 as H hiding (output)
38 38 import Text.Formlet
39 39 + 40 -- @ label pastePage
+ 41 -- @ do Paste page.
+ 42 -- @ trigger getPasteById
+ 43 -- @ next annotatePage
+ 44 -- @ next stepsPage
40 45 -- | Handle the paste page.
41 46 handle :: Controller ()
42 47 handle = do
43 48 pid <- getPasteId
44 49 justOrGoHome pid $ \(pid :: Integer) -> do
… … … … Edit file src/Amelie/Controller/Stepeval.hs 33188 → 33188
21 21 import qualified Data.Text.IO as T
22 22 import Data.Text.Lazy (fromStrict)
23 23 import Prelude hiding ((++))
24 24 import Snap.Types
25 25 + 26 -- @ label stepEvalPage
+ 27 -- @ do Stepeval info page.
26 28 -- | Handle the stepeval explanation page.
27 29 handle :: Controller ()
28 30 handle = do
29 31 conf <- env controllerStateConfig
30 32 contents <- io $ T.readFile $ configStepevalPrelude conf
… … … … 32 34 output $ page StepevalPage {
33 35 seHints = hints
34 36 , sePaste = contents
35 37 }
36 38 + 39 -- @ label stepEvalRawPage
+ 40 -- @ do Stepeval raw Prelude page.
37 41 -- | Handle the raw stepeval Prelude view.
38 42 handleRaw :: Controller ()
39 43 handleRaw = do
40 44 modifyResponse $ setContentType "text/plain; charset=UTF-8"
41 45 conf <- env controllerStateConfig
… … … … Edit file src/Amelie/Controller/Steps.hs 33188 → 33188
26 26 import Text.Formlet
27 27 import Control.Applicative
28 28 import Data.Text (unpack)
29 29 import Text.Blaze.Html5 as H hiding (output)
30 30 + 31 -- @ label stepsPage
+ 32 -- @ do Show code steps.
+ 33 -- @ trigger getPasteById
31 34 -- | Handle the paste page.
32 35 handle :: Controller ()
33 36 handle = do
34 37 pid <- getPasteId
35 38 justOrGoHome pid $ \(pid :: Integer) -> do
… … … …