-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
static: update sample-embed.hs and point the old embedded static to t…
…he new one
- Loading branch information
John Lenz
committed
Sep 12, 2013
1 parent
2ad3977
commit 8e16fd2
Showing
3 changed files
with
45 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
{-# LANGUAGE QuasiQuotes, TypeFamilies, MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
import Yesod.Static | ||
import Yesod.Dispatch | ||
{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies #-} | ||
-- | This embeds just a single file; it embeds the source code file | ||
-- \"sample-embed.hs\" from the current directory so when you compile, | ||
-- the sample-embed.hs file must be in the current directory. | ||
-- | ||
-- Try toggling the development argument to 'mkEmbeddedStatic'. When the | ||
-- development argument is true the file \"sample-embed.hs\" is reloaded | ||
-- from disk on every request (try changing it after you start the server). | ||
-- When development is false, the contents are embedded and the sample-embed.hs | ||
-- file does not even need to be present during runtime. | ||
module Main where | ||
|
||
import Yesod.Core | ||
import Network.Wai.Handler.Warp (run) | ||
import Yesod.EmbeddedStatic | ||
|
||
mkEmbeddedStatic False "eStatic" [embedFile "sample-embed.hs"] | ||
|
||
-- The above will generate variables | ||
-- eStatic :: EmbeddedStatic | ||
-- sample_embed_hs :: Route EmbeddedStatic | ||
|
||
staticFiles "." | ||
data MyApp = MyApp { getStatic :: EmbeddedStatic } | ||
|
||
data Sample = Sample | ||
getStatic _ = $(embed "tests") | ||
mkYesod "Sample" [parseRoutes| | ||
/ RootR GET | ||
/static StaticR Static getStatic | ||
mkYesod "MyApp" [parseRoutes| | ||
/ HomeR GET | ||
/static StaticR EmbeddedStatic getStatic | ||
|] | ||
instance Yesod Sample where approot _ = "" | ||
|
||
getRootR = do | ||
redirectText RedirectPermanent "static" | ||
return () | ||
instance Yesod MyApp where | ||
addStaticContent = embedStaticContent getStatic StaticR Right | ||
|
||
getHomeR :: Handler Html | ||
getHomeR = defaultLayout $ do | ||
toWidget [julius|console.log("Hello World");|] | ||
[whamlet| | ||
<h1>Hello | ||
<p>Check the | ||
<a href=@{StaticR sample_embed_hs}>embedded file | ||
|] | ||
|
||
main = toWaiApp Sample >>= run 3000 | ||
main :: IO () | ||
main = warp 3000 $ MyApp eStatic |
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