Map to JavaScript in HTML

Build Status

This is a library for serializing a (hash) map to JavaScript code in HTML, usually for dynamically generating strings on web pages.

Example

In your HTML or templates to generate HTML, such as Handlebars, for instance,

```html

```

Then, you can use this crate to insert your text into JavaScript code in HTML,

```rust extern crate maptojavascript_html;

use maptojavascripthtml::hashmaptojavascript_html; use std::collections::HashMap;

let mut map = HashMap::new();

map.insert("hello", "Hello world!"); map.insert("welcome", "Welcome to my website."); map.insert("other keys", "Hello world!");

let text = hashmaptojavascripthtml(&map, "_text", &["welcome", "hello"]).unwrap(); ```

If you want your text to be beautified, you can use hash_map_to_javascript_html_beautify function.

After Handlebars replaces {{{text}}} with your text, the HTML will be,

```html

```

The key and the value used in a map must implement the Display trait.

By the way, the text_to_javascript_html function can be useful when you just want to insert text as a JavaScript string into your HTML code.

Crates.io

https://crates.io/crates/map-to-javascript-html

Documentation

https://docs.rs/map-to-javascript-html

License

MIT