diff --git a/software/helloworld/instance.cfg.in b/software/helloworld/instance.cfg.in index aa80bd4ecccbe9893a1a4ec8ff96984d9edfbee1..2dffc75190150b0173b746fe8b88b37172644923 100644 --- a/software/helloworld/instance.cfg.in +++ b/software/helloworld/instance.cfg.in @@ -4,7 +4,7 @@ # ############################# # -# In this file is explained how to add a new value that the software will handle +# Now we are going how to add new parts, using new recipes # ############################# [buildout] @@ -12,6 +12,8 @@ parts = directory hello-world publish-connection-parameter +# Don't forget to include the new part ! It will also call [template-get] in software.cfg + template-creation # Define egg directories to be the one from Software Release # (/opt/slapgrid/...) @@ -55,6 +57,8 @@ recipe = slapos.cookbook:mkdirectory home = $${buildout:directory} etc = $${:home}/etc var = $${:home}/var +# Creation of the folder wich will contain the jinja template +data-fold = $${:home}/srv/data # Executables put here will be started but not monitored (for startup scripts) script = $${:etc}/run/ # Executables put here will be started and monitored (for daemons) @@ -65,6 +69,28 @@ promise = $${:etc}/promise/ # Path of the log directory used by our service (see [hello-world]) log = $${:var}/log + +# It is now time for Jinja ! +[template-creation] +recipe = slapos.recipe.template:jinja2 +# We could also define the template inline. +#template = inline: +# ---------------------------------- +# Title : {{title}} +# ---------------------------------- +# Hello {{name}} +# the value of template will be replaced thanks to the information given in software.cfg, during its own buildout +template = ${template-get:location}/${template-get:filename} +# Here we can declare where we want to get the new file rendered by Jinja +rendered = $${directory:data-fold}/data1.txt +mode = 700 +# In the context we can define the specific values wich will be substituted in the template +# key mean that the value is to get in another section of this buildout config file. Go to http://git.erp5.org/gitweb/slapos.recipe.template.git/blob/HEAD:/slapos/recipe/template/README.jinja2.txt?js=1 for more information +context = + key name instance-parameter:configuration.name + key title instance-parameter:configuration.title + + # Create a simple shell script that will only output your name if you # specified it as instance parameter. # Usually, of course, we use more useful commands, like web servers. @@ -87,4 +113,5 @@ wrapper-path = $${directory:service}/hello-world recipe = slapos.cookbook:publish name = Hello $${instance-parameter:configuration.name}! # Adds the published parameter "title". By default, its value is "Title : " + the value declared in the section [instance-parameter] above. -title = Title : $${instance-parameter:configuration.title} +title = $${instance-parameter:configuration.title} +path = $${template-creation:rendered} diff --git a/software/helloworld/software.cfg b/software/helloworld/software.cfg index 3233dcd224fe2189fed4e48a440656be293ff84a..631c5f8d837bb97c789cd6803d1b52a23810bdf0 100644 --- a/software/helloworld/software.cfg +++ b/software/helloworld/software.cfg @@ -30,3 +30,13 @@ output = ${buildout:directory}/instance.cfg # For production, you must give the md5 hash of instance.cfg.in #md5sum = ab51bfb473e030514997c7691951601f mode = 0644 + +# To make a render thanks to Jinja2, first we need to get the template +# The url is where to find it. Location is just there to share information through buildout, and corresponds to a default location +[template-get] +recipe = hexagonit.recipe.download +url = ${:_profile_base_location_}/template/${:filename} +location = ${buildout:parts-directory}/${:_buildout_section_name_} +filename = rendered.in +download-only = true +mode = 0644 diff --git a/software/helloworld/template/rendered.in b/software/helloworld/template/rendered.in new file mode 100644 index 0000000000000000000000000000000000000000..003d3d4c908b8ffd7c27d3e649e622e2e8f9cfd9 --- /dev/null +++ b/software/helloworld/template/rendered.in @@ -0,0 +1,6 @@ +{%if title %} +--------------------------------------- +{{title}} +--------------------------------------- +{% endif %} +Hello {{name}} \ No newline at end of file