From 274b5445a1ff1884fcb303c80e2a7bf2434ce9d5 Mon Sep 17 00:00:00 2001 From: Ian Duncan Date: Wed, 7 Jun 2017 20:11:01 +0900 Subject: [PATCH] Code review fixes for #1404 --- yesod-static/ChangeLog.md | 5 +++++ yesod-static/Yesod/Static.hs | 12 +++++++++++- yesod-static/yesod-static.cabal | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/yesod-static/ChangeLog.md b/yesod-static/ChangeLog.md index 7d5c9d26..7afd4396 100644 --- a/yesod-static/ChangeLog.md +++ b/yesod-static/ChangeLog.md @@ -1,3 +1,8 @@ +## 1.5.3 + +* Add `staticFilesMap` function +* Add `staticFilesMergeMap` function + ## 1.5.2 * Fix test case for CRLF line endings diff --git a/yesod-static/Yesod/Static.hs b/yesod-static/Yesod/Static.hs index 9454e681..4d8d368e 100644 --- a/yesod-static/Yesod/Static.hs +++ b/yesod-static/Yesod/Static.hs @@ -276,8 +276,10 @@ staticFilesList dir fs = publicFiles :: FilePath -> Q [Dec] publicFiles dir = mkStaticFiles' dir False --- | Similar to 'staticFilesList', but takes a manifest mapping +-- | Similar to 'staticFilesList', but takes a mapping of -- unmunged names to fingerprinted file names. +-- +-- @since 1.5.3 staticFilesMap :: FilePath -> M.Map FilePath FilePath -> Q [Dec] staticFilesMap fp m = mkStaticFilesList' fp (map splitBoth mapList) True where @@ -289,6 +291,11 @@ staticFilesMap fp m = mkStaticFilesList' fp (map splitBoth mapList) True let (a, b) = break (== '/') x in a : split (drop 1 b) +-- | Similar to 'staticFilesMergeMap', but also generates identifiers +-- for all files in the specified directory that don't have a +-- fingerprinted version. +-- +-- @since 1.5.3 staticFilesMergeMap :: FilePath -> M.Map FilePath FilePath -> Q [Dec] staticFilesMergeMap fp m = do fs <- qRunIO $ getFileListPieces fp @@ -305,6 +312,9 @@ staticFilesMergeMap fp m = do split x = let (a, b) = break (== '/') x in a : split (drop 1 b) + -- We want to keep mappings for all files that are pre-fingerprinted, + -- so this function checks against all of the existing fingerprinted files and + -- only inserts a new mapping if it's not a fingerprinted file. checkedInsert :: M.Map FilePath FilePath -- inverted dictionary -> M.Map FilePath FilePath -- accumulating state diff --git a/yesod-static/yesod-static.cabal b/yesod-static/yesod-static.cabal index 297cc452..9fe49537 100644 --- a/yesod-static/yesod-static.cabal +++ b/yesod-static/yesod-static.cabal @@ -1,5 +1,5 @@ name: yesod-static -version: 1.5.2 +version: 1.5.3 license: MIT license-file: LICENSE author: Michael Snoyman