Using Licius + Hamlet + Julius in Servant

邮差的信 提交于 2019-12-24 01:19:12

问题


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:


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.



来源:https://stackoverflow.com/questions/36596601/using-licius-hamlet-julius-in-servant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!