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

Template Enum support #1104

Open
RylanYancey opened this issue Oct 20, 2024 · 1 comment
Open

Template Enum support #1104

RylanYancey opened this issue Oct 20, 2024 · 1 comment

Comments

@RylanYancey
Copy link

I'd like to use Askama as follows:

#[derive(Template)]
#[derive(Serialize, Deserialize)]
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>,
	},

	#[template(path = "./templates/question/editor/truefalse.html")]
	TrueOrFalse,

	#[template(path = "./templates/question/editor/fillblank.html")]
	FillInTheBlank {
		sections: Vec<String>,
		starts_with_blank: bool,
	},

	#[template(path = "./templates/question/editor/short-answer.html")]
	ShortAnswer {
		answers: Vec<String>,
	},

	#[template(path = "./templates/question/editor/ranking-text.html")]
	RankingText {
		numbering: Numbering,
		items: Vec<String>,
	},

	#[template(path = "./templates/question/editor/ranking-image.html")]
	RankingImages {
		numbering: Numbering,
		items: Vec<i32>,
	},
}

#[derive(Serialize, Deserialize)]
pub enum Numbering {
	Letters,
	Numbers,
	Bullets,
}

Is this a possibility in the future?

@djc
Copy link
Owner

djc commented Oct 21, 2024

I'm not convinced. Why do you need this? Alternatively, could you do MultipleChoiceText(MultipleChoiceText) with struct MultipleChoiceText { numbering: Numbering, text: Vec<String> } instead? That should get you pretty close.

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

No branches or pull requests

2 participants