@@ -8,8 +8,8 @@ use std::io::{Read, Write};
8
8
use std:: process:: Command ;
9
9
use tempdir:: TempDir ;
10
10
11
- use { theme , parse , utils} ;
12
- use renderer:: { Renderer , HtmlHandlebars } ;
11
+ use { parse , theme , utils} ;
12
+ use renderer:: { HtmlHandlebars , Renderer } ;
13
13
use preprocess;
14
14
use errors:: * ;
15
15
@@ -60,7 +60,6 @@ impl MDBook {
60
60
/// [`set_dest()`](#method.set_dest)
61
61
62
62
pub fn new < P : Into < PathBuf > > ( root : P ) -> MDBook {
63
-
64
63
let root = root. into ( ) ;
65
64
if !root. exists ( ) || !root. is_dir ( ) {
66
65
warn ! ( "{:?} No directory with that name" , root) ;
@@ -130,7 +129,6 @@ impl MDBook {
130
129
/// `chapter_1.md` to the source directory.
131
130
132
131
pub fn init ( & mut self ) -> Result < ( ) > {
133
-
134
132
debug ! ( "[fn]: init" ) ;
135
133
136
134
if !self . config . get_root ( ) . exists ( ) {
@@ -139,7 +137,6 @@ impl MDBook {
139
137
}
140
138
141
139
{
142
-
143
140
if !self . get_destination ( ) . exists ( ) {
144
141
debug ! ( "[*]: {:?} does not exist, trying to create directory" , self . get_destination( ) ) ;
145
142
fs:: create_dir_all ( self . get_destination ( ) ) ?;
@@ -154,7 +151,6 @@ impl MDBook {
154
151
let summary = self . config . get_source ( ) . join ( "SUMMARY.md" ) ;
155
152
156
153
if !summary. exists ( ) {
157
-
158
154
// Summary does not exist, create it
159
155
debug ! ( "[*]: {:?} does not exist, trying to create SUMMARY.md" , & summary) ;
160
156
let mut f = File :: create ( & summary) ?;
@@ -175,16 +171,14 @@ impl MDBook {
175
171
debug ! ( "[*]: item: {:?}" , item) ;
176
172
let ch = match * item {
177
173
BookItem :: Spacer => continue ,
178
- BookItem :: Chapter ( _, ref ch) |
179
- BookItem :: Affix ( ref ch) => ch,
174
+ BookItem :: Chapter ( _, ref ch) | BookItem :: Affix ( ref ch) => ch,
180
175
} ;
181
176
if !ch. path . as_os_str ( ) . is_empty ( ) {
182
177
let path = self . config . get_source ( ) . join ( & ch. path ) ;
183
178
184
179
if !path. exists ( ) {
185
180
if !self . create_missing {
186
- return Err ( format ! ( "'{}' referenced from SUMMARY.md does not exist." , path. to_string_lossy( ) )
187
- . into ( ) ) ;
181
+ return Err ( format ! ( "'{}' referenced from SUMMARY.md does not exist." , path. to_string_lossy( ) ) . into ( ) ) ;
188
182
}
189
183
debug ! ( "[*]: {:?} does not exist, trying to create file" , path) ;
190
184
:: std:: fs:: create_dir_all ( path. parent ( ) . unwrap ( ) ) ?;
@@ -203,14 +197,15 @@ impl MDBook {
203
197
pub fn create_gitignore ( & self ) {
204
198
let gitignore = self . get_gitignore ( ) ;
205
199
206
- let destination = self . config . get_html_config ( )
207
- . get_destination ( ) ;
200
+ let destination = self . config . get_html_config ( ) . get_destination ( ) ;
208
201
209
- // Check that the gitignore does not extist and that the destination path begins with the root path
210
- // We assume tha if it does begin with the root path it is contained within. This assumption
211
- // will not hold true for paths containing double dots to go back up e.g. `root/../destination`
202
+ // Check that the gitignore does not extist and that the destination path
203
+ // begins with the root path
204
+ // We assume tha if it does begin with the root path it is contained within.
205
+ // This assumption
206
+ // will not hold true for paths containing double dots to go back up e.g.
207
+ // `root/../destination`
212
208
if !gitignore. exists ( ) && destination. starts_with ( self . config . get_root ( ) ) {
213
-
214
209
let relative = destination
215
210
. strip_prefix ( self . config . get_root ( ) )
216
211
. expect ( "Could not strip the root prefix, path is not relative to root" )
@@ -286,8 +281,7 @@ impl MDBook {
286
281
}
287
282
288
283
pub fn write_file < P : AsRef < Path > > ( & self , filename : P , content : & [ u8 ] ) -> Result < ( ) > {
289
- let path = self . get_destination ( )
290
- . join ( filename) ;
284
+ let path = self . get_destination ( ) . join ( filename) ;
291
285
292
286
utils:: fs:: create_file ( & path) ?
293
287
. write_all ( content)
@@ -300,7 +294,6 @@ impl MDBook {
300
294
/// The root directory is the one specified when creating a new `MDBook`
301
295
302
296
pub fn read_config ( mut self ) -> Result < Self > {
303
-
304
297
let toml = self . get_root ( ) . join ( "book.toml" ) ;
305
298
let json = self . get_root ( ) . join ( "book.json" ) ;
306
299
@@ -356,31 +349,33 @@ impl MDBook {
356
349
pub fn test ( & mut self , library_paths : Vec < & str > ) -> Result < ( ) > {
357
350
// read in the chapters
358
351
self . parse_summary ( ) . chain_err ( || "Couldn't parse summary" ) ?;
359
- let library_args: Vec < & str > = ( 0 ..library_paths. len ( ) ) . map ( |_| "-L" )
360
- . zip ( library_paths. into_iter ( ) )
361
- . flat_map ( |x| vec ! [ x. 0 , x. 1 ] )
362
- . collect ( ) ;
352
+ let library_args: Vec < & str > = ( 0 ..library_paths. len ( ) )
353
+ . map ( |_| "-L" )
354
+ . zip ( library_paths. into_iter ( ) )
355
+ . flat_map ( |x| vec ! [ x. 0 , x. 1 ] )
356
+ . collect ( ) ;
363
357
let temp_dir = TempDir :: new ( "mdbook" ) ?;
364
358
for item in self . iter ( ) {
365
-
366
359
if let BookItem :: Chapter ( _, ref ch) = * item {
367
360
if !ch. path . as_os_str ( ) . is_empty ( ) {
368
-
369
361
let path = self . get_source ( ) . join ( & ch. path ) ;
370
- let base = path. parent ( ) . ok_or_else (
371
- || String :: from ( "Invalid bookitem path!" ) ,
372
- ) ?;
362
+ let base = path. parent ( )
363
+ . ok_or_else ( || String :: from ( "Invalid bookitem path!" ) ) ?;
373
364
let content = utils:: fs:: file_to_string ( & path) ?;
374
365
// Parse and expand links
375
366
let content = preprocess:: links:: replace_all ( & content, base) ?;
376
367
println ! ( "[*]: Testing file: {:?}" , path) ;
377
368
378
- //write preprocessed file to tempdir
369
+ // write preprocessed file to tempdir
379
370
let path = temp_dir. path ( ) . join ( & ch. path ) ;
380
371
let mut tmpf = utils:: fs:: create_file ( & path) ?;
381
372
tmpf. write_all ( content. as_bytes ( ) ) ?;
382
373
383
- let output = Command :: new ( "rustdoc" ) . arg ( & path) . arg ( "--test" ) . args ( & library_args) . output ( ) ?;
374
+ let output = Command :: new ( "rustdoc" )
375
+ . arg ( & path)
376
+ . arg ( "--test" )
377
+ . args ( & library_args)
378
+ . output ( ) ?;
384
379
385
380
if !output. status . success ( ) {
386
381
bail ! ( ErrorKind :: Subprocess ( "Rustdoc returned an error" . to_string( ) , output) ) ;
@@ -398,15 +393,15 @@ impl MDBook {
398
393
399
394
pub fn with_destination < T : Into < PathBuf > > ( mut self , destination : T ) -> Self {
400
395
let root = self . config . get_root ( ) . to_owned ( ) ;
401
- self . config . get_mut_html_config ( )
396
+ self . config
397
+ . get_mut_html_config ( )
402
398
. set_destination ( & root, & destination. into ( ) ) ;
403
399
self
404
400
}
405
401
406
402
407
403
pub fn get_destination ( & self ) -> & Path {
408
- self . config . get_html_config ( )
409
- . get_destination ( )
404
+ self . config . get_html_config ( ) . get_destination ( )
410
405
}
411
406
412
407
pub fn with_source < T : Into < PathBuf > > ( mut self , source : T ) -> Self {
@@ -452,61 +447,56 @@ impl MDBook {
452
447
453
448
pub fn with_theme_path < T : Into < PathBuf > > ( mut self , theme_path : T ) -> Self {
454
449
let root = self . config . get_root ( ) . to_owned ( ) ;
455
- self . config . get_mut_html_config ( )
450
+ self . config
451
+ . get_mut_html_config ( )
456
452
. set_theme ( & root, & theme_path. into ( ) ) ;
457
453
self
458
454
}
459
455
460
456
pub fn get_theme_path ( & self ) -> & Path {
461
- self . config . get_html_config ( )
462
- . get_theme ( )
457
+ self . config . get_html_config ( ) . get_theme ( )
463
458
}
464
459
465
460
pub fn with_curly_quotes ( mut self , curly_quotes : bool ) -> Self {
466
- self . config . get_mut_html_config ( )
461
+ self . config
462
+ . get_mut_html_config ( )
467
463
. set_curly_quotes ( curly_quotes) ;
468
464
self
469
465
}
470
466
471
467
pub fn get_curly_quotes ( & self ) -> bool {
472
- self . config . get_html_config ( )
473
- . get_curly_quotes ( )
468
+ self . config . get_html_config ( ) . get_curly_quotes ( )
474
469
}
475
470
476
471
pub fn with_mathjax_support ( mut self , mathjax_support : bool ) -> Self {
477
- self . config . get_mut_html_config ( )
472
+ self . config
473
+ . get_mut_html_config ( )
478
474
. set_mathjax_support ( mathjax_support) ;
479
475
self
480
476
}
481
477
482
478
pub fn get_mathjax_support ( & self ) -> bool {
483
- self . config . get_html_config ( )
484
- . get_mathjax_support ( )
479
+ self . config . get_html_config ( ) . get_mathjax_support ( )
485
480
}
486
481
487
482
pub fn get_google_analytics_id ( & self ) -> Option < String > {
488
- self . config . get_html_config ( )
489
- . get_google_analytics_id ( )
483
+ self . config . get_html_config ( ) . get_google_analytics_id ( )
490
484
}
491
485
492
486
pub fn has_additional_js ( & self ) -> bool {
493
- self . config . get_html_config ( )
494
- . has_additional_js ( )
487
+ self . config . get_html_config ( ) . has_additional_js ( )
495
488
}
496
489
497
490
pub fn get_additional_js ( & self ) -> & [ PathBuf ] {
498
- self . config . get_html_config ( )
499
- . get_additional_js ( )
491
+ self . config . get_html_config ( ) . get_additional_js ( )
500
492
}
501
493
502
494
pub fn has_additional_css ( & self ) -> bool {
503
- self . config . get_html_config ( )
504
- . has_additional_css ( )
495
+ self . config . get_html_config ( ) . has_additional_css ( )
505
496
}
506
497
507
498
pub fn get_additional_css ( & self ) -> & [ PathBuf ] {
508
- self . config . get_html_config ( )
509
- . get_additional_css ( )
499
+ self . config . get_html_config ( ) . get_additional_css ( )
510
500
}
511
501
512
502
pub fn get_html_config ( & self ) -> & HtmlConfig {
0 commit comments