10000 Updated for lts-6.0; add .cabal file by erantapaa · Pull Request #1 · nbartlomiej/tfoo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Updated for lts-6.0; add .cabal file #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Application.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings,
MultiParamTypeClasses #-}
MultiParamTypeClasses, ViewPatterns #-}

module Application where

Expand Down Expand Up @@ -28,7 +28,7 @@ instance Yesod Tfoo where
addStylesheet $ StaticR $ StaticRoute ["styles", "tfoo.css"] []
addScript $ StaticR $ StaticRoute ["scripts","jquery-1.7.1.min.js"] []
addScript $ StaticR $ StaticRoute ["scripts","jquery.wiggle.js"] []
hamletToRepHtml $(hamletFile "templates/layout.hamlet")
withUrlRenderer $(hamletFile "templates/layout.hamlet")

instance RenderMessage Tfoo FormMessage where
renderMessage _ _ = defaultFormMessage
Expand Down
4 changes: 2 additions & 2 deletions Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE MultiParamTypeClasses, TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses, TemplateHaskell, ViewPatterns, OverloadedStrings #-}
module Main where

import Tfoo.Foundation
Expand Down Expand Up @@ -42,7 +42,7 @@ main = do
seedP <- liftIO $ Random.getStdGen >>= (\x -> return $ next x)
static' <- static "static"
args <- getArgs
warpDebug (getPort args) (Tfoo (fst seedP) games nextGameId static')
warp (getPort args) (Tfoo (fst seedP) games nextGameId static')

getPort :: [String] -> Int
getPort args = extractPort $ "-p" `elemIndex` args
Expand Down
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
2 changes: 1 addition & 1 deletion Tfoo/Game.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Tfoo.Game where

import Tfoo.Board

import Network.Wai.EventSource (ServerEvent (..), eventSourceApp)
import Network.Wai.EventSource (ServerEvent (..))
import Control.Concurrent.Chan

type Player = String
Expand Down
28 changes: 15 additions & 13 deletions Tfoo/Handlers/Root.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}

module Tfoo.Handlers.Root where

Expand All @@ -21,35 +22,38 @@ import Control.Concurrent.MVar

import Yesod
import Yesod.Default.Util
import Text.Julius

import Control.Concurrent.Chan
import Network.Wai.EventSource (ServerEvent (..), eventSourceApp)
import Network.Wai.EventSource (ServerEvent (..), eventSourceAppChan)
import Data.Default
import Network.Wai.Internal (ResponseReceived(..))


getHomeR :: Handler RepHtml
getHomeR :: Handler Html
getHomeR = do
tfoo <- getYesod
defaultLayout $(widgetFileNoReload "index")
defaultLayout $(widgetFileNoReload def "index")

postGamesR :: Handler RepHtml
postGamesR :: Handler Html
postGamesR = do
tfoo <- getYesod
id <- liftIO $ newGame tfoo
Just single <- runInputPost $ Just <$> iopt hiddenField (T.pack "single")
if isJust single
single <- runInputPost $ iopt hiddenField (T.pack "single")
if single == Just ("true" :: String)
then newSinglePlayerGame id
else return ()
redirect $ GameR id

getGameR :: Int -> Handler RepHtml
getGameR :: Int -> Handler Html
getGameR id = let
columns = [0..19]
rows = [0..19]
in do
game <- getGame id
maybePlayers <- lookupSession $ T.pack "players"
tfoo <- getYesod
defaultLayout $(widgetFileNoReload "game")
defaultLayout $(widgetFileNoReload def "game")

postMarkR :: Int -> Int -> Int -> Handler ()
postMarkR id x y = do
Expand All @@ -73,7 +77,7 @@ postMarkR id x y = do
then permissionDenied $ T.pack "Permission Denied"
else return ()

postPlayerOR :: Int -> Handler RepHtml
postPlayerOR :: Int -> Handler Html
postPlayerOR id = do
game <- getGame id
if (playerO game) == Nothing
Expand All @@ -85,7 +89,7 @@ postPlayerOR id = do
else return ()
redirect $ GameR id

postPlayerXR :: Int -> Handler RepHtml
postPlayerXR :: Int -> Handler Html
postPlayerXR id = do
game <- getGame id
if (playerX game) == Nothing
Expand All @@ -101,7 +105,5 @@ getChannelR :: Int -> Handler ()
getChannelR id = do
game <- getGame id
channel <- liftIO $ dupChan $ channel game
request <- waiRequest
response <- lift $ eventSourceApp channel request
sendWaiApplication (eventSourceAppChan channel)
updateGame id game
sendWaiResponse response
2 changes: 1 addition & 1 deletion Tfoo/Helpers/Game.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Control.Monad
import Control.Concurrent.MVar
import Control.Concurrent.Chan

import Network.Wai.EventSource (ServerEvent (..), eventSourceApp)
import Network.Wai.EventSource (ServerEvent (..) )
import Blaze.ByteString.Builder.Char.Utf8 (fromString)

getGame :: Int -> Handler Game
Expand Down
12 changes: 12 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

resolver: lts-6.0

packages:
- '.'

extra-deps: []

flags: {}

extra-package-dbs: []

2 changes: 1 addition & 1 deletion templates/game.julius
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $(document).ready(function() {
$(element).click(function(){
var x = $(element).attr('data-x');
var y = $(element).attr('data-y');
post('#{show id}/mark/' + x + '/' + y);
post('#{rawJS $ show id}/mark/' + x + '/' + y);
});
});
});
33 changes: 33 additions & 0 deletions tfoo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: tfoo
version: 0.1.0.0
synopsis: Five in a row
-- description:
homepage: https://github.com/nbartlomiej/tfoo
-- license:
license-file: LICENSE
author: Bartlomiej Niemtur
maintainer: nbartlomiej@gmail.com
-- copyright:
category: Game
build-type: Simple
extra-source-files: README.rdoc
cabal-version: >=1.10

executable tfoo
main-is: Main.hs
other-modules: Application,
Tfoo.Board,
Tfoo.Foundation,
Tfoo.Game,
Tfoo.Handlers.Root,
Tfoo.Helpers.Application,
Tfoo.Helpers.Game,
Tfoo.Matrix

other-extensions: TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings, MultiParamTypeClasses, ViewPatterns
build-depends: base >=4.8, random, text,
wai-eventsource, yesod, yesod-static, yesod-default, blaze-builder,
shakespeare, hamlet, wai-extra, data-default, wai

-- hs-source-dirs:
default-language: Haskell2010
0