diff --git a/Import.hs b/Import.hs deleted file mode 100644 index a102001..0000000 --- a/Import.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Import - ( module Import - ) where - -import Foundation as Import -import Import.NoFoundation as Import diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index d94fbe3..7207294 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -12,16 +12,20 @@ Flag library-only Default: False library - hs-source-dirs: ., app - exposed-modules: Application - Foundation - Import - Import.NoFoundation - Model - Settings - Settings.StaticFiles - Handler.Common - Handler.Home + hs-source-dirs: app + , src + + exposed-modules: App.DB.Model + , App.FoundationImport + , App.Handler + , App.NoFoundationImport + , App.Route.Common.Handler + , App.Route.Home.Form + , App.Route.Home.Handler + , Application + , Foundation + , Settings + , Settings.StaticFiles if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT @@ -29,58 +33,59 @@ library else ghc-options: -Wall -fwarn-tabs -O2 - extensions: TemplateHaskell - QuasiQuotes - OverloadedStrings - NoImplicitPrelude - CPP - MultiParamTypeClasses - TypeFamilies - GADTs - GeneralizedNewtypeDeriving - FlexibleContexts - EmptyDataDecls - NoMonomorphismRestriction - DeriveDataTypeable - ViewPatterns - TupleSections - RecordWildCards + extensions: CPP + , DeriveDataTypeable + , EmptyDataDecls + , FlexibleContexts + , GADTs + , GeneralizedNewtypeDeriving + , MultiParamTypeClasses + , NoImplicitPrelude + , NoMonomorphismRestriction + , OverloadedStrings + , QuasiQuotes + , RankNTypes + , RecordWildCards + , TemplateHaskell + , TupleSections + , TypeFamilies + , ViewPatterns build-depends: base >= 4 && < 5 - , yesod >= 1.4.1 && < 1.5 - , yesod-core >= 1.4.6 && < 1.5 - , yesod-auth >= 1.4.0 && < 1.5 - , yesod-static >= 1.4.0.3 && < 1.5 - , yesod-form >= 1.4.0 && < 1.5 + , aeson >= 0.6 && < 0.9 + , bytestring >= 0.9 && < 0.11 , classy-prelude >= 0.10.2 , classy-prelude-conduit >= 0.10.2 , classy-prelude-yesod >= 0.10.2 - , bytestring >= 0.9 && < 0.11 - , text >= 0.11 && < 2.0 - , persistent >= 2.0 && < 2.2 - , persistent-postgresql >= 2.1.1 && < 2.2 - , persistent-template >= 2.0 && < 2.2 - , template-haskell - , shakespeare >= 2.0 && < 2.1 - , hjsmin >= 0.1 && < 0.2 - , monad-control >= 0.3 && < 1.1 - , wai-extra >= 3.0 && < 3.1 - , yaml >= 0.8 && < 0.9 - , http-conduit >= 2.1 && < 2.2 - , directory >= 1.1 && < 1.3 - , warp >= 3.0 && < 3.1 - , data-default - , aeson >= 0.6 && < 0.9 , conduit >= 1.0 && < 2.0 - , monad-logger >= 0.3 && < 0.4 + , containers + , data-default + , directory >= 1.1 && < 1.3 , fast-logger >= 2.2 && < 2.4 - , wai-logger >= 2.2 && < 2.3 , file-embed + , hjsmin >= 0.1 && < 0.2 + , http-conduit >= 2.1 && < 2.2 + , monad-control >= 0.3 && < 1.1 + , monad-logger >= 0.3 && < 0.4 + , persistent >= 2.0 && < 2.2 + , persistent-postgresql >= 2.1.1 && < 2.2 + , persistent-template >= 2.0 && < 2.2 , safe + , shakespeare >= 2.0 && < 2.1 + , template-haskell + , text >= 0.11 && < 2.0 + , time , unordered-containers - , containers , vector - , time + , wai-extra >= 3.0 && < 3.1 + , wai-logger >= 2.2 && < 2.3 + , warp >= 3.0 && < 3.1 + , yaml >= 0.8 && < 0.9 + , yesod >= 1.4.1 && < 1.5 + , yesod-auth >= 1.4.0 && < 1.5 + , yesod-core >= 1.4.6 && < 1.5 + , yesod-form >= 1.4.0 && < 1.5 + , yesod-static >= 1.4.0.3 && < 1.5 executable PROJECTNAME if flag(library-only) @@ -98,33 +103,33 @@ test-suite test hs-source-dirs: test ghc-options: -Wall - extensions: TemplateHaskell - QuasiQuotes - OverloadedStrings - NoImplicitPrelude - CPP - MultiParamTypeClasses - TypeFamilies - GADTs - GeneralizedNewtypeDeriving - FlexibleContexts - EmptyDataDecls - NoMonomorphismRestriction - DeriveDataTypeable - ViewPatterns - TupleSections + extensions: CPP + , DeriveDataTypeable + , EmptyDataDecls + , FlexibleContexts + , GADTs + , GeneralizedNewtypeDeriving + , MultiParamTypeClasses + , NoImplicitPrelude + , NoMonomorphismRestriction + , OverloadedStrings + , QuasiQuotes + , TemplateHaskell + , TupleSections + , TypeFamilies + , ViewPatterns build-depends: base , PROJECTNAME - , yesod-test >= 1.4.3 && < 1.5 - , yesod-core - , yesod + , classy-prelude + , classy-prelude-yesod + , hspec >= 2.0.0 + , monad-logger , persistent , persistent-postgresql , resourcet - , monad-logger , shakespeare , transformers - , hspec >= 2.0.0 - , classy-prelude - , classy-prelude-yesod + , yesod + , yesod-core + , yesod-test >= 1.4.3 && < 1.5 diff --git a/Model.hs b/src/App/DB/Model.hs similarity index 93% rename from Model.hs rename to src/App/DB/Model.hs index 353bafb..fb663a4 100644 --- a/Model.hs +++ b/src/App/DB/Model.hs @@ -1,4 +1,4 @@ -module Model where +module App.DB.Model where import ClassyPrelude.Yesod import Database.Persist.Quasi diff --git a/src/App/FoundationImport.hs b/src/App/FoundationImport.hs new file mode 100644 index 0000000..d94e436 --- /dev/null +++ b/src/App/FoundationImport.hs @@ -0,0 +1,6 @@ +module App.FoundationImport + ( module Import + ) where + +import Foundation as Import +import App.NoFoundationImport as Import diff --git a/src/App/Handler.hs b/src/App/Handler.hs new file mode 100644 index 0000000..f3835a8 --- /dev/null +++ b/src/App/Handler.hs @@ -0,0 +1,9 @@ + +-- | This module is just for reexports of all handlers in the +-- project. +module App.Handler + ( module Import + ) where + +import App.Route.Common.Handler as Import +import App.Route.Home.Handler as Import diff --git a/Import/NoFoundation.hs b/src/App/NoFoundationImport.hs similarity index 52% rename from Import/NoFoundation.hs rename to src/App/NoFoundationImport.hs index 15bf2dc..5136aa9 100644 --- a/Import/NoFoundation.hs +++ b/src/App/NoFoundationImport.hs @@ -1,11 +1,19 @@ -module Import.NoFoundation +module App.NoFoundationImport ( module Import + , Form ) where import ClassyPrelude.Yesod as Import -import Model as Import + +import App.DB.Model as Import import Settings as Import import Settings.StaticFiles as Import import Yesod.Auth as Import import Yesod.Core.Types as Import (loggerSet) import Yesod.Default.Config2 as Import + + +-- | A convenient synonym for creating forms. +type Form app x = + (RenderMessage app FormMessage) + => Html -> MForm (HandlerT app IO) (FormResult x, WidgetT app IO ()) diff --git a/Handler/Common.hs b/src/App/Route/Common/Handler.hs similarity index 88% rename from Handler/Common.hs rename to src/App/Route/Common/Handler.hs index eadd206..c442680 100644 --- a/Handler/Common.hs +++ b/src/App/Route/Common/Handler.hs @@ -1,8 +1,8 @@ -- | Common handler functions. -module Handler.Common where +module App.Route.Common.Handler where +import App.FoundationImport import Data.FileEmbed (embedFile) -import Import -- These handlers embed files in the executable at compile time to avoid a -- runtime dependency, and for efficiency. diff --git a/src/App/Route/Home/Form.hs b/src/App/Route/Home/Form.hs new file mode 100644 index 0000000..48d52bc --- /dev/null +++ b/src/App/Route/Home/Form.hs @@ -0,0 +1,13 @@ +module App.Route.Home.Form where + +import App.NoFoundationImport + +import Yesod.Form.Bootstrap3 + ( BootstrapFormLayout (..), renderBootstrap3 + , withSmallInput ) + + +sampleForm :: Form app (FileInfo, Text) +sampleForm = renderBootstrap3 BootstrapBasicForm $ (,) + <$> fileAFormReq "Choose a file" + <*> areq textField (withSmallInput "What's on the file?") Nothing diff --git a/Handler/Home.hs b/src/App/Route/Home/Handler.hs similarity index 74% rename from Handler/Home.hs rename to src/App/Route/Home/Handler.hs index 86e3039..e0902b2 100644 --- a/Handler/Home.hs +++ b/src/App/Route/Home/Handler.hs @@ -1,8 +1,7 @@ -module Handler.Home where +module App.Route.Home.Handler where -import Import -import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, - withSmallInput) +import App.FoundationImport +import App.Route.Home.Form -- This is a handler function for the GET request method on the HomeR -- resource pattern. All of your resource patterns are defined in @@ -33,8 +32,3 @@ postHomeR = do aDomId <- newIdent setTitle "Welcome To Yesod!" $(widgetFile "homepage") - -sampleForm :: Form (FileInfo, Text) -sampleForm = renderBootstrap3 BootstrapBasicForm $ (,) - <$> fileAFormReq "Choose a file" - <*> areq textField (withSmallInput "What's on the file?") Nothing diff --git a/Application.hs b/src/Application.hs similarity index 99% rename from Application.hs rename to src/Application.hs index 0e4792e..08e497b 100644 --- a/Application.hs +++ b/src/Application.hs @@ -15,7 +15,7 @@ module Application import Control.Monad.Logger (liftLoc, runLoggingT) import Database.Persist.Postgresql (createPostgresqlPool, pgConnStr, pgPoolSize, runSqlPool) -import Import +import App.FoundationImport import Language.Haskell.TH.Syntax (qLocation) import Network.Wai.Handler.Warp (Settings, defaultSettings, defaultShouldDisplayException, @@ -30,8 +30,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, -- Import all relevant handler modules here. -- Don't forget to add new modules to your cabal file! -import Handler.Common -import Handler.Home +import App.Handler -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Foundation.hs b/src/Foundation.hs similarity index 97% rename from Foundation.hs rename to src/Foundation.hs index f9ff583..2894dea 100644 --- a/Foundation.hs +++ b/src/Foundation.hs @@ -1,6 +1,6 @@ module Foundation where -import Import.NoFoundation +import App.NoFoundationImport import Database.Persist.Sql (ConnectionPool, runSqlPool) import Text.Hamlet (hamletFile) import Text.Jasmine (minifym) @@ -33,9 +33,6 @@ instance HasHttpManager App where -- explanation for this split. mkYesodData "App" $(parseRoutesFile "config/routes") --- | A convenient synonym for creating forms. -type Form x = Html -> MForm (HandlerT App IO) (FormResult x, Widget) - -- Please see the documentation for the Yesod typeclass. There are a number -- of settings which can be configured by overriding methods here. instance Yesod App where diff --git a/Settings.hs b/src/Settings.hs similarity index 100% rename from Settings.hs rename to src/Settings.hs diff --git a/Settings/StaticFiles.hs b/src/Settings/StaticFiles.hs similarity index 100% rename from Settings/StaticFiles.hs rename to src/Settings/StaticFiles.hs diff --git a/test/TestImport.hs b/test/TestImport.hs index a735b38..2f366ec 100644 --- a/test/TestImport.hs +++ b/test/TestImport.hs @@ -3,12 +3,12 @@ module TestImport , module X ) where +import App.DB.Model as X import Application (makeFoundation) import ClassyPrelude as X import Database.Persist as X hiding (get) import Database.Persist.Sql (SqlPersistM, SqlBackend, runSqlPersistMPool, rawExecute, rawSql, unSingle, connEscapeName) import Foundation as X -import Model as X import Test.Hspec as X import Text.Shakespeare.Text (st) import Yesod.Default.Config2 (ignoreEnv, loadAppSettings)