From 19d55076a400b16177653baa9f468d0d6a9a8a57 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 14 May 2013 15:36:44 -0700 Subject: [PATCH] web: require yesod 1.2, cabal file cleanup --- hledger-web/Application.hs | 2 +- hledger-web/Foundation.hs | 11 +- hledger-web/Handler/Utils.hs | 6 - hledger-web/hledger-web.cabal | 324 +++++++++++++++----------------- hledger-web/tests/HomeTest.hs | 9 +- hledger-web/tests/TestImport.hs | 5 +- hledger-web/tests/main.hs | 10 +- 7 files changed, 170 insertions(+), 197 deletions(-) diff --git a/hledger-web/Application.hs b/hledger-web/Application.hs index e20cbc7a7..881d9fa70 100644 --- a/hledger-web/Application.hs +++ b/hledger-web/Application.hs @@ -62,6 +62,6 @@ getApplicationDev = do j <- either error' id `fmap` readJournalFile Nothing Nothing f defaultDevelApp loader (makeApplication defwebopts j) where - loader = loadConfig (configSettings Development) + loader = Yesod.Default.Config.loadConfig (configSettings Development) { csParseExtra = parseExtra } diff --git a/hledger-web/Foundation.hs b/hledger-web/Foundation.hs index 8ee3aa2d8..80f4bb86f 100644 --- a/hledger-web/Foundation.hs +++ b/hledger-web/Foundation.hs @@ -23,7 +23,6 @@ import Settings (widgetFile, Extra (..)) import Settings (staticDir) import Text.Jasmine (minifym) #endif -import Web.ClientSession (getKey) import Text.Hamlet (hamletFile) import Hledger.Web.Options @@ -72,7 +71,7 @@ mkYesodData "App" $(parseRoutesFile "config/routes") -- | A convenience alias. type AppRoute = Route App -type Form x = Html -> MForm App App (FormResult x, Widget) +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. @@ -81,11 +80,9 @@ instance Yesod App where -- Store session data on the client in encrypted cookies, -- default session idle timeout is 120 minutes - makeSessionBackend _ = do - key <- getKey ".hledger-web_client_session_key.aes" - let timeout = fromIntegral (120 * 60 :: Int) -- 120 minutes - (getCachedDate, _closeDateCacher) <- clientSessionDateCacher timeout - return . Just $ clientSessionBackend2 key getCachedDate + makeSessionBackend _ = fmap Just $ defaultClientSessionBackend + (120 * 60) + ".hledger-web_client_session_key.aes" defaultLayout widget = do master <- getYesod diff --git a/hledger-web/Handler/Utils.hs b/hledger-web/Handler/Utils.hs index f957cf01a..91b6562ff 100644 --- a/hledger-web/Handler/Utils.hs +++ b/hledger-web/Handler/Utils.hs @@ -4,7 +4,6 @@ module Handler.Utils where import Prelude import Control.Applicative ((<$>)) -import Control.Monad.IO.Class (liftIO) import Data.IORef import Data.Maybe import Data.Text(pack,unpack) @@ -12,11 +11,6 @@ import Data.Time.Calendar import Data.Time.Clock import Data.Time.Format import System.Locale (defaultTimeLocale) -#if BLAZE_HTML_0_4 -import Text.Blaze (toHtml) -#else -import Text.Blaze.Html (toHtml) -#endif import Text.Hamlet import Yesod.Core diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 944d66c50..ede57363e 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -1,6 +1,5 @@ name: hledger-web --- also in cpp-options below -version: 0.20.98 +version: 0.20.98 category: Finance synopsis: A web interface for the hledger accounting tool. description: @@ -46,22 +45,17 @@ extra-source-files: templates/normalize.lucius source-repository head - type: git - location: https://github.com/simonmichael/hledger - --- Flag production --- Description: Build fully optimised and with web files embedded (not loaded from ./static/) --- Default: True + type: git + location: https://github.com/simonmichael/hledger flag threaded Description: Build with support for multithreaded execution. Default: True flag blaze_html_0_4 - description: Use the older 0.4 version of blaze-html. + description: Use the older 0.4 version of blaze-html. No longer well tested. default: False - flag dev Description: Turn on development settings, like auto-reload templates. Default: False @@ -70,39 +64,13 @@ flag library-only Description: Build for use with "yesod devel" Default: False - library - hs-source-dirs: . app - - exposed-modules: Application - Foundation - Import - Settings - Settings.StaticFiles - Settings.Development - Handler.Common - Handler.JournalEditR - Handler.JournalEntriesR - Handler.JournalR - Handler.Post - Handler.RegisterR - Handler.RootR - Handler.Utils - other-modules: - Hledger.Web - Hledger.Web.Main - Hledger.Web.Options - - -- if flag(library-only) - -- Buildable: True - -- else - -- Buildable: False - - ghc-options: -Wall -fno-warn-unused-do-bind cpp-options: -DVERSION="0.20.98" if flag(dev) || flag(library-only) - cpp-options: -DDEVELOPMENT - + cpp-options: -DDEVELOPMENT + + ghc-options: -Wall -fno-warn-unused-do-bind + extensions: TemplateHaskell QuasiQuotes OverloadedStrings @@ -117,161 +85,167 @@ library NoMonomorphismRestriction RecordWildCards - build-depends: base >= 4 && < 5 - , yesod-platform >= 1.2 && < 1.3 - -- , yesod >= 1.1.3 && < 1.2 - -- , yesod-core >= 1.1.7 && < 1.2 - -- , yesod-static >= 1.1 && < 1.2 - -- , yesod-default >= 1.1 && < 1.2 - -- , yesod-form >= 1.1 && < 1.3 - -- , clientsession - -- , bytestring >= 0.9 && < 0.11 - -- , text >= 0.11 && < 0.12 - -- , template-haskell - -- , hamlet >= 1.1 && < 1.2 - -- , shakespeare-css >= 1.0 && < 1.1 - -- , shakespeare-js >= 1.0 && < 1.2 - -- , shakespeare-text >= 1.0 && < 1.1 - -- , hjsmin >= 0.1 && < 0.2 - -- , monad-control >= 0.3 && < 0.4 - -- , wai-extra >= 1.3 && < 1.4 - -- , yaml >= 0.8 && < 0.9 - -- , http-conduit >= 1.8 && < 1.10 - -- , directory >= 1.1 && < 1.3 - -- , warp >= 1.3 && < 1.4 - -- , data-default - - , hledger == 0.20.98 - , hledger-lib == 0.20.98 - , cmdargs >= 0.10 && < 0.11 + hs-source-dirs: . app + exposed-modules: Application + Foundation + Import + Settings + Settings.StaticFiles + Settings.Development + Handler.Common + Handler.JournalEditR + Handler.JournalEntriesR + Handler.JournalR + Handler.Post + Handler.RegisterR + Handler.RootR + Handler.Utils + other-modules: + Hledger.Web + Hledger.Web.Main + Hledger.Web.Options + -- Setup -- stops yesod devel complaining, requires build-depends: Cabal + build-depends: + hledger == 0.20.98 + , hledger-lib == 0.20.98 + , base >= 4 && < 5 + , bytestring + , clientsession + , cmdargs >= 0.10 && < 0.11 + , data-default , directory , filepath + , hamlet + , hjsmin + , http-conduit , HUnit , network-conduit , old-locale , parsec - , regexpr >= 0.5.1 - , safe >= 0.2 + , regexpr >= 0.5.1 + , safe >= 0.2 + , shakespeare-text + , template-haskell + , text , time , transformers , wai , wai-extra - , wai-handler-launch >= 1.3 && < 1.4 + , wai-handler-launch >= 1.3 && < 1.4 , warp , yaml - - -- if flag(blaze_html_0_4) - -- cpp-options: -DBLAZE_HTML_0_4 - -- build-depends: - -- blaze-html >= 0.4 && < 0.5 - -- else - build-depends: + , yesod + , yesod-core + , yesod-platform >= 1.2 && < 1.3 + , yesod-static + if flag(blaze_html_0_4) + cpp-options: -DBLAZE_HTML_0_4 + build-depends: + blaze-html >= 0.4 && < 0.5 + else + build-depends: blaze-html >= 0.5 && < 0.7 , blaze-markup >= 0.5.1 && < 0.7 --- executable hledger-web --- cpp-options: -DVERSION="0.20.98" +executable hledger-web + if flag(library-only) + Buildable: False --- if flag(library-only) --- Buildable: False + cpp-options: -DVERSION="0.20.98" + if flag(dev) + cpp-options: -DDEVELOPMENT --- if flag(dev) --- cpp-options: -DDEVELOPMENT --- ghc-options: -O0 -Wall -fno-warn-unused-do-bind --- else --- ghc-options: -O2 -Wall -fno-warn-unused-do-bind + ghc-options: -Wall -fno-warn-unused-do-bind + if flag(threaded) + ghc-options: -threaded + if flag(dev) + ghc-options: -O0 + else + ghc-options: -O2 --- if flag(threaded) --- ghc-options: -threaded + extensions: TemplateHaskell + QuasiQuotes + OverloadedStrings + NoImplicitPrelude + CPP + OverloadedStrings + MultiParamTypeClasses + TypeFamilies + RecordWildCards --- extensions: TemplateHaskell --- QuasiQuotes --- OverloadedStrings --- NoImplicitPrelude --- CPP --- OverloadedStrings --- MultiParamTypeClasses --- TypeFamilies --- RecordWildCards + hs-source-dirs: . app + main-is: main.hs + other-modules: + Application + Foundation + Import + Settings + Settings.StaticFiles + Settings.Development + Handler.Common + Handler.JournalEditR + Handler.JournalEntriesR + Handler.JournalR + Handler.Post + Handler.RegisterR + Handler.RootR + Handler.Utils + Hledger.Web + Hledger.Web.Main + Hledger.Web.Options --- hs-source-dirs: . app + build-depends: + hledger == 0.20.98 + , hledger-lib == 0.20.98 + , base >= 4 && < 5 + , bytestring + , clientsession + , cmdargs >= 0.10 && < 0.11 + , data-default + , directory + , filepath + , hamlet + , hjsmin + , http-conduit + , HUnit + , network-conduit + , old-locale + , parsec + , regexpr >= 0.5.1 + , safe >= 0.2 + , shakespeare-text + , template-haskell + , text + , time + , transformers + , wai + , wai-extra + , wai-handler-launch >= 1.3 && < 1.4 + , warp + , yaml + , yesod + , yesod-core + , yesod-platform >= 1.2 && < 1.3 + , yesod-static --- main-is: main.hs --- other-modules: --- Application --- Foundation --- Import --- Settings --- Settings.StaticFiles --- Settings.Development --- Handler.Common --- Handler.JournalEditR --- Handler.JournalEntriesR --- Handler.JournalR --- Handler.Post --- Handler.RegisterR --- Handler.RootR --- Handler.Utils --- Hledger.Web --- Hledger.Web.Main --- Hledger.Web.Options + if flag(blaze_html_0_4) + cpp-options: -DBLAZE_HTML_0_4 + build-depends: + blaze-html >= 0.4 && < 0.5 + else + build-depends: + blaze-html >= 0.5 && < 0.7 + , blaze-markup >= 0.5.1 && < 0.7 --- build-depends: --- hledger-web --- , hledger == 0.20.0.1 --- , hledger-lib == 0.20.0.1 --- , base >= 4.3 && < 5 --- , cmdargs >= 0.10 && < 0.11 --- , directory --- , filepath --- , HUnit --- , old-locale --- , parsec --- , regexpr >= 0.5.1 --- , safe >= 0.2 --- , time - --- -- , yesod-platform == 1.1.* --- , yesod >= 1.1.3 && < 1.2 --- , yesod-core >= 1.1.7 && < 1.2 --- , yesod-default --- , yesod-static --- , clientsession --- , hamlet --- , network-conduit --- , shakespeare-text --- , template-haskell --- , text --- , transformers --- , wai --- , wai-extra --- , wai-handler-launch >= 1.3 && < 1.4 --- , warp --- , yaml --- , hjsmin >= 0.1 && < 0.2 --- , http-conduit >= 1.8 && < 1.10 --- , data-default - --- if flag(blaze_html_0_4) --- cpp-options: -DBLAZE_HTML_0_4 --- build-depends: --- blaze-html >= 0.4 && < 0.5 --- else --- build-depends: --- blaze-html >= 0.5 && < 0.7 --- , blaze-markup >= 0.5.1 && < 0.7 - - --- test-suite test --- type: exitcode-stdio-1.0 --- main-is: main.hs --- hs-source-dirs: tests --- ghc-options: -Wall - --- build-depends: --- base --- , hledger-web --- , yesod-test >= 0.3 && < 0.4 --- , yesod-default --- , yesod-core >= 1.1.7 && < 1.2 +test-suite test + type: exitcode-stdio-1.0 + ghc-options: -Wall + hs-source-dirs: tests + main-is: main.hs + build-depends: + hledger-web + , base + , hspec + , yesod >= 1.2 && < 1.3 + , yesod-test >= 1.2 && < 1.3 diff --git a/hledger-web/tests/HomeTest.hs b/hledger-web/tests/HomeTest.hs index 8f44dc362..ad762a345 100644 --- a/hledger-web/tests/HomeTest.hs +++ b/hledger-web/tests/HomeTest.hs @@ -7,11 +7,12 @@ import TestImport homeSpecs :: Specs homeSpecs = - describe "These are some example tests" $ - it "loads the index and checks it looks right" $ do - get_ "/register" + ydescribe "Some hledger-web tests" $ + + yit "serves a reasonable-looking register page" $ do + get RegisterR statusIs 200 - -- htmlAllContain "h1" "hledger" + bodyContains "accounts" -- post "/" $ do -- addNonce diff --git a/hledger-web/tests/TestImport.hs b/hledger-web/tests/TestImport.hs index fefdb3522..19d1f3edc 100644 --- a/hledger-web/tests/TestImport.hs +++ b/hledger-web/tests/TestImport.hs @@ -1,9 +1,12 @@ {-# LANGUAGE OverloadedStrings #-} module TestImport ( module Yesod.Test + , module Foundation , Specs ) where import Yesod.Test -type Specs = SpecsConn () +import Foundation + +type Specs = YesodSpec App diff --git a/hledger-web/tests/main.hs b/hledger-web/tests/main.hs index 2e647792f..340b37255 100644 --- a/hledger-web/tests/main.hs +++ b/hledger-web/tests/main.hs @@ -7,13 +7,17 @@ module Main where import Import import Yesod.Default.Config import Yesod.Test +import Test.Hspec (hspec) import Application (makeFoundation) import HomeTest main :: IO () main = do - conf <- loadConfig $ (configSettings Testing) { csParseExtra = parseExtra } + conf <- Yesod.Default.Config.loadConfig $ (configSettings Testing) + { csParseExtra = parseExtra + } foundation <- makeFoundation conf - app <- toWaiAppPlain foundation - runTests app (error "No database available") homeSpecs + hspec $ do + yesodSpec foundation $ do + homeSpecs