Code Monkey home page Code Monkey logo

Comments (5)

djc avatar djc commented on August 23, 2024

So include now works, but only with a string literal path. Not sure that satisfies your use case here?

At some point I think I will need something like a Renderable trait anyway, also for escaping strings by default (#23). Not yet sure I like this name, but also haven't come up with a better one...

from askama.

anowell avatar anowell commented on August 23, 2024

Thanks. This does look pretty reasonable while remaining true to being Jinja-like, though you're correct it doesn't quite satisfy my usecase.

For my usecase, I've stuck to just adding a String field on a template and pre-rendering the partial nested template when intializing the main template. It works well enough, though I still think it'd be cleaner if I could use the actual template type or Box<Template> or maybe a generic T: Template (so that i can' hold different nested templates) as the type of a field on another template.

Anyhow, huge thanks for the various fixes/features to improve my use cases. Askama is definitely great to work with!

from askama.

djc avatar djc commented on August 23, 2024

I told you I wasn't done. 😉

I just pushed cece25b, which implements Display for all Templates. I experimented with making a separate trait for this which I called Render (to invoke a similarity to the Read and Write traits in std), but it ends up being identical to Template, which is not helpful. On top of that, the Template trait itself is already really similar to Display, in that the meat of it is just a method that writes stuff into a Write.

So doing it this way seems to be more ergonomical, and makes conceptual sense: if you derive Template for your type, it makes sense to me that displaying that type invokes the template implementation. If people want a different serialization, they can use Debug still, and I could potentially add an option to the template() attribute to disable generation the impl Display code.

So, with that, I think you have a nice solution to your problem!

Thanks again for all the feedback, I think it's already made Askama a lot better already, and it has allowed me to more critically review my code from 6 months ago. 👍

from askama.

anowell avatar anowell commented on August 23, 2024

Huge thanks! Implementing Display for all Templates works for me and I mostly agree with your reasoning. I sorta imagine somebody eventually coming along and not wanting that behavior, but I had a hard time thinking up a compelling scenario for that, so 👍 from me.

p.s. I included a shout-out for Askama in this r/rust thread. ;-)

from askama.

djc avatar djc commented on August 23, 2024

Thaks for the shout out, very nice.

from askama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.