2015-09-04 23:23:32 +02:00
|
|
|
module Handler.ShowChallenge where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
|
2015-09-06 14:24:49 +02:00
|
|
|
import qualified Data.Text.Lazy as TL
|
|
|
|
import Text.Markdown
|
|
|
|
|
|
|
|
import Handler.Extract
|
|
|
|
import Handler.Shared
|
|
|
|
|
2015-09-04 23:23:32 +02:00
|
|
|
getShowChallengeR :: Text -> Handler Html
|
|
|
|
getShowChallengeR name = do
|
|
|
|
(Entity _ challenge) <- runDB $ getBy404 $ UniqueName name
|
2015-09-06 14:24:49 +02:00
|
|
|
challengeLayout True challenge (showChallengeWidget challenge)
|
|
|
|
|
|
|
|
getChallengeReadmeR :: Text -> Handler Html
|
|
|
|
getChallengeReadmeR name = do
|
|
|
|
(Entity _ challenge) <- runDB $ getBy404 $ UniqueName name
|
|
|
|
let repoId = challengePublicRepo challenge
|
|
|
|
let repoDir = getRepoDir repoId
|
|
|
|
let readmeFilePath = repoDir </> readmeFile
|
|
|
|
contents <- readFile readmeFilePath
|
|
|
|
challengeLayout False challenge $ toWidget $ markdown def $ TL.fromStrict contents
|
|
|
|
|
|
|
|
showChallengeWidget challenge = $(widgetFile "show-challenge")
|
|
|
|
|
|
|
|
challengeLayout withHeader challenge widget = do
|
|
|
|
bc <- widgetToPageContent widget
|
2015-09-04 23:23:32 +02:00
|
|
|
defaultLayout $ do
|
2015-09-06 14:24:49 +02:00
|
|
|
setTitle "Challenge"
|
|
|
|
$(widgetFile "challenge")
|