Make jsAttributesHandler use jsAttributes
This addresses this comment: https://github.com/yesodweb/yesod/pull/1622#discussion_r317467498
This commit is contained in:
parent
59988f46a1
commit
d1e4fd485b
@ -252,13 +252,12 @@ class RenderRoute site => Yesod site where
|
|||||||
-- | Same as @jsAttributes@ but allows you to run arbitrary Handler code
|
-- | 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
|
-- 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
|
-- tag generated by @widgetFile@. If this function is overridden then
|
||||||
-- @jsAttributes@, the two attribute maps will be merged, favouring the
|
-- @jsAttributes@ is ignored.
|
||||||
-- keys from @jsAttributes@ in case of a collision.
|
|
||||||
--
|
--
|
||||||
-- @since 1.6.16
|
-- @since 1.6.16
|
||||||
jsAttributesHandler :: HandlerFor site [(Text, Text)]
|
jsAttributesHandler :: HandlerFor site [(Text, Text)]
|
||||||
jsAttributesHandler = pure []
|
jsAttributesHandler = getYesod >>= return . jsAttributes
|
||||||
|
|
||||||
-- | Create a session backend. Returning 'Nothing' disables
|
-- | Create a session backend. Returning 'Nothing' disables
|
||||||
-- sessions. If you'd like to change the way that the session
|
-- sessions. If you'd like to change the way that the session
|
||||||
@ -532,7 +531,7 @@ widgetToPageContent :: Yesod site
|
|||||||
=> WidgetFor site ()
|
=> WidgetFor site ()
|
||||||
-> HandlerFor site (PageContent (Route site))
|
-> HandlerFor site (PageContent (Route site))
|
||||||
widgetToPageContent w = do
|
widgetToPageContent w = do
|
||||||
jsAttrsFromHandler <- jsAttributesHandler
|
jsAttrs <- jsAttributesHandler
|
||||||
HandlerFor $ \hd -> do
|
HandlerFor $ \hd -> do
|
||||||
master <- unHandlerFor getYesod hd
|
master <- unHandlerFor getYesod hd
|
||||||
ref <- newIORef mempty
|
ref <- newIORef mempty
|
||||||
@ -544,10 +543,6 @@ widgetToPageContent w = do
|
|||||||
let title = maybe mempty unTitle mTitle
|
let title = maybe mempty unTitle mTitle
|
||||||
scripts = runUniqueList scripts'
|
scripts = runUniqueList scripts'
|
||||||
stylesheets = runUniqueList stylesheets'
|
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
|
flip unHandlerFor hd $ do
|
||||||
render <- getUrlRenderParams
|
render <- getUrlRenderParams
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user