reduce code repetition with class splices
This commit is contained in:
parent
b20822a644
commit
7d9bc2d7cd
|
@ -4,16 +4,18 @@ use maud::{html, Markup};
|
|||
///
|
||||
/// Render a flash elements based on the given flash name and message.
|
||||
pub fn build_template(flash_name: &str, flash_msg: &str) -> Markup {
|
||||
let flash_class = match flash_name {
|
||||
"success" => "capsule center-text flash-message font-normal border-success",
|
||||
"info" => "capsule center-text flash-message font-normal border-info",
|
||||
"warning" => "capsule center-text flash-message font-normal border-warning",
|
||||
"error" => "capsule center-text flash-message font-normal border-danger",
|
||||
let common_classes = "capsule center center-text flash-message font-normal ";
|
||||
|
||||
let border_class = match flash_name {
|
||||
"success" => "border-success",
|
||||
"info" => "border-info",
|
||||
"warning" => "border-warning",
|
||||
"error" => "border-danger",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
html! {
|
||||
div class=(flash_class) {
|
||||
div class={ (common_classes) (border_class) } {
|
||||
(flash_msg)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue