83 releases (4 breaking)

new 0.5.26 Jan 15, 2021
0.5.15 Aug 11, 2020
0.5.12 Jul 31, 2020

#29 in Template engine

Download history 85/week @ 2020-09-27 8/week @ 2020-10-04 15/week @ 2020-10-11 84/week @ 2020-10-18 13/week @ 2020-10-25 8/week @ 2020-11-01 97/week @ 2020-11-08 34/week @ 2020-11-15 107/week @ 2020-11-22 12/week @ 2020-11-29 158/week @ 2020-12-06 4/week @ 2020-12-13 7/week @ 2020-12-20 26/week @ 2020-12-27 34/week @ 2021-01-03 105/week @ 2021-01-10

222 downloads per month
Used in 6 crates (5 directly)

MIT/Apache

740KB
344 lines

Rusty Domain Extensible Language

Crates.IO Documentation Build Nightly Build Donate using Liberapay

Domain specific language macros and component system for Rust to generate xhtml. (pronounced "Rad Axle")

Rdxl is implemented as procedural macros, so there are no runtime dependencies other than for string manipulation. This means that rdxl can be used both for server-side or client-side through web assembly.

let my_int = 3;
let my_str = "asdf";
let my_vec = vec![true, false, true, true];

println!("{}",xhtml!(<ul>
   {{ for v in my_vec.iter() {{
      <li>{{my_int}}, {{my_str}}, {{v}}</li>
   }} }}
</ul>));

Modularized templating is encouraged through custom XML elements that implement the Display property. Foreign xhtml snippets or miscellaneous content can be inserted inline as long as it also implements the Display trait.

xtype!(<!MyList my_string:String my_int:u64>
   <!MyItem my_bool:bool/>
   <!MyOtherItem my_char:char/>
</MyList>);

xrender!(MyList, <ul>
  <li>{{ self.my_string }}</li>
  <li>{{ self.my_int }}</li>
  {{ for i in self.children.iter() {{
    {{ if let MyListChildren::MyItem(my_item) = i {{
      <li>MyItem: {{ my_item.my_bool }}</li>
    }} else if let MyListChildren::MyOtherItem(my_other_item) = i {{
      <li>MyOtherItem: {{ my_other_item.my_char }}</li>
    }} }}
  }} }}
</ul>);

Foreign syntaxes, like Javascript, may be quoted inline with cooked or raw strings.

xrender!(BarGraph,
  <script src="https://d3js.org/d3.v4.min.js"></script>
  <script>
    r#"var margin = {top: 20, right: 20, bottom: 30, left: 40},
           width = 960 - margin.left - margin.right,
           height = 500 - margin.top - margin.bottom;"#
    ...
  </script>
);

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in rdxl by you, shall be dual licensed under the MIT and Apache 2.0 license without any additional terms or conditions.

Dependencies