Map to JavaScript in HTML
This is a library for serializing a map to JavaScript code in HTML, usually for dynamically generating strings on web pages.
Usage
In your HTML or templates to generate HTML, such as Handlebars, for instance,
Then, you can use the MapToJavaScriptHTML
trait to insert your text from a map,
extern crate map_to_javascript_html;
use BTreeMap;
use MapToJavaScriptHTML;
let mut map = new;
map.insert;
map.insert;
map.insert;
let text = map.to_javascript_html;
assert_eq!;
After Handlebars replaces {{{text}}} with your text, the HTML will be,
The key and the value used in a map must implement the Display
trait.
Methods suffixed with _to_string
, _to_vec
, _to_writer
can be used to generate HTML.
There are also methods prefixed with to_javascript_html_with_keys
which can be used with keys to filter the output.
extern crate map_to_javascript_html;
use BTreeMap;
use MapToJavaScriptHTML;
let mut map = new;
map.insert;
map.insert;
map.insert;
let text = map.to_javascript_html_with_keys;
assert_eq!;
No Std
Disable the default features to compile this crate without std.
[]
= "*"
= false
Serde Support
To support the maps from the serde
framework, enable the serde
feature.
[]
= "*"
= ["serde"]
Crates.io
https://crates.io/crates/map-to-javascript-html
Documentation
https://docs.rs/map-to-javascript-html