File tree 8 files changed +70
-1
lines changed
8 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ cfg-if = "0.1"
51
51
52
52
parking_lot = " 0.10"
53
53
54
+ # This dependency should be uncommented when rebuilding the images in the API
55
+ # documentation. In all other cases this dependency cannot be used since having
56
+ # a path-only dependency would make it impossible to publish this crate.
57
+ # turtle_docs_helpers = { path = "turtle_docs_helpers" }
58
+
54
59
[dependencies .futures-util ]
55
60
version = " 0.3"
56
61
default-features = false
Original file line number Diff line number Diff line change @@ -188,3 +188,10 @@ impl AsyncDrawing {
188
188
self . client . debug_drawing ( ) . await
189
189
}
190
190
}
191
+
192
+ #[ cfg( docs_images) ]
193
+ impl turtle_docs_helpers:: SaveDocsSvg for AsyncDrawing {
194
+ fn save_docs_svg ( & self , path : std:: path:: PathBuf ) {
195
+ self . client . save_docs_svg ( path) ;
196
+ }
197
+ }
Original file line number Diff line number Diff line change @@ -324,3 +324,10 @@ impl AsyncTurtle {
324
324
self . client . debug_turtle ( self . id , self . angle_unit ) . await
325
325
}
326
326
}
327
+
328
+ #[ cfg( docs_images) ]
329
+ impl turtle_docs_helpers:: SaveDocsSvg for AsyncTurtle {
330
+ fn save_docs_svg ( & self , path : std:: path:: PathBuf ) {
331
+ self . client . save_docs_svg ( path) ;
332
+ }
333
+ }
Original file line number Diff line number Diff line change @@ -629,6 +629,13 @@ impl Drawing {
629
629
}
630
630
}
631
631
632
+ #[ cfg( docs_images) ]
633
+ impl turtle_docs_helpers:: SaveDocsSvg for Drawing {
634
+ fn save_docs_svg ( & self , path : std:: path:: PathBuf ) {
635
+ self . drawing . save_docs_svg ( path) ;
636
+ }
637
+ }
638
+
632
639
#[ cfg( test) ]
633
640
mod tests {
634
641
use super :: * ;
Original file line number Diff line number Diff line change @@ -408,3 +408,12 @@ impl ProtocolClient {
408
408
}
409
409
}
410
410
}
411
+
412
+ #[ cfg( docs_images) ]
413
+ impl turtle_docs_helpers:: SaveDocsSvg for ProtocolClient {
414
+ fn save_docs_svg ( & self , path : std:: path:: PathBuf ) {
415
+ use crate :: sync_runtime:: block_on;
416
+ block_on ( self . export_svg ( path) )
417
+ . expect ( "unable to save docs image" ) ;
418
+ }
419
+ }
Original file line number Diff line number Diff line change @@ -535,7 +535,7 @@ impl Turtle {
535
535
///
536
536
/// # Example
537
537
///
538
- /// ```rust,no_run
538
+ /// ```rust
539
539
/// use turtle::Turtle;
540
540
///
541
541
/// fn main() {
@@ -557,6 +557,7 @@ impl Turtle {
557
557
/// turtle.set_pen_color("#4CAF50"); // green
558
558
/// turtle.set_pen_size(100.0);
559
559
/// turtle.forward(200.0);
560
+ /// # #[cfg(docs_images)] turtle_docs_helpers::save_docs_image(&turtle, "pen_thickness");
560
561
/// }
561
562
/// ```
562
563
///
@@ -891,6 +892,13 @@ impl Turtle {
891
892
}
892
893
}
893
894
895
+ #[ cfg( docs_images) ]
896
+ impl turtle_docs_helpers:: SaveDocsSvg for Turtle {
897
+ fn save_docs_svg ( & self , path : std:: path:: PathBuf ) {
898
+ self . turtle . save_docs_svg ( path) ;
899
+ }
900
+ }
901
+
894
902
#[ cfg( test) ]
895
903
mod tests {
896
904
use super :: * ;
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " turtle_docs_helpers"
3
+ version = " 0.1.0"
4
+ authors = [
" Sunjay Varma <[email protected] >" ]
5
+ edition = " 2018"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+
9
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ use std:: path:: { Path , PathBuf } ;
2
+
3
+ /// Saves the image being drawn as an SVG and panics if an error occurs
4
+ ///
5
+ /// This is different from the `save_svg` method on `Drawing` and `AsyncDrawing`
6
+ /// because this is only meant to be used for automation and may need to access
7
+ /// internal APIs.
8
+ pub trait SaveDocsSvg {
9
+ fn save_docs_svg ( & self , path : PathBuf ) ;
10
+ }
11
+
12
+ /// Saves the currently drawn image to `docs/assets/images/docs/{output_name}`
13
+ pub fn save_docs_image < T : SaveDocsSvg > ( drawing : & T , output_name : & str ) {
14
+ let svg_path = Path :: new ( "docs/assets/images/docs" ) . join ( output_name) . with_extension ( "svg" ) ;
15
+ drawing. save_docs_svg ( svg_path) ;
16
+ todo ! ( )
17
+ }
You can’t perform that action at this time.
0 commit comments