@@ -8,7 +8,7 @@ use book::bookitem::BookItem;
88use { utils, theme} ;
99
1010use std:: path:: { Path , PathBuf } ;
11- use std:: fs:: File ;
11+ use std:: fs:: { self , File } ;
1212use std:: error:: Error ;
1313use std:: io:: { self , Read , Write } ;
1414use std:: collections:: BTreeMap ;
@@ -50,7 +50,7 @@ impl Renderer for HtmlHandlebars {
5050
5151 // Check if dest directory exists
5252 debug ! ( "[*]: Check if destination directory exists" ) ;
53- if let Err ( _) = utils :: create_path ( book. get_dest ( ) ) {
53+ if let Err ( _) = fs :: create_dir_all ( book. get_dest ( ) ) {
5454 return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Unexpected error when constructing destination path" ) ) )
5555 }
5656
@@ -159,42 +159,69 @@ impl Renderer for HtmlHandlebars {
159159
160160 debug ! ( "[*] Copy static files" ) ;
161161 // JavaScript
162- let mut js_file = try!( File :: create ( book. get_dest ( ) . join ( "book.js" ) ) ) ;
162+ let mut js_file = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "book.js" ) ) { f } else {
163+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create book.js" ) ) )
164+ } ;
163165 try!( js_file. write_all ( & theme. js ) ) ;
164166
165167 // Css
166- let mut css_file = try!( File :: create ( book. get_dest ( ) . join ( "book.css" ) ) ) ;
168+ let mut css_file = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "book.css" ) ) { f } else {
169+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create book.css" ) ) )
170+ } ;
167171 try!( css_file. write_all ( & theme. css ) ) ;
168172
169173 // JQuery local fallback
170- let mut jquery = try!( File :: create ( book. get_dest ( ) . join ( "jquery.js" ) ) ) ;
174+ let mut jquery = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "jquery.js" ) ) { f } else {
175+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create jquery.js" ) ) )
176+ } ;
171177 try!( jquery. write_all ( & theme. jquery ) ) ;
172178
179+ // syntax highlighting
180+ let mut highlight_css = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "highlight.css" ) ) { f } else {
181+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create highlight.css" ) ) )
182+ } ;
183+ try!( highlight_css. write_all ( & theme. highlight_css ) ) ;
184+
185+ let mut tomorrow_night_css = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "tomorrow-night.css" ) ) { f } else {
186+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create tomorrow-night.css" ) ) )
187+ } ;
188+ try!( tomorrow_night_css. write_all ( & theme. tomorrow_night_css ) ) ;
189+
190+ let mut highlight_js = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "highlight.js" ) ) { f } else {
191+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create highlight.js" ) ) )
192+ } ;
193+ try!( highlight_js. write_all ( & theme. highlight_js ) ) ;
194+
173195 // Font Awesome local fallback
174- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/css/font-awesome" ) . with_extension ( "css" ) ) ) ;
196+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/css/font-awesome.css" ) ) { f } else {
197+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create font-awesome.css" ) ) )
198+ } ;
175199 try!( font_awesome. write_all ( theme:: FONT_AWESOME ) ) ;
176- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.eot" ) ) ) ;
200+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.eot" ) ) { f } else {
201+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.eot" ) ) )
202+ } ;
177203 try!( font_awesome. write_all ( theme:: FONT_AWESOME_EOT ) ) ;
178- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.svg" ) ) ) ;
204+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.svg" ) ) { f } else {
205+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.svg" ) ) )
206+ } ;
179207 try!( font_awesome. write_all ( theme:: FONT_AWESOME_SVG ) ) ;
180- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.ttf" ) ) ) ;
208+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.ttf" ) ) { f } else {
209+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.ttf" ) ) )
210+ } ;
181211 try!( font_awesome. write_all ( theme:: FONT_AWESOME_TTF ) ) ;
182- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff" ) ) ) ;
212+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff" ) ) { f } else {
213+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.woff" ) ) )
214+ } ;
183215 try!( font_awesome. write_all ( theme:: FONT_AWESOME_WOFF ) ) ;
184- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff2" ) ) ) ;
216+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff2" ) ) { f } else {
217+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.woff2" ) ) )
218+ } ;
185219 try!( font_awesome. write_all ( theme:: FONT_AWESOME_WOFF2 ) ) ;
186- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/FontAwesome.ttf" ) ) ) ;
220+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/FontAwesome.ttf" ) ) { f } else {
221+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create FontAwesome.ttf" ) ) )
222+ } ;
187223 try!( font_awesome. write_all ( theme:: FONT_AWESOME_TTF ) ) ;
188224
189- // syntax highlighting
190- let mut highlight_css = try!( File :: create ( book. get_dest ( ) . join ( "highlight.css" ) ) ) ;
191- try!( highlight_css. write_all ( & theme. highlight_css ) ) ;
192- let mut tomorrow_night_css = try!( File :: create ( book. get_dest ( ) . join ( "tomorrow-night.css" ) ) ) ;
193- try!( tomorrow_night_css. write_all ( & theme. tomorrow_night_css ) ) ;
194- let mut highlight_js = try!( File :: create ( book. get_dest ( ) . join ( "highlight.js" ) ) ) ;
195- try!( highlight_js. write_all ( & theme. highlight_js ) ) ;
196-
197-
198225 // Copy all remaining files
199226 try!( utils:: copy_files_except_ext ( book. get_src ( ) , book. get_dest ( ) , true , & [ "md" ] ) ) ;
200227
0 commit comments