diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-09-09 02:16:54 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-09-09 02:16:54 +0800 |
commit | a0989292b9501af673b3d6148f055e5d7f3fb8c5 (patch) | |
tree | 12728fc16381b34bd496224a1025bb9feb1c57b3 | |
parent | afe9168fda6d43911fd3bdb3de785776d2402e30 (diff) |
Improve code readability on view by using arrays instead of vec
-rw-r--r-- | .github/workflows/rust.yml | 6 | ||||
-rw-r--r-- | svgbob/Cargo.toml | 7 | ||||
-rw-r--r-- | svgbob/src/buffer/cell_buffer.rs | 100 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/circle.rs | 4 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/line.rs | 4 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/polygon.rs | 4 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/rect.rs | 4 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/text.rs | 6 |
8 files changed, 71 insertions, 64 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6e0098c..d5eb81d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,3 +17,9 @@ jobs: - name: Run tests run: cargo test --verbose + + - name: Build no features + run: cargo build --all --no-default-features + + - name: Build with all features + run: cargo build --all --all-features diff --git a/svgbob/Cargo.toml b/svgbob/Cargo.toml index 357d7bf..fa4366d 100644 --- a/svgbob/Cargo.toml +++ b/svgbob/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svgbob" -version = "0.6.0" +version = "0.6.1" authors = ["Jovansonlee Cesar <ivanceras@gmail.com>"] edition = "2018" description = "Transform your ascii diagrams into happy little SVG" @@ -13,7 +13,8 @@ license = "Apache-2.0" nalgebra = "0.28" parry2d = "0.6" lazy_static = "1.3.0" -sauron = { version = "0.41"} +sauron = { version = "0.43", default-features = false} +#sauron = { version = "0.43", path = "../../sauron"} unicode-width = "0.1.5" itertools = "0.8.0" pom = { version = "3.1.0" } @@ -24,5 +25,5 @@ pom = { version = "3.1.0" } # This affects the rendering of text nodes # if the svg is rendered statically, characters such as '<' needed to be escaped # while if it is rendered in the dom, no escaping is needed. -with-dom = [] +with-dom = ["sauron/with-dom"] diff --git a/svgbob/src/buffer/cell_buffer.rs b/svgbob/src/buffer/cell_buffer.rs index a43ab42..c1f4421 100644 --- a/svgbob/src/buffer/cell_buffer.rs +++ b/svgbob/src/buffer/cell_buffer.rs @@ -268,7 +268,7 @@ impl CellBuffer { node }) .collect::<Vec<Node<MSG>>>(); - g(vec![], group_members) + g([], group_members) }) .collect(); @@ -310,87 +310,87 @@ impl CellBuffer { let font_size = settings.font_size.to_owned(); let element_styles = sauron::jss::jss! { - "line, path, circle,rect,polygon": { - "stroke": stroke_color.clone(), - "stroke-width": stroke_width.clone(), - "stroke-opacity": 1, - "fill-opacity": 1, - "stroke-linecap": "round", - "stroke-linejoin": "miter", + "line, path, circle, rect, polygon": { + stroke: stroke_color.clone(), + stroke_width: stroke_width.clone(), + stroke_opacity: 1, + fill_opacity: 1, + stroke_linecap: "round", + stroke_linejoin: "miter", }, "text": { /* This fix the spacing bug in svg text*/ - "white-space": "pre", - "fill": stroke_color.clone(), + white_space: "pre", + fill: stroke_color.clone(), }, "rect.backdrop":{ - "stroke": "none", - "fill": background.clone(), + stroke: "none", + fill: background.clone(), }, ".broken":{ - "stroke-dasharray": 8, + stroke_dasharray: 8, }, ".filled":{ - "fill": fill_color.clone(), + fill: fill_color.clone(), }, ".bg_filled":{ - "fill": background.clone(), + fill: background.clone(), }, ".nofill":{ - "fill": background.clone(), + fill: background.clone(), }, "text": { - "font-family": font_family.clone(), - "font-size": px(font_size.clone()), + font_family: font_family.clone(), + font_size: px(font_size.clone()), }, ".end_marked_arrow":{ - "marker-end": "url(#arrow)", + marker_end: "url(#arrow)", }, ".start_marked_arrow":{ - "marker-start": "url(#arrow)", + marker_start: "url(#arrow)", }, ".end_marked_diamond":{ - "marker-end": "url(#diamond)", + marker_end: "url(#diamond)", }, ".start_marked_diamond":{ - "marker-start": "url(#diamond)", + marker_start: "url(#diamond)", }, ".end_marked_circle":{ - "marker-end": "url(#circle)", + marker_end: "url(#circle)", }, ".start_marked_circle":{ - "marker-start": "url(#circle)", + marker_start: "url(#circle)", }, ".end_marked_open_circle":{ - "marker-end": "url(#open_circle)", + marker_end: "url(#open_circle)", }, ".start_marked_open_circle":{ - "marker-start": "url(#open_circle)", + marker_start: "url(#open_circle)", }, ".end_marked_big_open_circle":{ - "marker-end": "url(#big_open_circle)", + marker_end: "url(#big_open_circle)", }, ".start_marked_big_open_circle": { - "marker-start": "url(#big_open_circle)", + marker_start: "url(#big_open_circle)", } }; - html::tags::style(vec![], vec![text(element_styles), text(legend_css)]) + html::tags::style([], [text(element_styles), text(legend_css)]) } /// convert the fragments into svg nodes using the supplied settings, with size for the @@ -422,23 +422,23 @@ impl CellBuffer { // in accordance to how z-index works if settings.include_backdrop { children.push(rect( - vec![class("backdrop"), x(0), y(0), width(w), height(h)], - vec![], + [class("backdrop"), x(0), y(0), width(w), height(h)], + [], )); } children.extend(fragment_nodes); svg( - vec![xmlns("http://www.w3.org/2000/svg"), width(w), height(h)], + [xmlns("http://www.w3.org/2000/svg"), width(w), height(h)], children, ) } fn get_defs<MSG>() -> Node<MSG> { defs( - vec![], - vec![ + [], + [ Self::arrow_marker(), Self::diamond_marker(), Self::circle_marker(), @@ -450,7 +450,7 @@ impl CellBuffer { fn arrow_marker<MSG>() -> Node<MSG> { marker( - vec![ + [ id("arrow"), viewBox("-2 -2 8 8"), refX(4), @@ -459,13 +459,13 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![polygon(vec![points("0,0 0,4 4,2 0,0")], vec![])], + [polygon([points("0,0 0,4 4,2 0,0")], [])], ) } fn diamond_marker<MSG>() -> Node<MSG> { marker( - vec![ + [ id("diamond"), viewBox("-2 -2 8 8"), refX(4), @@ -474,13 +474,13 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![polygon(vec![points("0,2 2,0 4,2 2,4 0,2")], vec![])], + [polygon([points("0,2 2,0 4,2 2,4 0,2")], [])], ) } fn open_circle_marker<MSG>() -> Node<MSG> { marker( - vec![ + [ id("open_circle"), viewBox("0 0 8 8"), refX(4), @@ -489,16 +489,16 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle( - vec![cx(4), cy(4), r(2), html::attributes::class("bg_filled")], - vec![], + [circle( + [cx(4), cy(4), r(2), html::attributes::class("bg_filled")], + [], )], ) } fn circle_marker<MSG>() -> Node<MSG> { marker( - vec![ + [ id("circle"), viewBox("0 0 8 8"), refX(4), @@ -507,16 +507,16 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle( - vec![cx(4), cy(4), r(2), html::attributes::class("filled")], - vec![], + [circle( + [cx(4), cy(4), r(2), html::attributes::class("filled")], + [], )], ) } fn big_open_circle_marker<MSG>() -> Node<MSG> { marker( - vec![ + [ id("big_open_circle"), viewBox("0 0 8 8"), refX(4), @@ -525,9 +525,9 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle( - vec![cx(4), cy(4), r(3), html::attributes::class("bg_filled")], - vec![], + [circle( + [cx(4), cy(4), r(3), html::attributes::class("bg_filled")], + [], )], ) } diff --git a/svgbob/src/buffer/fragment_buffer/fragment/circle.rs b/svgbob/src/buffer/fragment_buffer/fragment/circle.rs index a77b44a..b49c38c 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/circle.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/circle.rs @@ -75,7 +75,7 @@ impl fmt::Display for Circle { impl<MSG> Into<Node<MSG>> for Circle { fn into(self) -> Node<MSG> { circle( - vec![ + [ cx(self.center.x), cy(self.center.y), r(self.radius), @@ -84,7 +84,7 @@ impl<MSG> Into<Node<MSG>> for Circle { ("nofill", !self.is_filled), ]), ], - vec![], + [], ) } } diff --git a/svgbob/src/buffer/fragment_buffer/fragment/line.rs b/svgbob/src/buffer/fragment_buffer/fragment/line.rs index 649e113..d113e40 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/line.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/line.rs @@ -516,7 +516,7 @@ impl fmt::Display for Line { impl<MSG> Into<Node<MSG>> for Line { fn into(self) -> Node<MSG> { svg::line( - vec![ + [ x1(self.start.x), y1(self.start.y), x2(self.end.x), @@ -526,7 +526,7 @@ impl<MSG> Into<Node<MSG>> for Line { ("solid", !self.is_broken), ]), ], - vec![], + [], ) } } diff --git a/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs b/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs index 42814c1..6ec42b9 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs @@ -206,7 +206,7 @@ impl Into<Polyline> for Polygon { impl<MSG> Into<Node<MSG>> for Polygon { fn into(self) -> Node<MSG> { polygon( - vec![ + [ points( self.points .iter() @@ -219,7 +219,7 @@ impl<MSG> Into<Node<MSG>> for Polygon { ("nofill", !self.is_filled), ]), ], - vec![], + [], ) } } diff --git a/svgbob/src/buffer/fragment_buffer/fragment/rect.rs b/svgbob/src/buffer/fragment_buffer/fragment/rect.rs index 7210c4a..2942991 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/rect.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/rect.rs @@ -150,7 +150,7 @@ impl Into<ConvexPolygon> for Rect { impl<MSG> Into<Node<MSG>> for Rect { fn into(self) -> Node<MSG> { rect( - vec![ + [ x(self.start.x), y(self.start.y), width(self.width()), @@ -167,7 +167,7 @@ impl<MSG> Into<Node<MSG>> for Rect { rx(0) }, ], - vec![], + [], ) } } diff --git a/svgbob/src/buffer/fragment_buffer/fragment/text.rs b/svgbob/src/buffer/fragment_buffer/fragment/text.rs index 71e2d1c..b2a444a 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/text.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/text.rs @@ -165,11 +165,11 @@ impl fmt::Display for Text { impl<MSG> Into<Node<MSG>> for Text { fn into(self) -> Node<MSG> { svg::tags::text( - vec![x(self.start.x), y(self.start.y)], + [x(self.start.x), y(self.start.y)], #[cfg(not(feature = "with-dom"))] - vec![text(escape_html_text(&self.text))], + [text(escape_html_text(&self.text))], #[cfg(feature = "with-dom")] - vec![text(&self.text)], + [text(&self.text)], ) } } |