From a2953e126cc060a30111e0020827c36ba9c9b0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Peccatte?= Date: Mon, 1 Feb 2016 15:41:04 +0100 Subject: [PATCH] Fixes #7856: Use a mustache template from a string --- .../file_from_string_mustache.cf | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tree/30_generic_methods/file_from_string_mustache.cf diff --git a/tree/30_generic_methods/file_from_string_mustache.cf b/tree/30_generic_methods/file_from_string_mustache.cf new file mode 100644 index 000000000..ad4ace851 --- /dev/null +++ b/tree/30_generic_methods/file_from_string_mustache.cf @@ -0,0 +1,49 @@ +##################################################################################### +# Copyright 2016 Normation SAS +##################################################################################### +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +##################################################################################### + +# @name File from a mustache string +# @description This is a bundle to build a file from a mustache string +# @agent_version >=3.7 +# +# @parameter template String containing a template to be expanded +# @parameter destination Destination file +# +# @class_prefix file_from_string_mustache +# @class_parameter destination +# This bundle will define a class file_from_string_mustache_${destination}_{kept,repaired,not_ok,ok,reached} + +bundle agent file_from_string_mustache(template, destination) +{ + vars: + "old_class_prefix" string => canonify("file_from_string_mustache_${destination}"); + "promisers" slist => { @{this.callers_promisers}, cf_null }, policy => "ifdefined"; + "class_prefix" string => canonify(join("_", "promisers")); + "args" slist => { "${template}", "${destination}" }; + "content" string => string_mustache("${template}", datastate()); + + files: + "${destination}" + create => "true", + edit_line => insert_lines("${content}"), + edit_defaults => ncf_empty_select("true"), + classes => classes_generic_two("${old_class_prefix}", "${class_prefix}"); + + methods: + any:: + "report" usebundle => _log("Build file ${destination} from string template", "${old_class_prefix}", "${class_prefix}", @{args}); +}