Skip to content
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

WIP: Provide join_html and join_to_html. #88

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

WIP: Provide join_html and join_to_html. #88

wants to merge 2 commits into from

Conversation

kaj
Copy link
Owner

@kaj kaj commented Jul 16, 2020

A possible solution to #85 .

Questions / things to test:

  • Is join_html and join_to_html good names for the functions?
  • Does join_html work with inline subtemplates when used in templates? It does not, and would be rather hard to fix at the moment. But inline templates with arguments would be a separate issue that would fix it.
  • Can the return type be improved? I would like to return impl ToHtml, but currently both join_html and join_to_html returns Box<dyn ToHtml>, as a trait function apparently cannot return impl Trait. They could also return HtmlJoiner<...>, but then that class (which I consider an implementation detail) would have to be public, and the generic type arguments would be inconveniently long.
  • Is the documentaion for join_html and join_to_html understandable?

@OskarPersson
Copy link

I think that both are good additions to the library, I really like the concept of join_html. However, I don't think destructuring tuples works in templates?

<!-- examples/simple/templates/hello_args.rs.html -->
@((greeting, who): &(&str, &str))
<h1>@greeting @who!</h1>
// examples/simple/src/main.rs
#[test]
fn test_hello_args() {
    assert_eq!(
        r2s(|o| hello_args_html(o, ("Hello", "World"))),
        "<h1>Hello World!</h1>\n",
    );
}
$ cargo t
warning: Template parse error in "templates/hello_args.rs.html":
warning:    1:@((greeting, who): &(&str, &str))
warning:        ^ expected formal argument

Also, would it be possible to have the template inline in join_html in addition to having the ability to have it as an external template?

@kaj
Copy link
Owner Author

kaj commented Aug 10, 2020

Turns out the code as it is now has problem with types and/or lifetimes when actually using a template with join_html. Looking at how to fix it, may have to change the template function type and/or the ToHtml trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants