Safe Haskell | None |
---|---|
Language | Haskell2010 |
Base types and combinators.
Synopsis
- renderText :: Html a -> Text
- renderBS :: Html a -> ByteString
- renderTextT :: Monad m => HtmlT m a -> m Text
- renderBST :: Monad m => HtmlT m a -> m ByteString
- renderToFile :: FilePath -> Html a -> IO ()
- execHtmlT :: Monad m => HtmlT m a -> m Builder
- evalHtmlT :: Monad m => HtmlT m a -> m a
- runHtmlT :: HtmlT m a -> m (Seq Attribute -> Builder, a)
- relaxHtmlT :: Monad m => HtmlT Identity a -> HtmlT m a
- commuteHtmlT :: (Functor m, Monad n) => HtmlT m a -> m (HtmlT n a)
- makeElement :: Functor m => Text -> HtmlT m a -> HtmlT m a
- makeElementNoEnd :: Applicative m => Text -> HtmlT m ()
- makeXmlElementNoEnd :: Applicative m => Text -> HtmlT m ()
- makeAttribute :: Text -> Text -> Attribute
- type Html = HtmlT Identity
- newtype HtmlT m a = HtmlT (m (Seq Attribute -> Builder, a))
- data Attribute = Attribute !Text !Text
- class Term arg result | result -> arg where
- class TermRaw arg result | result -> arg where
- termRaw :: Text -> arg -> result
- termRawWith :: Text -> [Attribute] -> arg -> result
- class ToHtml a where
- class With a where
Rendering
renderText :: Html a -> Text Source #
Render the HTML to a lazy Text
.
This is a convenience function defined in terms of execHtmlT
,
runIdentity
and toLazyByteString
, and
decodeUtf8
. Check the source if you're interested in the
lower-level behaviour.
renderBS :: Html a -> ByteString Source #
Render the HTML to a lazy ByteString
.
This is a convenience function defined in terms of execHtmlT
,
runIdentity
and toLazyByteString
. Check the source if
you're interested in the lower-level behaviour.
renderTextT :: Monad m => HtmlT m a -> m Text Source #
Render the HTML to a lazy Text
, but in a monad.
This is a convenience function defined in terms of execHtmlT
and
toLazyByteString
, and decodeUtf8
. Check the source if
you're interested in the lower-level behaviour.
renderBST :: Monad m => HtmlT m a -> m ByteString Source #
Render the HTML to a lazy ByteString
, but in a monad.
This is a convenience function defined in terms of execHtmlT
and
toLazyByteString
. Check the source if you're interested in
the lower-level behaviour.
renderToFile :: FilePath -> Html a -> IO () Source #
Render the HTML to a lazy ByteString
.
This is a convenience function defined in terms of execHtmlT
,
runIdentity
and toLazyByteString
. Check the source if
you're interested in the lower-level behaviour.
Running
Build the HTML. Analogous to execState
.
You might want to use this is if you want to do something with the
raw Builder
. Otherwise for simple cases you can just use
renderText
or renderBS
.
:: Monad m | |
=> HtmlT m a | HTML monad to evaluate. |
-> m a | Ignore the HTML output and just return the value. |
Evaluate the HTML to its return value. Analogous to evalState
.
Use this if you want to ignore the HTML output of an action completely and just get the result.
For using with the Html
type, you'll need runIdentity
e.g.
>>>
runIdentity (evalHtmlT (p_ "Hello!"))
()
:: (Functor m, Monad n) | |
=> HtmlT m a | unpurely generated HTML |
-> m (HtmlT n a) | Commuted monads. Note: |
Commute inner m
to the front.
This is useful when you have impure HTML generation, e.g. using StateT
.
Recall, there is `MonadState s HtmlT` instance.
exampleHtml :: MonadState Int m => HtmlT m () exampleHtml = ul_ $ replicateM_ 5 $ do x <- get put (x + 1) li_ $ toHtml $ show x exampleHtml' :: Monad m => HtmlT m () exampleHtml' = evalState (commuteHtmlT exampleHtml) 1
Since: 2.9.9
Combinators
Make an HTML builder.
:: Applicative m | |
=> Text | Name. |
-> HtmlT m () | A parent element. |
Make an HTML builder for elements which have no ending tag.
:: Applicative m | |
=> Text | Name. |
-> HtmlT m () | A parent element. |
Make an XML builder for elements which have no ending tag.
Make an attribute builder.
Types
A monad transformer that generates HTML. Use the simpler Html
type if you don't want to transform over some other monad.
Don't rely on the internal representation of this type. Use the monad and functor classes.
Instances
MonadTrans HtmlT Source # | Used for |
Defined in Lucid.Base | |
MonadWriter w m => MonadWriter w (HtmlT m) Source # | Since: 2.9.9 |
MonadState s m => MonadState s (HtmlT m) Source # | Since: 2.9.7 |
MonadReader r m => MonadReader r (HtmlT m) Source # | Since: 2.9.7 |
MonadError e m => MonadError e (HtmlT m) Source # | Since: 2.9.9 |
Defined in Lucid.Base throwError :: e -> HtmlT m a # catchError :: HtmlT m a -> (e -> HtmlT m a) -> HtmlT m a # | |
(Monad m, a ~ ()) => TermRaw Text (HtmlT m a) Source # | Given children immediately, just use that and expect no attributes. |
Monad m => Monad (HtmlT m) Source # | Basically acts like Writer. |
Functor m => Functor (HtmlT m) Source # | Just re-uses Monad. |
MonadFix m => MonadFix (HtmlT m) Source # | |
Defined in Lucid.Base | |
Applicative m => Applicative (HtmlT m) Source # | Based on the monad instance. |
MonadIO m => MonadIO (HtmlT m) Source # | If you want to use IO in your HTML generation. |
Defined in Lucid.Base | |
MFunctor HtmlT Source # | Since: 2.9.5 |
(Monad m, ToHtml f, a ~ ()) => TermRaw [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
(Applicative m, f ~ HtmlT m a) => Term [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
m ~ Identity => Show (HtmlT m a) Source # | Just calls |
(Monad m, a ~ ()) => IsString (HtmlT m a) Source # | We pack it via string. Could possibly encode straight into a builder. That might be faster. |
Defined in Lucid.Base fromString :: String -> HtmlT m a # | |
(a ~ (), Applicative m) => Semigroup (HtmlT m a) Source # | Since: 2.9.7 |
(a ~ (), Applicative m) => Monoid (HtmlT m a) Source # | Monoid is right-associative, a la the |
Functor m => With (HtmlT m a -> HtmlT m a) Source # | For the contentful elements: |
Functor m => With (HtmlT m a) Source # | For the contentless elements: |
(a ~ (), m ~ Identity) => ToHtml (HtmlT m a) Source # | Since: 2.9.8 |
Applicative m => Term (HtmlT m a) (HtmlT m a) Source # | Given children immediately, just use that and expect no attributes. |
A simple attribute. Don't use the constructor, use
makeAttribute
. Attributes are case sensitive, so if you want
attributes to be merged properly, use a single case representation.
Instances
Eq Attribute Source # | |
Show Attribute Source # | |
Hashable Attribute Source # | |
Defined in Lucid.Base | |
TermRaw Text Attribute Source # | Some termRaws (like |
Term Text Attribute Source # | Some terms (like |
(Monad m, ToHtml f, a ~ ()) => TermRaw [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
(Applicative m, f ~ HtmlT m a) => Term [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
Classes
class Term arg result | result -> arg where Source #
Used to construct HTML terms.
Simplest use: p_ = term "p" yields p_
.
Very overloaded for three cases:
- The first case is the basic
arg
of[(Text,Text)]
which will return a function that wants children. - The second is an
arg
which isHtmlT m ()
, in which case the term accepts no attributes and just the children are used for the element. - Finally, this is also used for overloaded attributes, like
style_
ortitle_
. If a return type of(Text,Text)
is inferred then an attribute will be made.
The instances look intimidating but actually the constraints make
it very general so that type inference works well even in the
presence of things like OverloadedLists
and such.
:: Text | Name of the element or attribute. |
-> arg | Either an attribute list or children. |
-> result | Result: either an element or an attribute. |
Used for constructing elements e.g. term "p"
yields p_
.
:: Text | Name. |
-> [Attribute] | Attribute transformer. |
-> arg | Some argument. |
-> result | Result: either an element or an attribute. |
Use this if you want to make an element which inserts some pre-prepared attributes into the element.
Instances
Term Text Attribute Source # | Some terms (like |
(Applicative m, f ~ HtmlT m a) => Term [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
Applicative m => Term (HtmlT m a) (HtmlT m a) Source # | Given children immediately, just use that and expect no attributes. |
class TermRaw arg result | result -> arg where Source #
Same as the Term
class, but will not HTML escape its
children. Useful for elements like style_
or
script_
.
:: Text | Name of the element or attribute. |
-> arg | Either an attribute list or children. |
-> result | Result: either an element or an attribute. |
Used for constructing elements e.g. termRaw "p"
yields p_
.
:: Text | Name. |
-> [Attribute] | Attribute transformer. |
-> arg | Some argument. |
-> result | Result: either an element or an attribute. |
Use this if you want to make an element which inserts some pre-prepared attributes into the element.
Instances
TermRaw Text Attribute Source # | Some termRaws (like |
(Monad m, a ~ ()) => TermRaw Text (HtmlT m a) Source # | Given children immediately, just use that and expect no attributes. |
(Monad m, ToHtml f, a ~ ()) => TermRaw [Attribute] (f -> HtmlT m a) Source # | Given attributes, expect more child input. |
Can be converted to HTML.
toHtml :: Monad m => a -> HtmlT m () Source #
Convert to HTML, doing HTML escaping.
toHtmlRaw :: Monad m => a -> HtmlT m () Source #
Convert to HTML without any escaping.
Instances
ToHtml String Source # | |
ToHtml ByteString Source # | This instance requires the ByteString to contain UTF-8 encoded
text, for the Since: 2.9.5 |
ToHtml ByteString Source # | This instance requires the ByteString to contain UTF-8 encoded
text, for the Since: 2.9.5 |
ToHtml Text Source # | |
ToHtml Text Source # | |
(a ~ (), m ~ Identity) => ToHtml (HtmlT m a) Source # | Since: 2.9.8 |
With an element use these attributes. An overloaded way of adding attributes either to an element accepting attributes-and-children or one that just accepts attributes. See the two instances.
:: a | Some element, either |
-> [Attribute] | |
-> a |
With the given element(s), use the given attributes.