Make jsAttributesHandler use jsAttributes

This addresses this comment:

https://github.com/yesodweb/yesod/pull/1622#discussion_r317467498
This commit is contained in:
Jezen Thomas 2019-08-26 12:03:53 +02:00
parent 59988f46a1
commit d1e4fd485b
No known key found for this signature in database
GPG key ID: 5FEF410819FCBDB7

View file

@ -252,13 +252,12 @@ class RenderRoute site => Yesod site where
-- | Same as @jsAttributes@ but allows you to run arbitrary Handler code
--
-- This is useful if you need to add a randomised nonce value to the script
-- tag generated by @widgetFile@. If you use both this function and
-- @jsAttributes@, the two attribute maps will be merged, favouring the
-- keys from @jsAttributes@ in case of a collision.
-- tag generated by @widgetFile@. If this function is overridden then
-- @jsAttributes@ is ignored.
--
-- @since 1.6.16
jsAttributesHandler :: HandlerFor site [(Text, Text)]
jsAttributesHandler = pure []
jsAttributesHandler = getYesod >>= return . jsAttributes
-- | Create a session backend. Returning 'Nothing' disables
-- sessions. If you'd like to change the way that the session
@ -532,7 +531,7 @@ widgetToPageContent :: Yesod site
=> WidgetFor site ()
-> HandlerFor site (PageContent (Route site))
widgetToPageContent w = do
jsAttrsFromHandler <- jsAttributesHandler
jsAttrs <- jsAttributesHandler
HandlerFor $ \hd -> do
master <- unHandlerFor getYesod hd
ref <- newIORef mempty
@ -544,10 +543,6 @@ widgetToPageContent w = do
let title = maybe mempty unTitle mTitle
scripts = runUniqueList scripts'
stylesheets = runUniqueList stylesheets'
jsAttrs =
let jsAttrsStatic = Map.fromList (jsAttributes master)
jsAttrsDynamic = Map.fromList jsAttrsFromHandler
in Map.toList $ Map.union jsAttrsStatic jsAttrsDynamic
flip unHandlerFor hd $ do
render <- getUrlRenderParams