By | Chris Done |
At | 2011-06-14 |
Title | Only generate hints for Haskell pastes. |
Description |
Edit file src/Amelie/Model/Paste.hs 33188 → 33188
77 77 ,"WHERE annotation_of = ?"
78 78 ,"ORDER BY id ASC"]
79 79 (Only pid)
80 80 81 81 -- | Create a paste, or update an existing one.
- 82 createOrEdit :: [Channel] -> PasteSubmit -> Model (Maybe PasteId)
- 83 createOrEdit chans paste@PasteSubmit{..} = do
+ 82 createOrEdit :: [Language] -> [Channel] -> PasteSubmit -> Model (Maybe PasteId)
+ 83 createOrEdit langs chans paste@PasteSubmit{..} = do
84 84 case pasteSubmitId of
- 85 Nothing -> createPaste chans paste
+ 85 Nothing -> createPaste langs chans paste
86 86 Just pid -> do updatePaste pid paste
87 87 return $ Just pid
88 88 89 89 -- | Create a new paste (possibly editing an existing one).
- 90 createPaste :: [Channel] -> PasteSubmit -> Model (Maybe PasteId)
- 91 createPaste chans ps@PasteSubmit{..} = do
+ 90 createPaste :: [Language] -> [Channel] -> PasteSubmit -> Model (Maybe PasteId)
+ 91 createPaste langs chans ps@PasteSubmit{..} = do
92 92 res <- single ["INSERT INTO paste"
93 93 ,"(title,author,content,channel,language,annotation_of)"
94 94 ,"VALUES"
95 95 ,"(?,?,?,?,?,?)"
96 96 ,"returning id"]
97 97 (pasteSubmitTitle,pasteSubmitAuthor,pasteSubmitPaste
98 98 ,pasteSubmitChannel,pasteSubmitLanguage,pasteSubmitId)
- 99 just res $ createHints ps
+ 99 when (lang == Just "haskell") $ just res $ createHints ps
100 100 just (pasteSubmitChannel >>= lookupChan) $ \chan ->
101 101 just res $ \pid -> do
102 102 annotated <- maybe (return Nothing) getPasteById pasteSubmitId
103 103 announcePaste annotated (channelName chan) ps pid
104 104 return (pasteSubmitId <|> res)
105 105 106 106 where lookupChan cid = find ((==cid).channelId) chans
+ 107 lookupLang lid = find ((==lid).languageId) langs
+ 108 lang = pasteSubmitLanguage >>= (fmap languageName . lookupLang)
107 109 just j m = maybe (return ()) m j
108 110 109 111 -- | Create the hints for a paste.
110 112 createHints :: PasteSubmit -> PasteId -> Model ()
111 113 createHints ps pid = do
… … … … Edit file src/Amelie/Controller/Paste.hs 33188 → 33188
85 85 Nothing -> return ()
86 86 Just PasteSubmit{pasteSubmitSpamTrap=Just{}} -> goHome
87 87 Just paste -> do
88 88 resetCache Key.Home
89 89 maybe (return ()) (resetCache . Key.Paste . fromIntegral) $ pasteSubmitId paste
- 90 pid <- model $ createPaste channels paste
+ 90 pid <- model $ createPaste languages channels paste
91 91 maybe (return ()) redirectToPaste pid
92 92 return html
93 93 94 94 -- | Redirect to the paste's page.
95 95 redirectToPaste :: PasteId -> Controller ()
… … … …