Skip to content

Commit 6e026b6

Browse files
committed
Minimal YesodPureScript sample
1 parent f79691b commit 6e026b6

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

Application.hs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Network.Wai.Middleware.RequestLogger (Destination (Logger),
2121
mkRequestLogger, outputFormat)
2222
import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet,
2323
toLogStr)
24+
import Yesod.PureScript (createYesodPureScriptSite)
2425

2526
-- Import all relevant handler modules here.
2627
-- Don't forget to add new modules to your cabal file!
@@ -46,6 +47,8 @@ makeFoundation appSettings = do
4647
(if appMutableStatic appSettings then staticDevel else static)
4748
(appStaticDir appSettings)
4849

50+
appPureScript <- createYesodPureScriptSite def
51+
4952
-- We need a log function to create a connection pool. We need a connection
5053
-- pool to create our foundation. And we need our foundation to get a
5154
-- logging function. To get out of this loop, we initially create a

Foundation.hs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Text.Jasmine (minifym)
77
import Yesod.Auth.BrowserId (authBrowserId)
88
import Yesod.Default.Util (addStaticContentExternal)
99
import Yesod.Core.Types (Logger)
10+
import Yesod.PureScript (YesodPureScript, PureScriptSite)
1011

1112
-- | The foundation datatype for your application. This can be a good place to
1213
-- keep settings and values requiring initialization before your application
@@ -18,6 +19,7 @@ data App = App
1819
, appConnPool :: ConnectionPool -- ^ Database connection pool.
1920
, appHttpManager :: Manager
2021
, appLogger :: Logger
22+
, appPureScript :: PureScriptSite
2123
}
2224

2325
instance HasHttpManager App where
@@ -142,6 +144,8 @@ instance YesodAuthPersist App
142144
instance RenderMessage App FormMessage where
143145
renderMessage _ _ = defaultFormMessage
144146

147+
instance YesodPureScript App
148+
145149
-- Note: Some functionality previously present in the scaffolding has been
146150
-- moved to documentation in the Wiki. Following are some hopefully helpful
147151
-- links:

Handler/Home.hs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Handler.Home where
33
import Import
44
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3,
55
withSmallInput)
6+
import Yesod.PureScript (getPureScriptRoute)
67

78
-- This is a handler function for the GET request method on the HomeR
89
-- resource pattern. All of your resource patterns are defined in
@@ -19,6 +20,7 @@ getHomeR = do
1920
defaultLayout $ do
2021
aDomId <- newIdent
2122
setTitle "Welcome To Yesod!"
23+
addScript $ PureScriptR $ getPureScriptRoute ["Hello"]
2224
$(widgetFile "homepage")
2325

2426
postHomeR :: Handler Html
@@ -32,6 +34,7 @@ postHomeR = do
3234
defaultLayout $ do
3335
aDomId <- newIdent
3436
setTitle "Welcome To Yesod!"
37+
addScript $ PureScriptR $ getPureScriptRoute ["Hello"]
3538
$(widgetFile "homepage")
3639

3740
sampleForm :: Form (FileInfo, Text)

bower_components/empty.purs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- just to ensure bower_components directory exists

config/routes

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/static StaticR Static appStatic
22
/auth AuthR Auth getAuth
3+
/purs PureScriptR PureScriptSite appPureScript
34

45
/favicon.ico FaviconR GET
56
/robots.txt RobotsR GET

purs/Hello.purs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
module Hello (main)
3+
where
4+
5+
import Control.Monad.Eff
6+
7+
foreign import log
8+
"""function log(s) {
9+
return function() {
10+
return window.console.log(s);
11+
};
12+
}""" :: forall eff. String -> Eff eff {}
13+
14+
main = log "hello"

yesod-purescript-sample.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
, yesod-auth >= 1.4.0 && < 1.5
5252
, yesod-static >= 1.4.0.3 && < 1.5
5353
, yesod-form >= 1.4.0 && < 1.5
54+
, yesod-purescript >= 0.0.4
5455
, classy-prelude >= 0.10.2
5556
, classy-prelude-conduit >= 0.10.2
5657
, classy-prelude-yesod >= 0.10.2

0 commit comments

Comments
 (0)