Skip to content

Commit

Permalink
MT#61052 support rendering yaml
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Rene Krenn committed Sep 13, 2024
1 parent eb1cd98 commit fda5db9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/NGCP/Template/Plugin/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) = @_;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fda5db9

Please sign in to comment.