git.delta.rocks / jrsonnet / refs/commits / ddc0d176fb77

difftreelog

source

crates/jrsonnet-stdlib/src/manifest/mod.rs1.5 KiBsourcehistory
1mod toml;2mod yaml;34use jrsonnet_evaluator::{5	error::Result,6	function::builtin,7	manifest::{escape_string_json, JsonFormat},8	typed::Any,9	IStr, ObjValue, Val,10};11pub use toml::TomlFormat;12pub use yaml::YamlFormat;1314#[builtin]15pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {16	Ok(escape_string_json(&str_))17}1819#[builtin]20pub fn builtin_manifest_json_ex(21	value: Any,22	indent: IStr,23	newline: Option<IStr>,24	key_val_sep: Option<IStr>,25	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,26) -> Result<String> {27	let newline = newline.as_deref().unwrap_or("\n");28	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");29	value.0.manifest(JsonFormat::std_to_json(30		indent.to_string(),31		newline,32		key_val_sep,33		#[cfg(feature = "exp-preserve-order")]34		preserve_order.unwrap_or(false),35	))36}3738#[builtin]39pub fn builtin_manifest_yaml_doc(40	value: Any,41	indent_array_in_object: Option<bool>,42	quote_keys: Option<bool>,43	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,44) -> Result<String> {45	value.0.manifest(YamlFormat::std_to_yaml(46		indent_array_in_object.unwrap_or(false),47		quote_keys.unwrap_or(true),48		#[cfg(feature = "exp-preserve-order")]49		preserve_order.unwrap_or(false),50	))51}5253#[builtin]54pub fn builtin_manifest_toml_ex(55	value: ObjValue,56	indent: IStr,57	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,58) -> Result<String> {59	Val::Obj(value).manifest(TomlFormat::std_to_toml(60		indent.to_string(),61		#[cfg(feature = "exp-preserve-order")]62		preserve_order.unwrap_or(false),63	))64}