Skip to content

Commit

Permalink
fix: handle relative paths for haskell-language-server
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ibizaman committed Dec 13, 2021
1 parent 8759d26 commit 36e8f83
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions hledger-web/Hledger/Web/Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion hledger-web/Hledger/Web/Handler/RegisterR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Hledger.Web.Widget.AddForm (addModal)
import Hledger.Web.Widget.Common
(accountQuery, mixedAmountAsHtml,
transactionFragment, removeDates, removeInacct, replaceInacct)
import Data.FileEmbed (makeRelativeToProject)

-- | The main journal/account register view, with accounts sidebar.
getRegisterR :: Handler Html
Expand Down Expand Up @@ -99,7 +100,7 @@ decorateLinks = concatMap $ \(acct, (name, comma)) ->
-- | Generate javascript/html for a register balance line chart based on
-- the provided "AccountTransactionsReportItem"s.
registerChartHtml :: Text -> String -> [(CommoditySymbol, [AccountTransactionsReportItem])] -> HtmlUrl AppRoute
registerChartHtml q title percommoditytxnreports = $(hamletFile "templates/chart.hamlet")
registerChartHtml q title percommoditytxnreports = $(makeRelativeToProject "templates/chart.hamlet" >>= hamletFile)
-- have to make sure plot is not called when our container (maincontent)
-- is hidden, eg with add form toggled
where
Expand Down
5 changes: 3 additions & 2 deletions hledger-web/Hledger/Web/Settings/StaticFiles.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
3 changes: 2 additions & 1 deletion hledger-web/Hledger/Web/Widget/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) "&nbsp;"
Expand Down
1 change: 1 addition & 0 deletions hledger-web/hledger-web.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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.24.99 && <1.25
Expand Down
1 change: 1 addition & 0 deletions hledger-web/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36e8f83

Please sign in to comment.