Merge pull request #1038 from yesodweb/widget_isstring_instance

Add IsString instance for WidgetT site m ()
This commit is contained in:
Andrew Martin 2015-07-23 13:21:10 -04:00
commit 81c996f29e

View File

@ -48,7 +48,7 @@ import qualified Network.Wai.Parse as NWP
import System.Log.FastLogger (LogStr, LoggerSet, toLogStr, pushLogStr)
import qualified System.Random.MWC as MWC
import Network.Wai.Logger (DateCacheGetter)
import Text.Blaze.Html (Html)
import Text.Blaze.Html (Html, toHtml)
import Text.Hamlet (HtmlUrl)
import Text.Julius (JavascriptUrl)
import Web.Cookie (SetCookie)
@ -251,6 +251,16 @@ instance (a ~ (), Monad m) => Monoid (WidgetT site m a) where
mappend x y = x >> y
instance (a ~ (), Monad m) => Semigroup (WidgetT site m a)
-- | A 'String' can be trivially promoted to a widget.
--
-- For example, in a yesod-scaffold site you could use:
--
-- @getHomeR = do defaultLayout "Widget text"@
instance (Monad m, a ~ ()) => IsString (WidgetT site m a) where
fromString = toWidget . toHtml . T.pack
where toWidget x = WidgetT $ const $ return $ ((), GWData (Body (const x))
mempty mempty mempty mempty mempty mempty)
type RY master = Route master -> [(Text, Text)] -> Text
-- | Newtype wrapper allowing injection of arbitrary content into CSS.