addCoffee/addCoffeeBody
This commit is contained in:
parent
56497ed267
commit
709d9b7547
@ -38,6 +38,8 @@ module Yesod.Widget
|
|||||||
-- ** Javascript
|
-- ** Javascript
|
||||||
, addJulius
|
, addJulius
|
||||||
, addJuliusBody
|
, addJuliusBody
|
||||||
|
, addCoffee
|
||||||
|
, addCoffeeBody
|
||||||
, addScript
|
, addScript
|
||||||
, addScriptAttrs
|
, addScriptAttrs
|
||||||
, addScriptRemote
|
, addScriptRemote
|
||||||
@ -54,6 +56,7 @@ import Text.Hamlet
|
|||||||
import Text.Cassius
|
import Text.Cassius
|
||||||
import Text.Lucius (Lucius)
|
import Text.Lucius (Lucius)
|
||||||
import Text.Julius
|
import Text.Julius
|
||||||
|
import Text.Coffee
|
||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
(Route, GHandler, GGHandler, YesodSubRoute(..), toMasterHandlerMaybe, getYesod
|
(Route, GHandler, GGHandler, YesodSubRoute(..), toMasterHandlerMaybe, getYesod
|
||||||
, getMessageRender
|
, getMessageRender
|
||||||
@ -61,7 +64,7 @@ import Yesod.Handler
|
|||||||
import Yesod.Message (RenderMessage)
|
import Yesod.Message (RenderMessage)
|
||||||
import Yesod.Content (RepHtml (..), toContent)
|
import Yesod.Content (RepHtml (..), toContent)
|
||||||
import Control.Applicative (Applicative)
|
import Control.Applicative (Applicative)
|
||||||
import Control.Monad.IO.Class (MonadIO)
|
import Control.Monad.IO.Class (MonadIO (liftIO))
|
||||||
import Control.Monad.Trans.Class (MonadTrans (lift))
|
import Control.Monad.Trans.Class (MonadTrans (lift))
|
||||||
import Yesod.Internal
|
import Yesod.Internal
|
||||||
import Control.Monad (liftM)
|
import Control.Monad (liftM)
|
||||||
@ -73,6 +76,7 @@ import Yesod.Handler (getUrlRenderParams)
|
|||||||
|
|
||||||
import Control.Monad.IO.Control (MonadControlIO)
|
import Control.Monad.IO.Control (MonadControlIO)
|
||||||
import qualified Text.Hamlet.NonPoly as NP
|
import qualified Text.Hamlet.NonPoly as NP
|
||||||
|
import Data.Text.Lazy.Builder (fromLazyText)
|
||||||
|
|
||||||
-- | A generic widget, allowing specification of both the subsite and master
|
-- | A generic widget, allowing specification of both the subsite and master
|
||||||
-- site datatypes. This is basically a large 'WriterT' stack keeping track of
|
-- site datatypes. This is basically a large 'WriterT' stack keeping track of
|
||||||
@ -209,6 +213,22 @@ addJulius x = GWidget $ tell $ GWData mempty mempty mempty mempty mempty (Just x
|
|||||||
addJuliusBody :: Monad m => Julius (Route master) -> GGWidget master m ()
|
addJuliusBody :: Monad m => Julius (Route master) -> GGWidget master m ()
|
||||||
addJuliusBody j = addHamlet $ \r -> H.script $ preEscapedLazyText $ renderJulius r j
|
addJuliusBody j = addHamlet $ \r -> H.script $ preEscapedLazyText $ renderJulius r j
|
||||||
|
|
||||||
|
-- | Add Coffesscript to the page's script tag. Requires the coffeescript
|
||||||
|
-- executable to be present at runtime.
|
||||||
|
addCoffee :: MonadIO m => Coffee (Route master) -> GGWidget master (GGHandler sub master m) ()
|
||||||
|
addCoffee c = do
|
||||||
|
render <- lift getUrlRenderParams
|
||||||
|
t <- liftIO $ renderCoffee render c
|
||||||
|
addJulius $ const $ Javascript $ fromLazyText t
|
||||||
|
|
||||||
|
-- | Add a new script tag to the body with the contents of this Coffesscript
|
||||||
|
-- template. Requires the coffeescript executable to be present at runtime.
|
||||||
|
addCoffeeBody :: MonadIO m => Coffee (Route master) -> GGWidget master (GGHandler sub master m) ()
|
||||||
|
addCoffeeBody c = do
|
||||||
|
render <- lift getUrlRenderParams
|
||||||
|
t <- liftIO $ renderCoffee render c
|
||||||
|
addJuliusBody $ const $ Javascript $ fromLazyText t
|
||||||
|
|
||||||
-- | Pull out the HTML tag contents and return it. Useful for performing some
|
-- | Pull out the HTML tag contents and return it. Useful for performing some
|
||||||
-- manipulations. It can be easier to use this sometimes than 'wrapWidget'.
|
-- manipulations. It can be easier to use this sometimes than 'wrapWidget'.
|
||||||
extractBody :: Monad mo => GGWidget m mo () -> GGWidget m mo (Hamlet (Route m))
|
extractBody :: Monad mo => GGWidget m mo () -> GGWidget m mo (Hamlet (Route m))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user