-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template haskell ede #7
Template haskell ede #7
Conversation
Could you tell me a bit more about it? Let me confirm the meaning of "type-safe on template parameter".
Is it correct that you say it's better to check if all the embedded template variables are given and their types are correct on second step? I surveyed some template engines and find that a. No type checking on template parameters is not so serious for early stage of development, so enhance it later phase of development What do you think about demerits of haiji
This is made by @notogawa. As well, this library have too many features for our use case. tpll
In addition, the github README says that
blaze-html
This library provides Haskell functions to represent html context as Haskell code inspite of parsing template string. servant-ede
Though the name is servant-ede, it seems not type-safe for template parameters. Mustache
Shakespeare
HStringTemplate
karver
|
…little bit, it doesn't seem like it will be usable all the time, but it might be worth trying if you don't know how to format a certain section of code.
…plate plate, parse it, and render it.
…o template haskell.
c822470
to
0cfe4b5
Compare
Yes, this is correct. I think it is generally better to make sure the templates can be rendered correctly at compile time. However, (I think?) you will write a lot of the template html code, so ideally we should use a library that you like using. Would you rather write the template html files with haiji or ede? I will checkout the source code for the haiji library. |
The only point which template html style I want to write is that the style does not conflict with pug. In our case, we're already using template engine pug on front-end. The main role of those template engines are as follows.
It implies that we do not expect any convenient functions on the second template engine. Please choose the second template engine by the back-end side convenience. |
Okay, that makes sense. In that case, let's use haiji because it is more type safe. It's a little cumbersome to use because of the type-safety, but I'm going to try to make a simple wrapper. |
@arowM After playing around with
For now, lets just use If I have some free time this week, I will play around with ghc to see if I can figure out why compiling I came up with a convenient syntax for writing |
I released haiji-0.2.0.0 with the proposed syntax. In this version, a memory usage while compile time will be reduced. |
Thanks for informing us, @notogawa ! |
@notogawa Thanks for releasing haiji-0.2.0.0! Unfortunately, compile times for templates with large numbers of variables seem to still be quite slow. Compiling the following code takes a little over a minute on my machine: {-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Default (def)
import Text.Haiji
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.IO as LT
main :: IO ()
main = LT.putStr
$ render $(haijiFile def "content3.tmpl") $
toDict @"a_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"b_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"c_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"d_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"e_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"f_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"g_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"h_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"i_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"j_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"k_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"l_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"m_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"n_variable" ("Hello,World!" :: LT.Text) `merge`
toDict @"o_variable" ("Hello,World!" :: LT.Text)
Last week I didn't find any time to play around with GHC to figure out why the compilation time takes so long, but maybe I'll be able to take some time this week. |
stack passes ghc options When ghc 7.8, .dump-hi file is small because .hi file is also small. Since ghc 7.10, .hi file has rich information (for optimization ?) and human readable dump become large. |
@notogawa Thanks for the explanation! I tried recompiling my example program from above without However, I couldn't find an easy way to force stack to not use |
I have a rough version of #6 working.
It's currently not type-safe with respect to template parameters, but it does make sure the template parses correctly at compile time.
I don't think it's possible to take the template parameters from the environment, because it's impossible to see what variables nd types the template will need.
(For instance, with a template like
{% if var %} {{ foo }} {% else %} {{ bar }} {% endif %}
, it's impossible to know whether the template will needfoo
orbar
without first trying to render it.)Maybe if we used a different template library we could get something that is more type-safe.
Also, #6 needs to be merged in before this can be merged in.
@arowM Please take a look at this, especially commit c822470. What do you think?