Skip to content

Commit 0e31cd3

Browse files
committed
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: haskell/haskell-language-server#481 (comment)
1 parent 55f5aa9 commit 0e31cd3

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

hledger-web/Hledger/Web/Foundation.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Control.Applicative ((<|>))
1919
import Control.Monad (join, when)
2020
import qualified Data.ByteString.Char8 as BC
2121
import Data.Traversable (for)
22+
import Data.FileEmbed (makeRelativeToProject)
2223
import Data.IORef (IORef, readIORef, writeIORef)
2324
import Data.Maybe (fromMaybe)
2425
import Data.Text (Text)
@@ -82,7 +83,7 @@ data App = App
8283
-- for our application to be in scope. However, the handler functions
8384
-- usually require access to the AppRoute datatype. Therefore, we
8485
-- split these actions into two functions and place them in separate files.
85-
mkYesodData "App" $(parseRoutesFile "config/routes")
86+
mkYesodData "App" $(makeRelativeToProject "config/routes" >>= parseRoutesFile)
8687

8788
-- | A convenience alias.
8889
type AppRoute = Route App
@@ -164,7 +165,7 @@ instance Yesod App where
164165
addScript $ StaticR hledger_js
165166
$(widgetFile "default-layout")
166167

167-
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
168+
withUrlRenderer $(makeRelativeToProject "templates/default-layout-wrapper.hamlet" >>= hamletFile)
168169

169170
#ifndef DEVELOPMENT
170171
-- This function creates static content files in the static folder

hledger-web/Hledger/Web/Settings/StaticFiles.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import System.IO (stdout, hFlush)
55
import Yesod.Static (Static, embed, publicFiles, staticDevel)
66

77
import Hledger.Web.Settings (staticDir, development)
8+
import Data.FileEmbed (makeRelativeToProject)
89

910
-- | use this to create your static file serving site
1011
-- staticSite :: IO Static.Static
@@ -26,6 +27,6 @@ staticSite =
2627
staticDevel staticDir)
2728
else (do
2829
-- putStrLn "Using built-in web files" >> hFlush stdout
29-
return $(embed staticDir))
30+
return $(makeRelativeToProject staticDir >>= embed))
3031

31-
$(publicFiles staticDir)
32+
$(makeRelativeToProject staticDir >>= publicFiles)

hledger-web/Hledger/Web/Widget/Common.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Hledger.Web.Widget.Common
1919
, replaceInacct
2020
) where
2121

22+
import Data.FileEmbed (makeRelativeToProject)
2223
import Data.Foldable (find, for_)
2324
import Data.List (elemIndex)
2425
import Data.Text (Text)
@@ -79,7 +80,7 @@ helplink topic label _ = H.a ! A.href u ! A.target "hledgerhelp" $ toHtml label
7980
-- | Render a "BalanceReport" as html.
8081
balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> Text -> [QueryOpt] -> BalanceReport -> HtmlUrl r
8182
balanceReportAsHtml (journalR, registerR) here hideEmpty j q qopts (items, total) =
82-
$(hamletFile "templates/balance-report.hamlet")
83+
$(makeRelativeToProject "templates/balance-report.hamlet" >>= hamletFile)
8384
where
8485
l = ledgerFromJournal Any j
8586
indent a = preEscapedString $ concat $ replicate (2 + 2 * a) "&nbsp;"

hledger-web/hledger-web.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ library
169169
, data-default
170170
, directory >=1.2.3.0
171171
, extra >=1.6.3
172+
, file-embed >=0.0.10
172173
, filepath
173174
, hjsmin
174175
, hledger >=1.23.99 && <1.24

hledger-web/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ library:
117117
- Decimal >=0.5.1
118118
- directory >=1.2.3.0
119119
- extra >=1.6.3
120+
- file-embed >=0.0.10
120121
- filepath
121122
- hjsmin
122123
- http-conduit

0 commit comments

Comments
 (0)