Skip to content

Commit

Permalink
fix wrong code-branch icon variant in crate-details
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar authored and GuillaumeGomez committed Sep 24, 2024
1 parent 83909af commit d5a3784
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
38 changes: 38 additions & 0 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,44 @@ mod tests {
});
}

#[test]
fn details_with_repository_and_stats_can_render_icon() {
wrapper(|env| {
env.fake_release()
.name("library")
.version("0.1.0")
.repo("https://github.com/org/repo")
.github_stats("org/repo", 10, 10, 10)
.create()?;

let page = kuchikiki::parse_html().one(
env.frontend()
.get("/crate/library/0.1.0/")
.send()?
.error_for_status()?
.text()?,
);

let link = page
.select_first("a.pure-menu-link[href='https://github.com/org/repo']")
.unwrap();

let icon_node = link.as_node().children().nth(1).unwrap();
assert_eq!(
icon_node
.as_element()
.unwrap()
.attributes
.borrow()
.get("class")
.unwrap(),
"fa-svg"
);

Ok(())
});
}

#[test]
fn feature_flags_report_null() {
wrapper(|env| {
Expand Down
14 changes: 11 additions & 3 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::Result;
use crate::web::rustdoc::RustdocPage;
use anyhow::Context;
use anyhow::{anyhow, Context};
use rinja::Template;
use std::{fmt, sync::Arc};
use tracing::trace;
Expand Down Expand Up @@ -267,8 +267,16 @@ impl IconType {
IconType::Brand => font_awesome_as_a_crate::Type::Brands,
};

let icon_file_string = font_awesome_as_a_crate::svg(type_, icon_name)
.map_err(|err| rinja::Error::Custom(Box::new(err)))?;
let icon_file_string = font_awesome_as_a_crate::svg(type_, icon_name).map_err(|err| {
rinja::Error::Custom(
anyhow!(err)
.context(format!(
"error trying to render icon with name \"{}\" and type \"{}\"",
icon_name, type_,
))
.into(),
)
})?;

let mut classes = vec!["fa-svg"];
if fw {
Expand Down
2 changes: 1 addition & 1 deletion templates/crate/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{# If the repo link is for github or gitlab, show some stats #}
{# TODO: add support for hosts besides github and gitlab (#35) #}
{%- if let Some(repository_metadata) = repository_metadata -%}
{{ "code-branch"|fab(false, false, "") }}
{{ "code-branch"|fas(false, false, "") }}
{% if let Some(name) = repository_metadata.name %}
{{name}}
{% else %}
Expand Down

0 comments on commit d5a3784

Please sign in to comment.