Issue #20516 has been reported by Henrik Lindberg.
----------------------------------------
Feature #20516: Add support for writing templates in the Puppet Language
https://projects.puppetlabs.com/issues/20516
* Author: Henrik Lindberg
* Status: Unreviewed
* Priority: Normal
* Assignee:
* Category:
* Target version:
* Affected Puppet version:
* Keywords: templates language EPP ARM
* Branch:
----------------------------------------
Writing templates in Ruby has two main problems caused by the fact that it
exposes users to the full fun-ride of evaluating ruby code inside the puppet
runtime:
* Many users do not know Ruby (and do not have a great desire to learn it)
and still need to be able to use templates
* Evaluating Ruby inside the puppet runtime comes with responsibilities that
are easy to forget and thus causing problems
An implementation of templates in the Puppet Language is proposed in ARM-3
Puppet Templates where this feature is described in more detail.
In short:
EPP supports the following tags:
* `<%= puppet expression %>` - This tag renders the value of the expression
it contains.
* `<% puppet expression(s) %>` - This tag will execute the expression(s) it
contains, but renders nothing.
* `<%# comment %>` - The tag and its content renders nothing.
* `<%%` or `%%>` - Renders a literal `<%` or `%>` respectively.
* `<%-` - Same as `<%` but suppresses any leading whitespace.
* `-%>` - Same as `%>` but suppresses any trailing whitespace on the same
line (including line break).
EPP supports parameters by placing an optional parameter list as the very first
element in the Epp. As an example,
`<%- ($x, $y, $z='unicorn') -%>` when placed first in the EPP text declares
that the parameters `x` and `y` must be
given as template arguments when calling `epptemplate` or `inline_epptemplate`,
and that `z` if not given as a template argument
defaults to `'unicorn'`. Template parameters are available as variables,
e.g.arguments `$x`, `$y` and `$z` in the example.
Arguments are passed to the template by calling one of the two epp template
functions with a Hash as the last argument, where parameters
are bound to values, e.g. `epptemplate('...', {'x'=>10, 'y'=>20})`. Excess
arguments may be given
(i.e. undeclared parameters). Template parameters shadow variables in outer
scopes. Template arguments may be
passed to any template; the template text does not have to have a declaration
of parameters.
Several strings may be given as arguments to `inline_epptemplate`, the result
is the concatenation of each produced result.
If template arguments are given, they are used for each given template string.
The full ARM text is found here
https://github.com/puppetlabs/armatures/blob/master/arm-3.puppet_templates/puppet_templates.md
In Summary: EPP templates behaves like erb templates, only that the logic is
written in Embedded Puppet instead of ruby, and that the expected (optional)
filenames
end with the extension `.epp` (and to support editors that require that the
file has an extension representing the type, the `.epp` can be placed next to
last e.g. `.epp.html`.
It is unfortunately not possible to repurpose the existing functions `template`
and `inline_template` (without breaking backwards compatibility) to support
both ERB and EPP templates (due to the function argument signatures) - hence
the introduction of the functions `epptemplate` and `inline_epptemplate`.
Currently, there is an experimental implementation based on --parser future,
and the ARM 3 needs to be updated. (More information to come).
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.