Skip to content

Commit

Permalink
link to lists of crates with options
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Apr 3, 2024
1 parent f63f320 commit 2d58ddc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
27 changes: 23 additions & 4 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ pub fn generate_pages(crates: &[Crate]) -> Result<(), Box<dyn Error>> {
]);

render_stats_page(crates.len(), &stats);
generate_rustfmt_pages(crates.len(), &stats);
generate_rustfmt_pages(crates.len(), &stats, crates)?;

Ok(())
}
Expand Down Expand Up @@ -736,7 +736,11 @@ fn load_collected_rustfmt() -> Vec<(String, String, String)> {
rustfmt
}

fn generate_rustfmt_pages(number_of_crates: usize, stats: &HashMap<&str, usize>) {
fn generate_rustfmt_pages(
number_of_crates: usize,
stats: &HashMap<&str, usize>,
crates: &[Crate],
) -> Result<(), Box<dyn Error>> {
let rustfmt = load_collected_rustfmt();
let mut count_by_key: HashMap<String, u32> = HashMap::new();
let mut count_by_pair: HashMap<(String, String), u32> = HashMap::new();
Expand Down Expand Up @@ -765,6 +769,21 @@ fn generate_rustfmt_pages(number_of_crates: usize, stats: &HashMap<&str, usize>)
count_by_pair.sort_by(|a, b| a.0.partial_cmp(b.0).unwrap());
//count_by_pair.reverse();

#[allow(clippy::pattern_type_mismatch)] // TODO
for (field, _count) in &count_by_key {
let crate_names = rustfmt
.iter()
.filter(|entry| &&entry.0 == field)
.map(|entry| &entry.2)
.collect::<Vec<&String>>();
render_filtered_crates(
&format!("rustfmt/{field}"),
&format!("Crates using the {field} formatting option"),
crates,
|krate| crate_names.contains(&&krate.name),
)?;
}

let partials = load_templates().unwrap();

let template = liquid::ParserBuilder::with_stdlib()
Expand All @@ -781,8 +800,6 @@ fn generate_rustfmt_pages(number_of_crates: usize, stats: &HashMap<&str, usize>)
"version": format!("{VERSION}"),
"utc": format!("{}", utc),
"title": "Rustfmt Stats",
//"user": user,
//"crate": krate,
"count_by_key": count_by_key,
"count_by_pair": count_by_pair,
"stats": stats,
Expand All @@ -792,6 +809,8 @@ fn generate_rustfmt_pages(number_of_crates: usize, stats: &HashMap<&str, usize>)
let html = template.render(&globals).unwrap();
let mut file = File::create(filename).unwrap();
writeln!(&mut file, "{html}").unwrap();

Ok(())
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions templates/incl/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</div>
<a href="/users/" class="navbar-item">Owners</a>
<a href="/vcs/" class="navbar-item">VCS</a>
<a href="/rustfmt/" class="navbar-item">fmt</a>
<a href="/news/" class="navbar-item">News</a>
<a href="/training" class="navbar-item">Training</a>
<a href="/support" class="navbar-item">Support</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/rustfmt.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 id="config-options" class="title">Config option used</h2>
<tbody>
{% for pair in count_by_key %}
<tr>
<td>{{ pair[0] }}</td>
<td><a href="/rustfmt/{{ pair[0] }}">{{ pair[0] }}</a></td>
<td>{{ pair[1] | commafy }}</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit 2d58ddc

Please sign in to comment.