require $& for whitespace before or after a builder

This commit is contained in:
rhiannon morris 2024-08-21 07:40:28 +02:00
parent d18c19a2e6
commit 035aa78920
4 changed files with 16 additions and 10 deletions

View file

@ -18,9 +18,15 @@ import Data.List.NonEmpty (NonEmpty, toList)
data Chunk = Lit String | Var String
-- |
-- * use @$var@ to insert a variable (instance of 'CanBuild')
-- * use @$&@ to insert nothing like @\&@ in a string (e.g. to add whitespace
-- at the start or end, or to have a variable followed by a letter
-- * use @$$@ for a literal @$@
parseB :: String -> ExpQ
parseB = toExpQ . reverse . go "" [] . trim where
trim = dropWhileEnd isSpace . dropWhile (== '\n')
trim = dropWhileEnd isSpace . dropWhile isSpace
go acc cs [] = addLit acc cs
go acc cs ('$':'&':rest) = go acc cs rest -- $&: expands to nothing
go acc cs ('$':'$':rest) = go ('$' : acc) cs rest -- $$: expands to one $

View file

@ -129,8 +129,8 @@ makeFilter prefix initial tag count = [b|
where
id' = [b|$prefix$&_$tag'|]
tag' = escId tag
checked = if HashSet.member tag initial then [b| checked|] else ""
hidden = if count <= 1 then [b| hidden|] else ""
checked = if HashSet.member tag initial then [b|$& checked|] else ""
hidden = if count <= 1 then [b|$& hidden|] else ""
makeYearItems :: Bool -- ^ nsfw
-> Int -- ^ year
@ -159,12 +159,12 @@ makeItem nsfw file info@(Info {bg}) = [b|
title = fromMaybe info.title $ info.galleryTitle
dir = takeDirectory file
thumbnail = getThumb dir info
nsfw' = if nsfw && anyNsfw info then [b| nsfw|] else ""
nsfw' = if nsfw && anyNsfw info then [b|$& nsfw|] else ""
tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info
date = latestDateFor nsfw info
date' = formatTooltip date
year' = date.year
updated' = if hasUpdatesFor nsfw info then [b|true|] else [b|false|]
bgStyle = case bg of Other col -> [b| style="background: $col"|]; _ -> ""
bgStyle = case bg of Other col -> [b|$& style="background: $col"|]; _ -> ""
tooltip = [b|$title ($upd$date')|]
where upd = if hasUpdatesFor nsfw info then "updated " else "" :: Builder

View file

@ -74,13 +74,13 @@ makeItem :: GalleryInfo -> Builder
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|
<li$nsfw><a href=$prefix title="$desc">$title</a></li>
|]
where nsfw = if hasNsfw filters then [b| class=nsfw|] else ""
where nsfw = if hasNsfw filters then [b|$& class=nsfw|] else ""
makeLink :: Link -> Builder
makeLink (Link {title, url, nsfw}) = [b|
<li$nsfw'><a href=$url>$title</a>
|]
where nsfw' = if nsfw then [b| class=nsfw|] else ""
where nsfw' = if nsfw then [b|$& class=nsfw|] else ""
hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw

View file

@ -302,11 +302,11 @@ altButton img i = [b|
|]
where
Image {label, nsfw, warning, download} = img
nsfwClass = if nsfw then [b| class=nsfw|] else ""
nsfwLabelClass = if nsfw then [b| class=nsfw-label|] else ""
nsfwClass = if nsfw then [b|$& class=nsfw|] else ""
nsfwLabelClass = if nsfw then [b|$& class=nsfw-label|] else ""
path' = pageFile img
link = fromMaybe (bigFile img) download
warning' = ifJust warning \(escAttr -> w) -> [b| data-warning="$w"|]
warning' = ifJust warning \(escAttr -> w) -> [b|$& data-warning="$w"|]
makeTags :: FilePath -> [Strict.Text] -> Builder
makeTags undir tags =