require $& for whitespace before or after a builder
This commit is contained in:
parent
d18c19a2e6
commit
035aa78920
4 changed files with 16 additions and 10 deletions
|
@ -18,9 +18,15 @@ import Data.List.NonEmpty (NonEmpty, toList)
|
||||||
|
|
||||||
data Chunk = Lit String | Var String
|
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 :: String -> ExpQ
|
||||||
parseB = toExpQ . reverse . go "" [] . trim where
|
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 [] = addLit acc cs
|
||||||
go acc cs ('$':'&':rest) = go acc cs rest -- $&: expands to nothing
|
go acc cs ('$':'&':rest) = go acc cs rest -- $&: expands to nothing
|
||||||
go acc cs ('$':'$':rest) = go ('$' : acc) cs rest -- $$: expands to one $
|
go acc cs ('$':'$':rest) = go ('$' : acc) cs rest -- $$: expands to one $
|
||||||
|
|
|
@ -129,8 +129,8 @@ makeFilter prefix initial tag count = [b|
|
||||||
where
|
where
|
||||||
id' = [b|$prefix$&_$tag'|]
|
id' = [b|$prefix$&_$tag'|]
|
||||||
tag' = escId tag
|
tag' = escId tag
|
||||||
checked = if HashSet.member tag initial then [b| checked|] else ""
|
checked = if HashSet.member tag initial then [b|$& checked|] else ""
|
||||||
hidden = if count <= 1 then [b| hidden|] else ""
|
hidden = if count <= 1 then [b|$& hidden|] else ""
|
||||||
|
|
||||||
makeYearItems :: Bool -- ^ nsfw
|
makeYearItems :: Bool -- ^ nsfw
|
||||||
-> Int -- ^ year
|
-> Int -- ^ year
|
||||||
|
@ -159,12 +159,12 @@ makeItem nsfw file info@(Info {bg}) = [b|
|
||||||
title = fromMaybe info.title $ info.galleryTitle
|
title = fromMaybe info.title $ info.galleryTitle
|
||||||
dir = takeDirectory file
|
dir = takeDirectory file
|
||||||
thumbnail = getThumb dir info
|
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
|
tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info
|
||||||
date = latestDateFor nsfw info
|
date = latestDateFor nsfw info
|
||||||
date' = formatTooltip date
|
date' = formatTooltip date
|
||||||
year' = date.year
|
year' = date.year
|
||||||
updated' = if hasUpdatesFor nsfw info then [b|true|] else [b|false|]
|
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')|]
|
tooltip = [b|$title ($upd$date')|]
|
||||||
where upd = if hasUpdatesFor nsfw info then "updated " else "" :: Builder
|
where upd = if hasUpdatesFor nsfw info then "updated " else "" :: Builder
|
||||||
|
|
|
@ -74,13 +74,13 @@ makeItem :: GalleryInfo -> Builder
|
||||||
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|
|
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|
|
||||||
<li$nsfw><a href=$prefix title="$desc">$title</a></li>
|
<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 -> Builder
|
||||||
makeLink (Link {title, url, nsfw}) = [b|
|
makeLink (Link {title, url, nsfw}) = [b|
|
||||||
<li$nsfw'><a href=$url>$title</a>
|
<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 -> Bool
|
||||||
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw
|
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw
|
||||||
|
|
|
@ -302,11 +302,11 @@ altButton img i = [b|
|
||||||
|]
|
|]
|
||||||
where
|
where
|
||||||
Image {label, nsfw, warning, download} = img
|
Image {label, nsfw, warning, download} = img
|
||||||
nsfwClass = if nsfw then [b| class=nsfw|] else ""
|
nsfwClass = if nsfw then [b|$& class=nsfw|] else ""
|
||||||
nsfwLabelClass = if nsfw then [b| class=nsfw-label|] else ""
|
nsfwLabelClass = if nsfw then [b|$& class=nsfw-label|] else ""
|
||||||
path' = pageFile img
|
path' = pageFile img
|
||||||
link = fromMaybe (bigFile img) download
|
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 :: FilePath -> [Strict.Text] -> Builder
|
||||||
makeTags undir tags =
|
makeTags undir tags =
|
||||||
|
|
Loading…
Reference in a new issue