From b3981d986b51c8170d891bdef2b431b566d072e1 Mon Sep 17 00:00:00 2001 From: Aleksey Uimanov Date: Fri, 29 May 2015 14:31:07 +0500 Subject: [PATCH 1/5] move everything to `src` --- PROJECTNAME.cabal | 3 ++- Application.hs => src/Application.hs | 0 Foundation.hs => src/Foundation.hs | 0 {Handler => src/Handler}/Common.hs | 0 {Handler => src/Handler}/Home.hs | 0 Import.hs => src/Import.hs | 0 {Import => src/Import}/NoFoundation.hs | 0 Model.hs => src/Model.hs | 0 Settings.hs => src/Settings.hs | 0 {Settings => src/Settings}/StaticFiles.hs | 0 10 files changed, 2 insertions(+), 1 deletion(-) rename Application.hs => src/Application.hs (100%) rename Foundation.hs => src/Foundation.hs (100%) rename {Handler => src/Handler}/Common.hs (100%) rename {Handler => src/Handler}/Home.hs (100%) rename Import.hs => src/Import.hs (100%) rename {Import => src/Import}/NoFoundation.hs (100%) rename Model.hs => src/Model.hs (100%) rename Settings.hs => src/Settings.hs (100%) rename {Settings => src/Settings}/StaticFiles.hs (100%) diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index d94fbe3..0ce1780 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -12,7 +12,8 @@ Flag library-only Default: False library - hs-source-dirs: ., app + hs-source-dirs: app + , src exposed-modules: Application Foundation Import diff --git a/Application.hs b/src/Application.hs similarity index 100% rename from Application.hs rename to src/Application.hs diff --git a/Foundation.hs b/src/Foundation.hs similarity index 100% rename from Foundation.hs rename to src/Foundation.hs diff --git a/Handler/Common.hs b/src/Handler/Common.hs similarity index 100% rename from Handler/Common.hs rename to src/Handler/Common.hs diff --git a/Handler/Home.hs b/src/Handler/Home.hs similarity index 100% rename from Handler/Home.hs rename to src/Handler/Home.hs diff --git a/Import.hs b/src/Import.hs similarity index 100% rename from Import.hs rename to src/Import.hs diff --git a/Import/NoFoundation.hs b/src/Import/NoFoundation.hs similarity index 100% rename from Import/NoFoundation.hs rename to src/Import/NoFoundation.hs diff --git a/Model.hs b/src/Model.hs similarity index 100% rename from Model.hs rename to src/Model.hs 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 From 59e60039e216636b7e6dc53c87fbf70661225923 Mon Sep 17 00:00:00 2001 From: Aleksey Uimanov Date: Fri, 29 May 2015 14:31:24 +0500 Subject: [PATCH 2/5] beautify cabal file --- PROJECTNAME.cabal | 143 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index 0ce1780..da0a84b 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -14,15 +14,16 @@ Flag library-only library hs-source-dirs: app , src + exposed-modules: Application - Foundation - Import - Import.NoFoundation - Model - Settings - Settings.StaticFiles - Handler.Common - Handler.Home + , Foundation + , Handler.Common + , Handler.Home + , Import + , Import.NoFoundation + , Model + , Settings + , Settings.StaticFiles if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT @@ -30,58 +31,58 @@ 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 + , 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) @@ -99,33 +100,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 From 5bb06c536d8109a244417e341b9d3aee6de8ca9c Mon Sep 17 00:00:00 2001 From: Aleksey Uimanov Date: Fri, 29 May 2015 14:41:06 +0500 Subject: [PATCH 3/5] move `Import` modules under `App` --- PROJECTNAME.cabal | 6 +++--- src/App/FoundationImport.hs | 6 ++++++ src/{Import/NoFoundation.hs => App/NoFoundationImport.hs} | 2 +- src/Application.hs | 2 +- src/Foundation.hs | 2 +- src/Handler/Common.hs | 2 +- src/Handler/Home.hs | 2 +- src/Import.hs | 6 ------ 8 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 src/App/FoundationImport.hs rename src/{Import/NoFoundation.hs => App/NoFoundationImport.hs} (91%) delete mode 100644 src/Import.hs diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index da0a84b..36a96f2 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -15,12 +15,12 @@ library hs-source-dirs: app , src - exposed-modules: Application + exposed-modules: App.FoundationImport + , App.NoFoundationImport + , Application , Foundation , Handler.Common , Handler.Home - , Import - , Import.NoFoundation , Model , Settings , Settings.StaticFiles 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/Import/NoFoundation.hs b/src/App/NoFoundationImport.hs similarity index 91% rename from src/Import/NoFoundation.hs rename to src/App/NoFoundationImport.hs index 15bf2dc..e981601 100644 --- a/src/Import/NoFoundation.hs +++ b/src/App/NoFoundationImport.hs @@ -1,4 +1,4 @@ -module Import.NoFoundation +module App.NoFoundationImport ( module Import ) where diff --git a/src/Application.hs b/src/Application.hs index 0e4792e..6779a7b 100644 --- a/src/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, diff --git a/src/Foundation.hs b/src/Foundation.hs index f9ff583..eb11534 100644 --- a/src/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) diff --git a/src/Handler/Common.hs b/src/Handler/Common.hs index eadd206..9baccf8 100644 --- a/src/Handler/Common.hs +++ b/src/Handler/Common.hs @@ -1,8 +1,8 @@ -- | Common handler functions. module Handler.Common 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/Handler/Home.hs b/src/Handler/Home.hs index 86e3039..3fabb3f 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -1,6 +1,6 @@ module Handler.Home where -import Import +import App.FoundationImport import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, withSmallInput) diff --git a/src/Import.hs b/src/Import.hs deleted file mode 100644 index a102001..0000000 --- a/src/Import.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Import - ( module Import - ) where - -import Foundation as Import -import Import.NoFoundation as Import From 5f172ee73c4e1810303f01dd12950cf84d7cc6c0 Mon Sep 17 00:00:00 2001 From: Aleksey Uimanov Date: Fri, 29 May 2015 14:55:07 +0500 Subject: [PATCH 4/5] move all modules to `App` --- PROJECTNAME.cabal | 9 +++++---- src/{ => App/DB}/Model.hs | 2 +- src/App/Handler.hs | 9 +++++++++ src/App/NoFoundationImport.hs | 3 ++- src/{Handler/Common.hs => App/Route/Common/Handler.hs} | 2 +- src/{Handler/Home.hs => App/Route/Home/Handler.hs} | 2 +- src/Application.hs | 3 +-- test/TestImport.hs | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) rename src/{ => App/DB}/Model.hs (93%) create mode 100644 src/App/Handler.hs rename src/{Handler/Common.hs => App/Route/Common/Handler.hs} (93%) rename src/{Handler/Home.hs => App/Route/Home/Handler.hs} (97%) diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index 36a96f2..f482f27 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -15,13 +15,14 @@ library hs-source-dirs: app , src - exposed-modules: App.FoundationImport + exposed-modules: App.DB.Model + , App.FoundationImport + , App.Handler , App.NoFoundationImport + , App.Route.Common.Handler + , App.Route.Home.Handler , Application , Foundation - , Handler.Common - , Handler.Home - , Model , Settings , Settings.StaticFiles diff --git a/src/Model.hs b/src/App/DB/Model.hs similarity index 93% rename from src/Model.hs rename to src/App/DB/Model.hs index 353bafb..fb663a4 100644 --- a/src/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/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/src/App/NoFoundationImport.hs b/src/App/NoFoundationImport.hs index e981601..6239557 100644 --- a/src/App/NoFoundationImport.hs +++ b/src/App/NoFoundationImport.hs @@ -3,7 +3,8 @@ module App.NoFoundationImport ) 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 diff --git a/src/Handler/Common.hs b/src/App/Route/Common/Handler.hs similarity index 93% rename from src/Handler/Common.hs rename to src/App/Route/Common/Handler.hs index 9baccf8..c442680 100644 --- a/src/Handler/Common.hs +++ b/src/App/Route/Common/Handler.hs @@ -1,5 +1,5 @@ -- | Common handler functions. -module Handler.Common where +module App.Route.Common.Handler where import App.FoundationImport import Data.FileEmbed (embedFile) diff --git a/src/Handler/Home.hs b/src/App/Route/Home/Handler.hs similarity index 97% rename from src/Handler/Home.hs rename to src/App/Route/Home/Handler.hs index 3fabb3f..23fa785 100644 --- a/src/Handler/Home.hs +++ b/src/App/Route/Home/Handler.hs @@ -1,4 +1,4 @@ -module Handler.Home where +module App.Route.Home.Handler where import App.FoundationImport import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, diff --git a/src/Application.hs b/src/Application.hs index 6779a7b..08e497b 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -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/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) From 92e0a64e8d49845b2a78626e8ab35f066ca182ed Mon Sep 17 00:00:00 2001 From: Aleksey Uimanov Date: Fri, 29 May 2015 15:02:54 +0500 Subject: [PATCH 5/5] make forms separated from `Foundation` --- PROJECTNAME.cabal | 2 ++ src/App/NoFoundationImport.hs | 7 +++++++ src/App/Route/Home/Form.hs | 13 +++++++++++++ src/App/Route/Home/Handler.hs | 8 +------- src/Foundation.hs | 3 --- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/App/Route/Home/Form.hs diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index f482f27..7207294 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -20,6 +20,7 @@ library , App.Handler , App.NoFoundationImport , App.Route.Common.Handler + , App.Route.Home.Form , App.Route.Home.Handler , Application , Foundation @@ -43,6 +44,7 @@ library , NoMonomorphismRestriction , OverloadedStrings , QuasiQuotes + , RankNTypes , RecordWildCards , TemplateHaskell , TupleSections diff --git a/src/App/NoFoundationImport.hs b/src/App/NoFoundationImport.hs index 6239557..5136aa9 100644 --- a/src/App/NoFoundationImport.hs +++ b/src/App/NoFoundationImport.hs @@ -1,5 +1,6 @@ module App.NoFoundationImport ( module Import + , Form ) where import ClassyPrelude.Yesod as Import @@ -10,3 +11,9 @@ 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/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/src/App/Route/Home/Handler.hs b/src/App/Route/Home/Handler.hs index 23fa785..e0902b2 100644 --- a/src/App/Route/Home/Handler.hs +++ b/src/App/Route/Home/Handler.hs @@ -1,8 +1,7 @@ module App.Route.Home.Handler where import App.FoundationImport -import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, - withSmallInput) +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/src/Foundation.hs b/src/Foundation.hs index eb11534..2894dea 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -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