#svg #html #xml #tag #markup

tagger

Write SVG / HTML / XML programmatically

26 releases (8 stable)

3.2.1 Sep 30, 2021
3.0.2 Jul 31, 2021
2.2.1 Jul 29, 2021
1.0.1 Apr 13, 2021
0.7.1 Mar 8, 2021

#21 in Template engine

Download history 8/week @ 2021-06-28 12/week @ 2021-07-05 10/week @ 2021-07-12 97/week @ 2021-07-19 132/week @ 2021-07-26 187/week @ 2021-08-02 13/week @ 2021-08-09 90/week @ 2021-08-16 12/week @ 2021-08-23 19/week @ 2021-08-30 10/week @ 2021-09-06 24/week @ 2021-09-13 11/week @ 2021-09-20 101/week @ 2021-09-27 18/week @ 2021-10-04 71/week @ 2021-10-11

219 downloads per month
Used in 2 crates (via poloto)

MIT license

11KB
222 lines

Overview

Build xml / html / svg programatically using element building blocks. Instead of using a templating engine, write data/markup that 'looks like' rust.

Find it on github and crates.io.

Tagger also provides functionality to build svg paths and polyline attribute data.

Example

fn main() {
    let width = 100.0;
    let height = 100.0;

    let mut w = tagger::new(tagger::upgrade_write(std::io::stdout()));

    w.elem("svg", |d| {
        d.attr("xmlns", "http://www.w3.org/2000/svg")
            .attr("viewBox", format_args!("0 0 {} {}", width, height));
    })
    .build(|w| {
        w.single("rect", |d| {
            d.attr("x1", 0)
                .attr("y1", 0)
                .attr("rx", 20)
                .attr("ry", 20)
                .attr("width", width)
                .attr("height", height)
                .attr("style", "fill:blue");
        });

        w.elem("style", tagger::no_attr()).build(|w| {
            w.put_raw(".test{fill:none;stroke:white;stroke-width:3}");
        });

        w.elem("g", |d| {
            d.attr("class", "test");
        })
        .build(|w| {
            for r in (0..50).step_by(10) {
                w.single("circle", |w| {
                    w.attr("cx", 50.0).attr("cy", 50.0).attr("r", r);
                });
            }
        });
    });
}


Output

demo

No runtime deps