Skip to content

Commit

Permalink
Add correct data file paths for examples. Fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Apr 27, 2013
1 parent 9f65da6 commit 5c9b6b0
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 31 deletions.
15 changes: 9 additions & 6 deletions src/BarTab.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Control.Monad
import Data.IORef
import Data.Maybe

import Paths

#ifdef CABAL
import "threepenny-gui" Graphics.UI.Threepenny
#else
Expand All @@ -15,12 +17,13 @@ import Graphics.UI.Threepenny

-- | Main entry point. Starts a TP server.
main :: IO ()
main = startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = "wwwroot"
} setup

main = do
static <- getStaticDir
startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = static
} setup

setup :: Window -> IO ()
setup w = do
Expand Down
13 changes: 8 additions & 5 deletions src/Buttons.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import "threepenny-gui" Graphics.UI.Threepenny
#else
import Graphics.UI.Threepenny
#endif
import Paths

-- | Main entry point. Starts a TP server.
main :: IO ()
main = startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = "../wwwroot"
} setup
main = do
static <- getStaticDir
startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = static
} setup

-- | A per-user worker thread. Each user session has a thread.
setup :: Window -> IO ()
Expand Down
7 changes: 5 additions & 2 deletions src/Chat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ import Control.Exception
import Control.Monad
import Data.List.Extra
import Data.Time
import Prelude hiding (catch)

#ifdef CABAL
import "threepenny-gui" Graphics.UI.Threepenny as UI
#else
import Graphics.UI.Threepenny as UI
#endif
import Prelude hiding (catch)
import Paths


main :: IO ()
main = do
static <- getStaticDir
messages <- Chan.newChan
startGUI Config
{ tpPort = 10000
, tpCustomHTML = Just "chat.html"
, tpStatic = "../wwwroot"
, tpStatic = static
} $ setup messages

type Message = (UTCTime, String, String)
Expand Down
8 changes: 4 additions & 4 deletions src/Graphics/UI/Threepenny/Internal/Resources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defaultHtmlFile :: Text
#ifdef CABAL

jsDriverCode = unsafePerformIO $
readFiles $ words "jquery.js jquery.cookie.js driver.hs"
readFiles $ words "jquery.js jquery-cookie.js driver.js"

cssDriverCode = unsafePerformIO $
readFiles ["driver.css"]
Expand All @@ -34,14 +34,14 @@ readFiles files = do
ys <- mapM (Text.readFile . getDataFile) files
return $ Text.unlines ys

getDataFile x = unsafePerformIO $ fmap (</> x) getDataDir

getDataFile x = unsafePerformIO $
fmap (</> "src" </> "Graphics" </> "UI" </> x) getDataDir

#else

jsDriverCode = Text.unlines $ map Text.pack
[ [include|Graphics/UI/jquery.js|]
, [include|Graphics/UI/jquery.cookie.js|]
, [include|Graphics/UI/jquery-cookie.js|]
, [include|Graphics/UI/driver.js|]
]

Expand Down
File renamed without changes.
13 changes: 8 additions & 5 deletions src/MissingDollars.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import "threepenny-gui" Graphics.UI.Threepenny as UI
#else
import Graphics.UI.Threepenny as UI
#endif
import Paths

-- | Main entry point. Starts a TP server.
main :: IO ()
main = startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = "../wwwroot"
} setup
main = do
static <- getStaticDir
startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = static
} setup


setup :: Window -> IO ()
Expand Down
20 changes: 20 additions & 0 deletions src/Paths.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{-# LANGUAGE CPP#-}
module Paths (getStaticDir) where

import Control.Monad
import System.FilePath

#if CABAL
-- using cabal
import qualified Paths_threepenny_gui (getDataDir)

getStaticDir :: IO FilePath
getStaticDir = (</> "wwwroot") `liftM` Paths_threepenny_gui.getDataDir

#else
-- using GHCi

getStaticDir :: IO FilePath
getStaticDir = return "../wwwroot/"

#endif
17 changes: 10 additions & 7 deletions src/UseWords.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
module Main where

import Control.Applicative hiding ((<|>),many)

import Control.Monad
import Control.Arrow (second)
import Data.Maybe
import Text.Parsec

#ifdef CABAL
import "threepenny-gui" Graphics.UI.Threepenny
import "threepenny-gui" Graphics.UI.Threepenny.Elements as H
#else
import Graphics.UI.Threepenny
import Graphics.UI.Threepenny.Elements as H
#endif
import Text.Parsec
import Paths


main :: IO ()
main = startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = "../wwwroot"
} setup
main = do
static <- getStaticDir
startGUI Config
{ tpPort = 10000
, tpCustomHTML = Nothing
, tpStatic = static
} setup


filename = "../wwwroot/and-then-haskell.txt"
Expand Down
19 changes: 17 additions & 2 deletions threepenny-gui.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ Cabal-version: >=1.8
Extra-Source-Files: src/Graphics/UI/*.html
,src/Graphics/UI/*.js

Data-dir: src/Graphics/UI
Data-files: *.js, *.html
Data-dir: .
Data-files: src/Graphics/UI/*.js
,src/Graphics/UI/*.html
,src/Graphics/UI/*.css
,wwwroot/css/*.css
,wwwroot/*.html
,wwwroot/*.txt


flag buildExamples
Expand Down Expand Up @@ -81,9 +86,11 @@ Executable threepenny-examples-bartab
cpp-options: -DCABAL
build-depends: base >= 4 && < 5
,threepenny-gui
,filepath
else
buildable: False
main-is: BarTab.hs
other-modules: Paths_threepenny_gui
hs-source-dirs: src

Executable threepenny-examples-buttons
Expand All @@ -92,40 +99,48 @@ Executable threepenny-examples-buttons
build-depends: base >= 4 && < 5
,threepenny-gui
,transformers
,filepath
else
buildable: False
main-is: Buttons.hs
other-modules: Paths_threepenny_gui
hs-source-dirs: src

Executable threepenny-examples-missing-dollars
if flag(buildExamples)
cpp-options: -DCABAL
build-depends: base >= 4 && < 5
,filepath
,threepenny-gui
,safe
else
buildable: False
main-is: MissingDollars.hs
other-modules: Paths_threepenny_gui
hs-source-dirs: src

Executable threepenny-examples-use-words
if flag(buildExamples)
cpp-options: -DCABAL
build-depends: base >= 4 && < 5
,threepenny-gui
,filepath
,parsec
else
buildable: False
main-is: UseWords.hs
other-modules: Paths_threepenny_gui
hs-source-dirs: src

Executable threepenny-examples-chat
if flag(buildExamples)
cpp-options: -DCABAL
build-depends: base >= 4 && < 5
,threepenny-gui
,filepath
,time
else
buildable: False
main-is: Chat.hs
other-modules: Paths_threepenny_gui
hs-source-dirs: src

0 comments on commit 5c9b6b0

Please sign in to comment.