Modified the Render logic
In Core.Render instances are declared for the Show class, and show and print are used elsewhere.
This commit is contained in:
parent
ef97b3fb76
commit
d38167de89
6 changed files with 38 additions and 23 deletions
|
@ -10,6 +10,7 @@ import Text.Blaze.Html5 ( Html )
|
|||
|
||||
import Components
|
||||
import Core.Compilers
|
||||
import Core.Render
|
||||
|
||||
import Kit.Templates.Index ( indexTemplate )
|
||||
import Kit.Templates.Post ( postTemplate )
|
||||
|
@ -18,7 +19,7 @@ allTemplates :: [Component Html]
|
|||
allTemplates = [postTemplate, indexTemplate]
|
||||
|
||||
allCss :: String
|
||||
allCss = toCss . mconcat $ allTemplates
|
||||
allCss = show . getCss . mconcat $ allTemplates
|
||||
|
||||
css :: Compiler (Item String)
|
||||
css = makeItem allCss
|
||||
|
|
|
@ -20,6 +20,7 @@ library
|
|||
Components
|
||||
Core.Colors
|
||||
Core.Compilers
|
||||
Core.Render
|
||||
Core.Routers
|
||||
Core.Writer
|
||||
Css.Default
|
||||
|
|
|
@ -4,9 +4,8 @@ module Components
|
|||
, Component(..)
|
||||
, new
|
||||
, (<.>)
|
||||
, putHtml
|
||||
, toCss
|
||||
, putCss
|
||||
, getHtml
|
||||
, getCss
|
||||
) where
|
||||
|
||||
import Clay ( Css
|
||||
|
@ -37,21 +36,21 @@ prop name css = Prop (Map.singleton name css)
|
|||
|
||||
type Component = Writer Prop
|
||||
|
||||
-- |render a Component's Html
|
||||
putHtml :: Component Html -> IO ()
|
||||
putHtml = putStr . renderHtml . fst . runWriter
|
||||
-- |Return a Component's Css as a String
|
||||
toCss :: Component a -> String
|
||||
toCss =
|
||||
unpack
|
||||
. renderWith compact []
|
||||
. mconcat
|
||||
. map snd
|
||||
. Map.toList
|
||||
. cssMap
|
||||
. snd
|
||||
. runWriter
|
||||
-- |Get a Component's Html
|
||||
getHtml :: Component Html -> Html
|
||||
getHtml = fst . runWriter
|
||||
---- |Return a Component's Css as a String
|
||||
--toCss :: Component a -> String
|
||||
--toCss =
|
||||
-- unpack
|
||||
-- . renderWith compact []
|
||||
-- . mconcat
|
||||
-- . map snd
|
||||
-- . Map.toList
|
||||
-- . cssMap
|
||||
-- . snd
|
||||
-- . runWriter
|
||||
|
||||
-- |render a Component's Css
|
||||
putCss :: Component a -> IO ()
|
||||
putCss = putStr . toCss
|
||||
-- |Get a Component's Css
|
||||
getCss :: Component a -> Css
|
||||
getCss = mconcat . map snd . Map.toList . cssMap . snd . runWriter
|
||||
|
|
12
src/Core/Render.hs
Normal file
12
src/Core/Render.hs
Normal file
|
@ -0,0 +1,12 @@
|
|||
module Core.Render where
|
||||
|
||||
import Clay
|
||||
import Data.Text.Lazy ( unpack )
|
||||
import Text.Blaze.Html.Renderer.String
|
||||
import Text.Blaze.Html5
|
||||
|
||||
instance Show Css where
|
||||
show = unpack . renderWith compact []
|
||||
|
||||
instance Show Html where
|
||||
show = renderHtml
|
|
@ -4,6 +4,7 @@ module Kit.Templates.Index
|
|||
) where
|
||||
|
||||
import Components
|
||||
import Core.Render
|
||||
import Kit.Atoms.Button
|
||||
import Kit.Atoms.ButtonLink
|
||||
import Kit.Organisms.Head
|
||||
|
@ -22,4 +23,4 @@ indexTemplate =
|
|||
docTypeHtml <$> defaultHead "Very first try" <> (body <$> indexBody)
|
||||
|
||||
main :: IO ()
|
||||
main = putHtml indexTemplate
|
||||
main = print $ getHtml indexTemplate
|
||||
|
|
|
@ -4,6 +4,7 @@ module Kit.Templates.Post
|
|||
) where
|
||||
|
||||
import Components
|
||||
import Core.Render
|
||||
import Kit.Organisms.Head
|
||||
import Text.Blaze.Html5 as H
|
||||
hiding ( main )
|
||||
|
@ -16,4 +17,4 @@ postTemplate = docTypeHtml <$> defaultHead "$title$" <> pure
|
|||
)
|
||||
|
||||
main :: IO ()
|
||||
main = putHtml postTemplate
|
||||
main = print $ getHtml postTemplate
|
||||
|
|
Loading…
Reference in a new issue