Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JSON/YAML/JavaScript Escaping (#82)
- Loading branch information
Showing
11 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "generate-yaml" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
minijinja = { path = "../../minijinja", features = ["json"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# generate-yaml | ||
|
||
This demonstrates how MiniJinja can be used to generate YAML files with automatic escaping. | ||
It renders a YAML template and fills in some values which are automatically formatted to | ||
be valid JSON and YAML syntax. | ||
|
||
```console | ||
$ cargo run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! This example dumps out YAML by using auto escaping. | ||
use std::collections::BTreeMap; | ||
use std::env; | ||
|
||
use minijinja::{context, Environment}; | ||
|
||
fn main() { | ||
let mut env = Environment::new(); | ||
env.add_template("template.yml", include_str!("template.yaml")) | ||
.unwrap(); | ||
let tmpl = env.get_template("template.yml").unwrap(); | ||
println!( | ||
"{}", | ||
tmpl.render(context! { | ||
env => env::vars().collect::<BTreeMap<_, _>>(), | ||
title => "Hello World!", | ||
yaml => "[1, 2, 3]", | ||
}) | ||
.unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
env: {{ env }} | ||
title: {{ title }} | ||
skip: {{ true }} | ||
run: {{ ["bash", "./script.sh"] }} | ||
yaml_value: {{ yaml|safe }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters