-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add enum support #223
Comments
I agree, this would be useful. Something like this, perhaps? |
With a default template? Hum why not! |
I think it would a good feature to have! The main problem I have are the constants in I think, in a first iteration we could require that the |
Not sure if median is the best idea here. Maybe taking the biggest value would be better? |
As a user, I would expect the Maybe an attribute can be accepted when deriving enums that lets you specify an escape hatch. Unsure if it is worth the maintenance cost for how often it would actually get used. I imagine most users would just take the default and not worry about it. #[derive(Template)]
#[derive(Serialize, Deserialize)]
#[template(size_hint = "median")]
// #[template(size_hint = "largest")] default
// #[template(size_hint = Self::MultipleChoiceText)] a "hot path" variant
pub enum QuestionData {
#[template(path = "./templates/question/editor/multiple-text.html")]
MultipleChoiceText {
numbering: Numbering,
text: Vec<String>,
},
#[template(path = "./templates/question/editor/multiple-image.html")]
MultipleChoiceImage {
numbering: Numbering,
images: Vec<i32>,
},
} FWIW - I have many cases where I use a single field struct to wrap and display an enum like this, so this feature would be a great add. Especially If work is needed on implementation, I may be able to help a bit. Still getting used to the codebase and it seems substantial progress has already been made. Maybe if documentation or examples are needed? |
It's also what I think.
That seems a bit too much in my opinion.
Work is already in progress in #255. But if you have some tests in mind, don't hesitate to post them there. |
It would allow to do:
And so calling
render
on the enum would be on its variant instead. It was suggested in djc/askama#1104 and I kinda like the idea.The text was updated successfully, but these errors were encountered: