From 0e7b713a8051da5b1feb6afad96c5f226cbeb6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Z=C3=A1rybnick=C3=BD?= Date: Sat, 9 Jun 2018 17:23:18 +0200 Subject: [PATCH] web: Simplify hledgerLayout into defaultLayout --- hledger-web/src/Foundation.hs | 94 ++++++---- hledger-web/src/Handler/AddR.hs | 2 +- hledger-web/src/Handler/Common.hs | 194 ++++++-------------- hledger-web/src/Handler/JournalR.hs | 34 ++-- hledger-web/src/Handler/RegisterR.hs | 19 +- hledger-web/templates/default-layout.hamlet | 36 +++- 6 files changed, 173 insertions(+), 206 deletions(-) diff --git a/hledger-web/src/Foundation.hs b/hledger-web/src/Foundation.hs index 554042067..7bf5427b5 100644 --- a/hledger-web/src/Foundation.hs +++ b/hledger-web/src/Foundation.hs @@ -9,8 +9,10 @@ import Data.IORef (IORef, readIORef, writeIORef) import Data.List (isPrefixOf) import Data.Maybe (fromMaybe) import Data.Text (Text) +import qualified Data.Text as T import Data.Time.Calendar (Day) import Network.HTTP.Conduit (Manager) +import System.FilePath (takeFileName) import Text.Blaze (Markup) import Text.Blaze.Html.Renderer.String (renderHtml) import Text.Hamlet (hamletFile) @@ -19,6 +21,7 @@ import Yesod.Static import Yesod.Default.Config import Handler.AddForm +import Handler.Common (balanceReportAsHtml) import Settings.StaticFiles import Settings (widgetFile, Extra (..)) #ifndef DEVELOPMENT @@ -28,7 +31,7 @@ import Yesod.Default.Util (addStaticContentExternal) #endif import Hledger -import Hledger.Cli +import Hledger.Cli (CliOpts(..), journalReloadIfChanged) import Hledger.Web.WebOptions -- | The site argument for your application. This can be a good place to @@ -78,50 +81,63 @@ 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 - approot = ApprootMaster $ appRoot . settings + approot = ApprootMaster $ appRoot . settings - -- don't use session data - makeSessionBackend _ = return Nothing + -- don't use session data + makeSessionBackend _ = return Nothing - defaultLayout widget = do - master <- getYesod - lastmsg <- getMessage - VD{j, opts} <- getViewData + defaultLayout widget = do + master <- getYesod + lastmsg <- getMessage + VD{am, here, j, opts, q, qopts, showsidebar} <- getViewData - -- We break up the default layout into two components: - -- default-layout is the contents of the body tag, and - -- default-layout-wrapper is the entire page. Since the final - -- value passed to hamletToRepHtml cannot be a widget, this allows - -- you to use normal widget features in default-layout. - pc <- widgetToPageContent $ do - addStylesheet $ StaticR css_bootstrap_min_css - addStylesheet $ StaticR css_bootstrap_datepicker_standalone_min_css - -- load these things early, in HEAD: - toWidgetHead [hamlet| -