Skip to content

Commit

Permalink
Minimal YesodPureScript sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mpietrzak committed Dec 20, 2014
1 parent f79691b commit 6e026b6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Network.Wai.Middleware.RequestLogger (Destination (Logger),
mkRequestLogger, outputFormat)
import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet,
toLogStr)
import Yesod.PureScript (createYesodPureScriptSite)

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

appPureScript <- createYesodPureScriptSite def

-- We need a log function to create a connection pool. We need a connection
-- pool to create our foundation. And we need our foundation to get a
-- logging function. To get out of this loop, we initially create a
Expand Down
4 changes: 4 additions & 0 deletions Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Text.Jasmine (minifym)
import Yesod.Auth.BrowserId (authBrowserId)
import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Core.Types (Logger)
import Yesod.PureScript (YesodPureScript, PureScriptSite)

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

instance HasHttpManager App where
Expand Down Expand Up @@ -142,6 +144,8 @@ instance YesodAuthPersist App
instance RenderMessage App FormMessage where
renderMessage _ _ = defaultFormMessage

instance YesodPureScript App

-- Note: Some functionality previously present in the scaffolding has been
-- moved to documentation in the Wiki. Following are some hopefully helpful
-- links:
Expand Down
3 changes: 3 additions & 0 deletions Handler/Home.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Handler.Home where
import Import
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3,
withSmallInput)
import Yesod.PureScript (getPureScriptRoute)

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

postHomeR :: Handler Html
Expand All @@ -32,6 +34,7 @@ postHomeR = do
defaultLayout $ do
aDomId <- newIdent
setTitle "Welcome To Yesod!"
addScript $ PureScriptR $ getPureScriptRoute ["Hello"]
$(widgetFile "homepage")

sampleForm :: Form (FileInfo, Text)
Expand Down
1 change: 1 addition & 0 deletions bower_components/empty.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- just to ensure bower_components directory exists
1 change: 1 addition & 0 deletions config/routes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/static StaticR Static appStatic
/auth AuthR Auth getAuth
/purs PureScriptR PureScriptSite appPureScript

/favicon.ico FaviconR GET
/robots.txt RobotsR GET
Expand Down
14 changes: 14 additions & 0 deletions purs/Hello.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

module Hello (main)
where

import Control.Monad.Eff

foreign import log
"""function log(s) {
return function() {
return window.console.log(s);
};
}""" :: forall eff. String -> Eff eff {}

main = log "hello"
1 change: 1 addition & 0 deletions yesod-purescript-sample.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ library
, yesod-auth >= 1.4.0 && < 1.5
, yesod-static >= 1.4.0.3 && < 1.5
, yesod-form >= 1.4.0 && < 1.5
, yesod-purescript >= 0.0.4
, classy-prelude >= 0.10.2
, classy-prelude-conduit >= 0.10.2
, classy-prelude-yesod >= 0.10.2
Expand Down

0 comments on commit 6e026b6

Please sign in to comment.