Skip to content

Commit

Permalink
Merge pull request #340 from ncharles/ust_7856/use_a_mustache_templat…
Browse files Browse the repository at this point in the history
…e_from_a_string

Fixes #7856: Use a mustache template from a string
  • Loading branch information
jooooooon committed Apr 22, 2016
2 parents 40974d1 + a2953e1 commit d23f72d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions 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 <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @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});
}

0 comments on commit d23f72d

Please sign in to comment.