-
Notifications
You must be signed in to change notification settings - Fork 55
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
Making layouts #31
Comments
Hello, @lephyrius ! Sailfish is based on EJS, which does not support this feature. However, I think it is better for the sailfish to have this feature for creating simple templates. Sailfish compiler is properly separated for each stage (lexer, transformer, resolver, optimizer), so the implementation is not so hard. In contrast, its design is not stabilized yet. Could you tell me its use case? I want to stabilize its design based on the use cases. What I'm so far planning is
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<section>
<% yield body %>
</section>
<footer>
<% yield footer %>
</footer>
</body>
</html>
<% extend!("layout.stpl", body { %>
<h1>Hello, world!</h1>
<% }, footer { %>
Copyright © <%= copyrights %>
<% }); %> If you want to create a layout with the existing version, you need 3 templates.
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<section>
<%- body.render_once() %>
</section>
<footer>
<% footer.render_once() %>
</footer>
</body>
</html>
<h1>Hello, world!</h1>
Copyright © <%= copyrights %>
#[derive(TemplateOnce)]
#[template(path = "layout.stpl")]
struct Layout<T1: TemplateOnce, T2: TemplateOnce> {
title: String,
body: T1,
footer: T2
}
#[derive(TemplateOnce)]
#[template(path = "page-body.stpl")]
struct PageBody;
#[derive(TemplateOnce)]
#[template(path = "page-footer.stpl")]
struct PageFooter {
copyrights: String
}
let result = Layout {
title: "page".to_owned(),
body: PageBody,
footer: PageFooter {
copyrights: "2020 Ryohei Machida".to_owned()
}
}.render_once().unwrap(); |
I really like everything! |
hi @lephyrius @Kogia-sima, @vthg2themax ,the layout code you talked about above is not working for me. I'm using the latest 0.8.1 release, and with just copy paste your code, I aways got this. Is there anything i need to change ?
|
The error messages made thought this TemplateOnce trait is not working for generic struct, but turns out just a simple problem <!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<section>
<%- body.render_once().unwrap() %>
</section>
<footer>
<% footer.render_once().unwrap() %>
</footer>
</body>
</html> |
Are there any plans to continue supporting the project with new features? Speed is good, but it would be nice to improve the DX level with new updates |
@rocinant3 Unfortunately I am just maintaining this project currently. I cannot speak for @Kogia-sima however. I am willing to merge any positive changes to the project in accordance with our stated goals, but I am unable to devote very much time to new features. I have 2 kids, and a family which all take priority, and this is an interesting side project. Pull Requests are always welcome though! |
@vthg2themax thanks for the answer. I'll start working on a fork |
I want to have a generic layout for all my pages. How I currently do it is I have a generic struct with title/body values and inject them in the layout template.
I think there should be a bit more sophisticated way of doing it preferably a way to specify a layout.
The text was updated successfully, but these errors were encountered: