Skip to content

Commit

Permalink
fix(cssinfo): add warning on empty result
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Nov 6, 2024
1 parent a0af5e8 commit bdcca17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/rari-doc/src/helpers/css_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ fn add_additional_applies_to<'a>(
));
}

fn get_css_l10n_for_locale(key: &str, locale: Locale) -> &str {
pub fn get_css_l10n_for_locale(key: &str, locale: Locale) -> &str {
if let Some(data) = mdn_data_files().css_l10n.get(key) {
let data = get_for_locale(locale, data);
if !data.is_null() {
Expand Down
16 changes: 14 additions & 2 deletions crates/rari-doc/src/templ/templs/cssinfo.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::fmt::Write;

use rari_templ_func::rari_f;
use rari_utils::concat_strs;
use serde_json::Value;

use crate::error::DocError;
use crate::helpers::css_info::{css_info_properties, mdn_data_files, write_computed_output};
use crate::helpers::css_info::{
css_info_properties, get_css_l10n_for_locale, mdn_data_files, write_computed_output,
};

#[rari_f]
pub fn cssinfo() -> Result<String, DocError> {
Expand All @@ -27,10 +30,19 @@ pub fn cssinfo() -> Result<String, DocError> {
} else {
data.css_properties.get(&name).unwrap_or(&Value::Null)
};
let props = css_info_properties(at_rule, env.locale, css_info_data)?;

if props.is_empty() {
return Ok(concat_strs!(
"<span style=\"color:red;\">",
get_css_l10n_for_locale("missing", env.locale),
"</span>"
));
}

let mut out = String::new();
out.push_str(r#"<table class="properties"><tbody>"#);
for (name, label) in css_info_properties(at_rule, env.locale, css_info_data)? {
for (name, label) in props {
write!(&mut out, r#"<tr><th scope="row">{label}</th><td>"#)?;
write_computed_output(env, &mut out, env.locale, css_info_data, name, at_rule)?;
write!(&mut out, r#"</td></tr>"#)?;
Expand Down

0 comments on commit bdcca17

Please sign in to comment.