From fda5db94560bac53e41259bcb7f92b0bd1bbfbaf Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Fri, 13 Sep 2024 11:27:52 +0200 Subject: [PATCH] MT#61052 support rendering yaml some templates need to produce yaml output (ie. copy entire portions of config.yml), which supported with this change, ie. [% Utils.to_yaml(element_from_configyml) %] there is libtemplate-plugin-yaml-perl, which is avoided to not (re-) introduce deps other than YAML::XS. Change-Id: Iec7f9dd6d13270d9afa78fbe126f0e41d21b6ed7 --- lib/NGCP/Template/Plugin/Utils.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/NGCP/Template/Plugin/Utils.pm b/lib/NGCP/Template/Plugin/Utils.pm index 4c9cd232..21adc8b5 100644 --- a/lib/NGCP/Template/Plugin/Utils.pm +++ b/lib/NGCP/Template/Plugin/Utils.pm @@ -8,6 +8,7 @@ use parent qw(Template::Plugin); use MIME::Base64 (); use Data::Dumper (); use Config::General (); +use YAML::XS (); sub new { my ($class, $context, @params) = @_; @@ -37,6 +38,11 @@ sub to_config_general { return $conf->save_string($params[0]); } +sub to_yaml { + my ($self, @params) = @_; + return YAML::XS::Dump($params[0]); +} + sub get_ref { my ($self, @params) = @_; return ref $params[0]; @@ -94,6 +100,10 @@ Serializes the given input object to string (perl syntax). Serializes the given input object to string (Config::General syntax). +=item [% serialized = Utils.to_yaml(object) %] + +Serializes the given input object to string (YAML syntax). + =item [% Utils.get_ref(object) %] Get the variable type.