2
votes

I would like to use Shakespearean Templates (Licius + Hamlet + Julius) from the Yesod.But I have some difficulty with this. The following code from enter link description here works:

type TestAPI 
    = "tests" :> Get '[JSON] [Test]
    :<|> "test" :> Get '[JSON] Test
    :<|> "TestHTML.html" :> Get '[HTML] Page_TestHTML 

serverTestAPI :: ServerT TestAPI AppM
serverTestAPI = tests 
           :<|> test
           :<|> testHtml

data Page_TestHTML = Page_TestHTML

instance ToMarkup Page_TestHTML where
    toMarkup Page_TestHTML = builderHtml  

testHtml = return Page_TestHTML

builderHtml = [shamlet|
                $doctype 5
                <html>
                    <head>
                        <title>Greeting2
                <body>
                    <h2> Hello world HTML Qqqqq |]

But next code is not working:

data Page_TestHTML_2 = Page_TestHTML_2

instance ToMarkup Page_TestHTML_2 where
    toMarkup Page_TestHTML_2 = builderHtml_2

testHtml_2 = return Page_TestHTML_2

builderHtml_2 = do 
    $(luciusFile "templates/test/TestHTML2.lucius")
    $(shamletFile "templates/test/TestHTML2.hamlet")

How I can constructing together Licius + Hamlet + Julius for Servant (without whole Yesod)?

1
Can you add the compiler error you're getting?user2141650
Error: Couldn't match expected type ‘t0 -> Css’ with actual type ‘blaze-markup-0.7.0.3:Text.Blaze.Internal.MarkupM a0’ The lambda expression ‘\ _render_alwD -> (shakespeare-2.0.8:Text.Css.CssNoWhitespace . (foldr ($) ...)) ...’QSpider
When will people learn that it's not a good idea to omit type signatures?leftaroundabout
Well, the fact that type signature s are not needed is a selling point of Haskell. So no wonder people uses this "feature"mb14
@mb14 maybe the seller should add "as long as you keep your hands off most of the extensions" in his small print ;)Random Dev

1 Answers

2
votes

I was able to solve the question. The following code works!

data Page_LoginHTML = Page_LoginHTML

instance H.ToMarkup Page_LoginHTML where
    toMarkup Page_LoginHTML = builderHtml  

loginHtml = return Page_LoginHTML

cssStyle :: Html 
cssStyle = toHtml $ renderCssUrl undefined 
    [cassius|
        .q-test-2 
            color: green
    |]

htmlBody :: Html 
htmlBody =   
    [shamlet|
        <h1> Hamlet Login Render
    |]

builderHtml = H.docTypeHtml $ do
    H.head $ do
        H.title "Login"
        H.style cssStyle
    H.body htmlBody

Maybe it will be useful for somebody.