1+ use alloc:: collections:: BTreeMap ;
12use core:: cmp:: Ordering ;
23use std:: fs:: File ;
34
4- use hashbrown:: HashMap ;
55use serde:: Serialize ;
66use tera:: { Context , Tera } ;
77use toml_edit:: { DocumentMut , Item } ;
@@ -81,7 +81,7 @@ fn parse_examples(panic_on_missing: bool) -> Vec<Example> {
8181 . collect ( )
8282}
8383
84- fn parse_categories ( ) -> HashMap < Box < str > , String > {
84+ fn parse_categories ( ) -> BTreeMap < String , String > {
8585 let manifest_file = std:: fs:: read_to_string ( "Cargo.toml" ) . unwrap ( ) ;
8686 let manifest = manifest_file. parse :: < DocumentMut > ( ) . unwrap ( ) ;
8787 manifest
@@ -108,10 +108,10 @@ pub(crate) fn check(what_to_run: Command) {
108108
109109 if what_to_run. contains ( Command :: UPDATE ) {
110110 let categories = parse_categories ( ) ;
111- let examples_by_category: HashMap < Box < str > , Category > = examples
111+ let examples_by_category: BTreeMap < String , Category > = examples
112112 . into_iter ( )
113- . fold ( HashMap :: < Box < str > , Vec < Example > > :: new ( ) , |mut v, ex| {
114- v. entry_ref ( ex. category . as_str ( ) ) . or_default ( ) . push ( ex) ;
113+ . fold ( BTreeMap :: < String , Vec < Example > > :: new ( ) , |mut v, ex| {
114+ v. entry ( ex. category . clone ( ) ) . or_default ( ) . push ( ex) ;
115115 v
116116 } )
117117 . into_iter ( )
@@ -130,13 +130,16 @@ pub(crate) fn check(what_to_run: Command) {
130130
131131 let mut context = Context :: new ( ) ;
132132 context. insert ( "all_examples" , & examples_by_category) ;
133- Tera :: new ( "docs-template/*.md.tpl" )
134- . expect ( "error parsing template" )
135- . render_to (
136- "EXAMPLE_README.md.tpl" ,
137- & context,
138- File :: create ( "examples/README.md" ) . expect ( "error creating file" ) ,
139- )
140- . expect ( "error rendering template" ) ;
133+ let mut tera = Tera :: new ( ) ;
134+ tera. register_filter ( "slugify" , tera_contrib:: slug:: slug) ;
135+ tera. load_from_glob ( "docs-template/*.md.tpl" )
136+ . expect ( "error parsing template" ) ;
137+
138+ tera. render_to (
139+ "EXAMPLE_README.md.tpl" ,
140+ & context,
141+ File :: create ( "examples/README.md" ) . expect ( "error creating file" ) ,
142+ )
143+ . expect ( "error rendering template" ) ;
141144 }
142145}
0 commit comments