does it work?
This commit is contained in:
parent
7ec9a8f10e
commit
9b949230dd
28 changed files with 188 additions and 114 deletions
|
@ -43,6 +43,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet,
|
|||
import Handler.Common
|
||||
import Handler.Home
|
||||
import Handler.Station
|
||||
import Handler.Ad
|
||||
|
||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
||||
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
||||
|
|
|
@ -146,8 +146,10 @@ instance Yesod App where
|
|||
-- value passed to hamletToRepHtml cannot be a widget, this allows
|
||||
-- you to use normal widget features in default-layout.
|
||||
|
||||
-- randomAddNumber <- liftIO $ getStdRandom (randomR (0,4))
|
||||
|
||||
pc <- widgetToPageContent $ do
|
||||
addStylesheet $ StaticR css_bootstrap_css
|
||||
-- addStylesheet $ StaticR css_bootstrap_css
|
||||
-- ^ generated from @Settings/StaticFiles.hs@
|
||||
$(widgetFile "default-layout")
|
||||
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
|
||||
|
|
15
src/Handler/Ad.hs
Normal file
15
src/Handler/Ad.hs
Normal file
|
@ -0,0 +1,15 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
module Handler.Ad where
|
||||
|
||||
import Import
|
||||
|
||||
getAdR :: Handler Html
|
||||
getAdR = do
|
||||
basePath <- getsYesod (appAdFilePath . appSettings)
|
||||
number <- applyAtomicGen (randomR (0 :: Int ,4)) globalStdGen
|
||||
sendFile typePng $ basePath <> "image" <> show number <> ".png"
|
|
@ -19,7 +19,8 @@ checkStation stationIdentifier = do
|
|||
Nothing -> notFound
|
||||
Just m -> return m
|
||||
|
||||
repsertBy :: (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m ()
|
||||
-- TODO works without the type annotation, but I don't know why this one is wrong. No time to find out now
|
||||
-- repsertBy :: (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m ()
|
||||
repsertBy val = do
|
||||
valM <- getByValue val
|
||||
case valM of
|
||||
|
|
|
@ -10,3 +10,5 @@ import Settings.StaticFiles as Import
|
|||
import Yesod.Auth as Import
|
||||
import Yesod.Core.Types as Import (loggerSet)
|
||||
import Yesod.Default.Config2 as Import
|
||||
import System.Random as Import
|
||||
import System.Random.Stateful as Import
|
||||
|
|
|
@ -71,6 +71,7 @@ data AppSettings = AppSettings
|
|||
-- ^ Copyright text to appear in the footer of the page
|
||||
|
||||
, appStations :: Map Text Text
|
||||
, appAdFilePath :: String
|
||||
}
|
||||
|
||||
instance FromJSON AppSettings where
|
||||
|
@ -98,6 +99,7 @@ instance FromJSON AppSettings where
|
|||
|
||||
appCopyright <- o .: "copyright"
|
||||
appStations <- M.fromList . map (\x -> (stationId x, stationName x)) <$> o .: "stations"
|
||||
appAdFilePath <- o .: "ad-files"
|
||||
|
||||
return AppSettings {..}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue