#svg #html #xml #tag #markup

tagger

Write SVG / HTML / XML programmatically

23 releases (5 stable)

new 2.1.2 Jul 23, 2021
1.0.1 Apr 13, 2021
0.7.1 Mar 8, 2021

#22 in Template engine

Download history 45/week @ 2021-04-07 107/week @ 2021-04-14 33/week @ 2021-04-21 27/week @ 2021-04-28 9/week @ 2021-05-05 23/week @ 2021-05-12 24/week @ 2021-05-19 8/week @ 2021-05-26 6/week @ 2021-06-02 28/week @ 2021-06-09 6/week @ 2021-06-16 8/week @ 2021-06-23 13/week @ 2021-06-30 9/week @ 2021-07-07 51/week @ 2021-07-14 64/week @ 2021-07-21

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

MIT license

14KB
334 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

use tagger::attr_builder;
use tagger::prelude::*;

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

    let mut svg = elem!(
        "svg",
        attr_builder()
            .attr("xmlns", "http://www.w3.org/2000/svg")
            .attr("viewBox", formatm!("0 0 {} {}", width, height))
            .build()
    );

    let rect_attr = attr_builder()
        .attr("x1", 0)
        .attr("y1", 0)
        .attr("rx", 20)
        .attr("ry", 20)
        .attr("width", width)
        .attr("height", height)
        .attr("style", "fill:blue")
        .build();

    svg.append(single!("rect", rect_attr));

    svg.append(elem!("style").appendm(single!(".test{fill:none;stroke:white;stroke-width:3}")));

    let mut g = elem!("g", attr_builder().attr("class", "test").build());
    for r in (0..50).step_by(10) {
        g.append(single!(
            "circle",
            attr_builder()
                .attr("cx", 50.0)
                .attr("cy", 50.0)
                .attr("r", r)
                .build()
        ));
    }
    svg.append(g);

    println!("{}", svg);
}

Output

demo

No runtime deps