Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit db0049c

Browse files
authored
Merge pull request #791 from deckgo/nm-header-footer
infra: Read and inject header and footer
2 parents a9ebf9c + d081b80 commit db0049c

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

infra/handler/app/Test.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ testPresDeploys = withQueueName $ withEnv $ \env -> withSQS env $ withS3 env $ d
173173
, presentationOwner = someUserId
174174
, presentationAttributes = HMS.empty
175175
, presentationBackground = Nothing
176+
, presentationHeader = Nothing
177+
, presentationFooter = Nothing
176178
, presentationDescription = ""
177179
, presentationHeadExtra = Nothing
178180
}

infra/handler/src/DeckGo/Handler.hs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ newtype PresentationBackground = PresentationBackground { unPresentationBackgrou
244244
deriving stock (Show, Eq)
245245
deriving newtype (Aeson.FromJSON, Aeson.ToJSON)
246246

247+
newtype PresentationHeader = PresentationHeader { unPresentationHeader :: T.Text }
248+
deriving stock (Show, Eq)
249+
deriving newtype (Aeson.FromJSON, Aeson.ToJSON)
250+
251+
newtype PresentationFooter = PresentationFooter { unPresentationFooter :: T.Text }
252+
deriving stock (Show, Eq)
253+
deriving newtype (Aeson.FromJSON, Aeson.ToJSON)
254+
247255
-- SLIDES
248256

249257
instance ToSchema Slide where
@@ -312,6 +320,8 @@ data PresentationInfo = PresentationInfo
312320
{ presentationName :: PresentationName
313321
, presentationOwner :: UserId
314322
, presentationBackground :: Maybe PresentationBackground
323+
, presentationHeader :: Maybe PresentationHeader
324+
, presentationFooter :: Maybe PresentationFooter
315325
, presentationAttributes :: HMS.HashMap T.Text T.Text
316326
, presentationSlides :: [Slide]
317327
, presentationDescription :: T.Text
@@ -331,6 +341,8 @@ instance FromJSONObject PresentationInfo where
331341
obj .: "name" <*>
332342
obj .: "owner_id" <*>
333343
obj .:? "background" <*>
344+
obj .:? "header" <*>
345+
obj .:? "footer" <*>
334346
obj .:? "attributes" .!= HMS.empty <*>
335347
obj .: "slides" <*>
336348
obj .: "description" <*>
@@ -1325,11 +1337,17 @@ type Tag = TagSoup.Tag T.Text
13251337
processTags :: PresentationInfo -> [Tag] -> [Tag]
13261338
processTags presentationInfo = concatMap $ \case
13271339
TagSoup.TagOpen str (HMS.fromList -> attrs)
1340+
-- If the tag is 'deckgo-deck', we add the slides and the "background",
1341+
-- "header" and "footer" divs
13281342
| str == "deckgo-deck" -> do
13291343
[ TagSoup.TagOpen str (HMS.toList (presentationAttributes presentationInfo <> attrs)) ] <>
13301344
(concatMap slideTags (presentationSlides presentationInfo)) <>
13311345
(maybe [] presentationBackgroundTags
1332-
(presentationBackground presentationInfo))
1346+
(presentationBackground presentationInfo)) <>
1347+
(maybe [] presentationHeaderTags
1348+
(presentationHeader presentationInfo)) <>
1349+
(maybe [] presentationFooterTags
1350+
(presentationFooter presentationInfo))
13331351
t -> [t]
13341352

13351353
presentationBackgroundTags :: PresentationBackground -> [Tag]
@@ -1339,6 +1357,20 @@ presentationBackgroundTags (unPresentationBackground -> bg) =
13391357
[ TagSoup.TagClose "div"
13401358
]
13411359

1360+
presentationHeaderTags :: PresentationHeader -> [Tag]
1361+
presentationHeaderTags (unPresentationHeader -> bg) =
1362+
[ TagSoup.TagOpen "div" (HMS.toList $ HMS.singleton "slot" "header")
1363+
] <> TagSoup.parseTags bg <>
1364+
[ TagSoup.TagClose "div"
1365+
]
1366+
1367+
presentationFooterTags :: PresentationFooter -> [Tag]
1368+
presentationFooterTags (unPresentationFooter -> bg) =
1369+
[ TagSoup.TagOpen "div" (HMS.toList $ HMS.singleton "slot" "footer")
1370+
] <> TagSoup.parseTags bg <>
1371+
[ TagSoup.TagClose "div"
1372+
]
1373+
13421374
slideTags :: Slide -> [Tag]
13431375
slideTags slide =
13441376
[ TagSoup.TagOpen

0 commit comments

Comments
 (0)