@@ -47,58 +47,49 @@ fn get_git_hash() -> Result<Option<String>> {
4747 }
4848}
4949
50- fn compile_sass_file (
51- out_dir : & Path ,
52- name : & str ,
53- target : & str ,
54- include_paths : & [ String ] ,
55- ) -> Result < ( ) > {
56- use sass_rs:: { Context , Options , OutputStyle } ;
57-
58- const STYLE_DIR : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/templates/style" ) ;
59-
60- let include_paths = {
61- let mut paths = vec ! [ STYLE_DIR . to_owned( ) ] ;
62- paths. extend_from_slice ( include_paths) ;
63- paths
64- } ;
65-
66- for path in & include_paths {
67- for entry in walkdir:: WalkDir :: new ( path) {
68- println ! ( "cargo:rerun-if-changed={}" , entry?. path( ) . display( ) ) ;
69- }
70- }
50+ fn compile_sass_file ( src : & Path , dest : & Path ) -> Result < ( ) > {
51+ let css = grass:: from_path (
52+ src. to_str ( )
53+ . context ( "source file path must be a utf-8 string" ) ?,
54+ & grass:: Options :: default ( ) . style ( grass:: OutputStyle :: Compressed ) ,
55+ )
56+ . map_err ( |e| Error :: msg ( e. to_string ( ) ) ) ?;
7157
72- let mut context =
73- Context :: new_file ( format ! ( "{}/{}.scss" , STYLE_DIR , name) ) . map_err ( Error :: msg) ?;
74- context. set_options ( Options {
75- output_style : OutputStyle :: Compressed ,
76- include_paths,
77- ..Default :: default ( )
78- } ) ;
79-
80- let css = context. compile ( ) . map_err ( Error :: msg) ?;
81- let dest_path = out_dir. join ( format ! ( "{}.css" , target) ) ;
82- std:: fs:: write ( dest_path, css) ?;
58+ std:: fs:: write ( dest, css) ?;
8359
8460 Ok ( ( ) )
8561}
8662
8763fn compile_sass ( out_dir : & Path ) -> Result < ( ) > {
88- // Compile base.scss -> style.css
89- compile_sass_file ( out_dir, "base" , "style" , & [ ] ) ?;
90-
91- // Compile rustdoc.scss -> rustdoc.css
92- compile_sass_file ( out_dir, "rustdoc" , "rustdoc" , & [ ] ) ?;
93- compile_sass_file ( out_dir, "rustdoc-2021-12-05" , "rustdoc-2021-12-05" , & [ ] ) ?;
94-
95- // Compile vendored.scss -> vendored.css
96- compile_sass_file (
97- out_dir,
98- "vendored" ,
99- "vendored" ,
100- & [ concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/vendor/pure-css/css" ) . to_owned ( ) ] ,
101- ) ?;
64+ const STYLE_DIR : & str = "templates/style" ;
65+
66+ for entry in walkdir:: WalkDir :: new ( STYLE_DIR ) {
67+ let entry = entry?;
68+ println ! (
69+ "cargo:rerun-if-changed={}" ,
70+ entry
71+ . path( )
72+ . to_str( )
73+ . with_context( || format!( "{} is a non-utf-8 path" , entry. path( ) . display( ) ) ) ?
74+ ) ;
75+ let file_name = entry. file_name ( ) . to_str ( ) . unwrap ( ) ;
76+ if entry. metadata ( ) ?. is_file ( ) && !file_name. starts_with ( '_' ) {
77+ let dest = out_dir
78+ . join ( entry. path ( ) . strip_prefix ( STYLE_DIR ) ?)
79+ . with_extension ( "css" ) ;
80+ compile_sass_file ( entry. path ( ) , & dest) . with_context ( || {
81+ format ! ( "compiling {} to {}" , entry. path( ) . display( ) , dest. display( ) )
82+ } ) ?;
83+ }
84+ }
85+
86+ // Compile vendored.css
87+ println ! ( "cargo:rerun-if-changed=vendor/pure-css/css/pure-min.css" ) ;
88+ let pure = std:: fs:: read_to_string ( "vendor/pure-css/css/pure-min.css" ) ?;
89+ println ! ( "cargo:rerun-if-changed=vendor/pure-css/css/grids-responsive-min.css" ) ;
90+ let grids = std:: fs:: read_to_string ( "vendor/pure-css/css/grids-responsive-min.css" ) ?;
91+ let vendored = pure + & grids;
92+ std:: fs:: write ( out_dir. join ( "vendored" ) . with_extension ( "css" ) , vendored) ?;
10293
10394 Ok ( ( ) )
10495}
0 commit comments