From 0e31cd39cede0697b903b65c45a80e32d069122d Mon Sep 17 00:00:00 2001 From: ibizaman Date: Thu, 9 Dec 2021 22:59:40 -0800 Subject: [PATCH] fix: handle relative paths for haskell-language-server This is needed for both `cabal build hledger-web` and `haskell-language-server` to succeed. This was already done in the heldger-cli package for example but not in the heldger-web package. In essence, hls and stack/cabal uses different roots when embedding files in template haskell in sub-packages. Reference: https://github.com/haskell/haskell-language-server/issues/481#issuecomment-737775878 --- hledger-web/Hledger/Web/Foundation.hs | 5 +++-- hledger-web/Hledger/Web/Settings/StaticFiles.hs | 5 +++-- hledger-web/Hledger/Web/Widget/Common.hs | 3 ++- hledger-web/hledger-web.cabal | 1 + hledger-web/package.yaml | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hledger-web/Hledger/Web/Foundation.hs b/hledger-web/Hledger/Web/Foundation.hs index 5ace13192ab5..c90d3728ac5e 100644 --- a/hledger-web/Hledger/Web/Foundation.hs +++ b/hledger-web/Hledger/Web/Foundation.hs @@ -19,6 +19,7 @@ import Control.Applicative ((<|>)) import Control.Monad (join, when) import qualified Data.ByteString.Char8 as BC import Data.Traversable (for) +import Data.FileEmbed (makeRelativeToProject) import Data.IORef (IORef, readIORef, writeIORef) import Data.Maybe (fromMaybe) import Data.Text (Text) @@ -82,7 +83,7 @@ data App = App -- for our application to be in scope. However, the handler functions -- usually require access to the AppRoute datatype. Therefore, we -- split these actions into two functions and place them in separate files. -mkYesodData "App" $(parseRoutesFile "config/routes") +mkYesodData "App" $(makeRelativeToProject "config/routes" >>= parseRoutesFile) -- | A convenience alias. type AppRoute = Route App @@ -164,7 +165,7 @@ instance Yesod App where addScript $ StaticR hledger_js $(widgetFile "default-layout") - withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") + withUrlRenderer $(makeRelativeToProject "templates/default-layout-wrapper.hamlet" >>= hamletFile) #ifndef DEVELOPMENT -- This function creates static content files in the static folder diff --git a/hledger-web/Hledger/Web/Settings/StaticFiles.hs b/hledger-web/Hledger/Web/Settings/StaticFiles.hs index a63a084d9853..65c26c5b840c 100644 --- a/hledger-web/Hledger/Web/Settings/StaticFiles.hs +++ b/hledger-web/Hledger/Web/Settings/StaticFiles.hs @@ -5,6 +5,7 @@ import System.IO (stdout, hFlush) import Yesod.Static (Static, embed, publicFiles, staticDevel) import Hledger.Web.Settings (staticDir, development) +import Data.FileEmbed (makeRelativeToProject) -- | use this to create your static file serving site -- staticSite :: IO Static.Static @@ -26,6 +27,6 @@ staticSite = staticDevel staticDir) else (do -- putStrLn "Using built-in web files" >> hFlush stdout - return $(embed staticDir)) + return $(makeRelativeToProject staticDir >>= embed)) -$(publicFiles staticDir) +$(makeRelativeToProject staticDir >>= publicFiles) diff --git a/hledger-web/Hledger/Web/Widget/Common.hs b/hledger-web/Hledger/Web/Widget/Common.hs index 2ce97f20e258..9c38e1e0ae9f 100644 --- a/hledger-web/Hledger/Web/Widget/Common.hs +++ b/hledger-web/Hledger/Web/Widget/Common.hs @@ -19,6 +19,7 @@ module Hledger.Web.Widget.Common , replaceInacct ) where +import Data.FileEmbed (makeRelativeToProject) import Data.Foldable (find, for_) import Data.List (elemIndex) import Data.Text (Text) @@ -79,7 +80,7 @@ helplink topic label _ = H.a ! A.href u ! A.target "hledgerhelp" $ toHtml label -- | Render a "BalanceReport" as html. balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> Text -> [QueryOpt] -> BalanceReport -> HtmlUrl r balanceReportAsHtml (journalR, registerR) here hideEmpty j q qopts (items, total) = - $(hamletFile "templates/balance-report.hamlet") + $(makeRelativeToProject "templates/balance-report.hamlet" >>= hamletFile) where l = ledgerFromJournal Any j indent a = preEscapedString $ concat $ replicate (2 + 2 * a) " " diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 35964cd6f7c0..ae3312d09b2a 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -169,6 +169,7 @@ library , data-default , directory >=1.2.3.0 , extra >=1.6.3 + , file-embed >=0.0.10 , filepath , hjsmin , hledger >=1.23.99 && <1.24 diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index 4b2a02f8ae27..77e19c8fb2d9 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -117,6 +117,7 @@ library: - Decimal >=0.5.1 - directory >=1.2.3.0 - extra >=1.6.3 + - file-embed >=0.0.10 - filepath - hjsmin - http-conduit