-
Notifications
You must be signed in to change notification settings - Fork 33
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
end of expression #2
Comments
An alternative not using whitespace and looking familiar to many people would be this: A short hand to echo directly: For the file beginning, it could be obligatory to start with the exact sequence "<?rct", because we anyway always need a header and in that way a file identification tool can quickly and reliably identify ructe files. Example: <?rct
use models::blog::{Entry, Comment};
template!<HTML>(entry: &Entry, comments: &[Comment]);
// or something else than "template!", maybe "arguments!"
// I like the "!" because it behaves much like a macro
// the <HTML> is necessary to solve #1 generically
?>
<!doctype html>
<html>
<head>
<title><?=(HTML)entry.title?> - my blog</title>
</head>
<body>
<h1><?rct echo!<HTML>(entry.title) ?></h1>
<?rct unsafe { echo_raw!(entry.content) } ?>
<?rct for comment in comments.iter() { ?>
<h2>Comment by <?=(HTML)comment.author?></h2>
<?rct unsafe { echo_raw!(comment.content) } // I like how we have to use `unsafe` at this *really* unsafe spot. ?>
<?rct } ?>
</body>
</html> Advantages
Disadvantages
|
This syntax is also very similar to jsp, so I have considered it. Part of why I didn't choose it is the verbosity and part is that twirl just fees more natural and ergonomic, so I used that syntax. However, twirls superiority over jsp might be entirely independent of the syntax. I have to think about this some more, so let's use this PR as a general discussion thread about syntax in general and expression syntax in particular for ructe. |
A related thing: I think there is a value in limiting the rust code that can be included in a template. It may be that I have just seen (and written, I have to admit) way to much java code embedded directly into .jsp files, and maybe developers of today would have better discipline, but I think Also, not allowing arbitrary whitespace (i.e. newlines) in expressions may be a way to remind template authors to keep expressions reasonably short. If a more complex expression is needed, maybe that should be in a helper method? |
I have been testing and using ructe for a while in some projects by now, and I think the basic syntax is nice to work with. A template engine based on a more jsp- or php-like syntax could be created, but that would be another project. So I'll just close this issue now. Thank you for the discussion, @ConnyOnny ! |
We could use rocker-like eval expressions: -- @(file_name).sql
SELECT * FROM @(schema).@(table); |
How about
@…\n
for simple stuff and@{…}
for more complicated stuff (where…
could contain new lines only in the latter case)?The text was updated successfully, but these errors were encountered: