-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
348 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import Yesod (develServer) | ||
|
||
main :: IO () | ||
main = develServer 3000 "Controller" "with~sitearg~" | ||
main = putStrLn "Please run: wai-handler-devel 3000 Controller with~sitearg~ --yesod" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
module Controller | ||
( with~sitearg~ | ||
) where | ||
|
||
import ~sitearg~ | ||
import Settings | ||
import Yesod.Helpers.Static | ||
import Data.ByteString (ByteString) | ||
import Network.Wai (Application) | ||
|
||
-- Import all relevant handler modules here. | ||
import Handler.Root | ||
|
||
-- This line actually creates our YesodSite instance. It is the second half | ||
-- of the call to mkYesodData which occurs in ~sitearg~.hs. Please see | ||
-- the comments there for more details. | ||
mkYesodDispatch "~sitearg~" resources~sitearg~ | ||
|
||
-- Some default handlers that ship with the Yesod site template. You will | ||
-- very rarely need to modify this. | ||
getFaviconR :: Handler () | ||
getFaviconR = sendFile "image/x-icon" "favicon.ico" | ||
|
||
getRobotsR :: Handler RepPlain | ||
getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString) | ||
|
||
-- This function allocates resources (such as a database connection pool), | ||
-- performs initialization and creates a WAI application. This is also the | ||
-- place to put your migrate statements to have automatic database | ||
-- migrations handled by Yesod. | ||
with~sitearg~ :: (Application -> IO a) -> IO a | ||
with~sitearg~ f = do | ||
let h = ~sitearg~ s | ||
toWaiApp h >>= f | ||
where | ||
s = static Settings.staticdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-} | ||
module Handler.Root where | ||
|
||
import ~sitearg~ | ||
|
||
-- This is a handler function for the GET request method on the RootR | ||
-- resource pattern. All of your resource patterns are defined in | ||
-- ~sitearg~.hs; look for the line beginning with mkYesodData. | ||
-- | ||
-- The majority of the code you will write in Yesod lives in these handler | ||
-- functions. You can spread them across multiple files if you are so | ||
-- inclined, or create a single monolithic file. | ||
getRootR :: Handler RepHtml | ||
getRootR = do | ||
defaultLayout $ do | ||
h2id <- lift newIdent | ||
setTitle "~project~ homepage" | ||
addWidget $(widgetFile "homepage") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
-- | Settings are centralized, as much as possible, into this file. This | ||
-- includes database connection settings, static file locations, etc. | ||
-- In addition, you can configure a number of different aspects of Yesod | ||
-- by overriding methods in the Yesod typeclass. That instance is | ||
-- declared in the ~project~.hs file. | ||
module Settings | ||
( hamletFile | ||
, cassiusFile | ||
, juliusFile | ||
, widgetFile | ||
, approot | ||
, staticroot | ||
, staticdir | ||
) where | ||
|
||
import qualified Text.Hamlet as H | ||
import qualified Text.Cassius as H | ||
import qualified Text.Julius as H | ||
import Language.Haskell.TH.Syntax | ||
import Yesod.Widget (addWidget, addCassius, addJulius) | ||
import Data.Monoid (mempty) | ||
import System.Directory (doesFileExist) | ||
|
||
-- | The base URL for your application. This will usually be different for | ||
-- development and production. Yesod automatically constructs URLs for you, | ||
-- so this value must be accurate to create valid links. | ||
approot :: String | ||
#ifdef PRODUCTION | ||
-- You probably want to change this. If your domain name was "yesod.com", | ||
-- you would probably want it to be: | ||
-- > approot = "http://www.yesod.com" | ||
-- Please note that there is no trailing slash. | ||
approot = "http://localhost:3000" | ||
#else | ||
approot = "http://localhost:3000" | ||
#endif | ||
|
||
-- | The location of static files on your system. This is a file system | ||
-- path. The default value works properly with your scaffolded site. | ||
staticdir :: FilePath | ||
staticdir = "static" | ||
|
||
-- | The base URL for your static files. As you can see by the default | ||
-- value, this can simply be "static" appended to your application root. | ||
-- A powerful optimization can be serving static files from a separate | ||
-- domain name. This allows you to use a web server optimized for static | ||
-- files, more easily set expires and cache values, and avoid possibly | ||
-- costly transference of cookies on static files. For more information, | ||
-- please see: | ||
-- http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain | ||
-- | ||
-- If you change the resource pattern for StaticR in ~project~.hs, you will | ||
-- have to make a corresponding change here. | ||
-- | ||
-- To see how this value is used, see urlRenderOverride in ~project~.hs | ||
staticroot :: String | ||
staticroot = approot ++ "/static" | ||
|
||
-- The rest of this file contains settings which rarely need changing by a | ||
-- user. | ||
|
||
-- The following three functions are used for calling HTML, CSS and | ||
-- Javascript templates from your Haskell code. During development, | ||
-- the "Debug" versions of these functions are used so that changes to | ||
-- the templates are immediately reflected in an already running | ||
-- application. When making a production compile, the non-debug version | ||
-- is used for increased performance. | ||
-- | ||
-- You can see an example of how to call these functions in Handler/Root.hs | ||
-- | ||
-- Note: due to polymorphic Hamlet templates, hamletFileDebug is no longer | ||
-- used; to get the same auto-loading effect, it is recommended that you | ||
-- use the devel server. | ||
|
||
toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath | ||
toHamletFile x = "hamlet/" ++ x ++ ".hamlet" | ||
toCassiusFile x = "cassius/" ++ x ++ ".cassius" | ||
toJuliusFile x = "julius/" ++ x ++ ".julius" | ||
|
||
hamletFile :: FilePath -> Q Exp | ||
hamletFile = H.hamletFile . toHamletFile | ||
|
||
cassiusFile :: FilePath -> Q Exp | ||
#ifdef PRODUCTION | ||
cassiusFile = H.cassiusFile . toCassiusFile | ||
#else | ||
cassiusFile = H.cassiusFileDebug . toCassiusFile | ||
#endif | ||
|
||
juliusFile :: FilePath -> Q Exp | ||
#ifdef PRODUCTION | ||
juliusFile = H.juliusFile . toJuliusFile | ||
#else | ||
juliusFile = H.juliusFileDebug . toJuliusFile | ||
#endif | ||
|
||
widgetFile :: FilePath -> Q Exp | ||
widgetFile x = do | ||
let h = unlessExists toHamletFile hamletFile | ||
let c = unlessExists toCassiusFile cassiusFile | ||
let j = unlessExists toJuliusFile juliusFile | ||
[|addWidget $h >> addCassius $c >> addJulius $j|] | ||
where | ||
unlessExists tofn f = do | ||
e <- qRunIO $ doesFileExist $ tofn x | ||
if e then f x else [|mempty|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: ~project~ | ||
version: 0.0.0 | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: ~name~ | ||
maintainer: ~name~ | ||
synopsis: The greatest Yesod web application ever. | ||
description: I'm sure you can say something clever here if you try. | ||
category: Web | ||
stability: Experimental | ||
cabal-version: >= 1.6 | ||
build-type: Simple | ||
homepage: http://~project~.yesodweb.com/ | ||
|
||
Flag production | ||
Description: Build the production executable. | ||
Default: False | ||
|
||
executable ~project~-test | ||
if flag(production) | ||
Buildable: False | ||
main-is: test.hs | ||
build-depends: base >= 4 && < 5 | ||
, yesod-core >= 0.7 && < 0.8 | ||
, yesod-static | ||
, wai-extra | ||
, directory | ||
, bytestring | ||
, text | ||
, template-haskell | ||
, hamlet | ||
, web-routes | ||
, transformers | ||
, wai | ||
, warp | ||
ghc-options: -Wall -threaded | ||
|
||
executable ~project~-production | ||
if flag(production) | ||
Buildable: True | ||
else | ||
Buildable: False | ||
cpp-options: -DPRODUCTION | ||
main-is: production.hs | ||
ghc-options: -Wall -threaded | ||
|
||
executable ~project~-devel | ||
if flag(production) | ||
Buildable: False | ||
main-is: devel-server.hs | ||
ghc-options: -Wall -O2 -threaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Hello | ||
<h2 ##{h2id}>You do not have Javascript enabled. |
Oops, something went wrong.