Skip to content

Commit

Permalink
(FEAT) Add simple standardized header template
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk committed Nov 23, 2020
1 parent 79cf864 commit df7ab8d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ The following sections/settings are included.
}
```

### EPP Templates

You can include a standardized comment header in your `.epp` or `.erb` templates with the following:
```puppet
<%= scope.call_function('epp', ["extlib/puppet_managed.epp"]) %>
```
The EPP template takes the following optional parameters:
- String $message = 'WARNING This file is managed by puppet. Do not edit!',
- String $begin_line = '#',
- String $end_line = '',
- Int $line_length = 70,
- String $metadata_title = 'Metadata:',
- Hash $metadata = {}
Example:
```puppet
<%= scope.call_function('epp', ["extlib/puppet_managed.epp"], {'metadata' => {'fqdn' => $::fqdn}}) %>
```
Should produce
```shell
#
#
# WARNING This file is managed by puppet. Do not edit!
#
# Metadata:
# fqdn=hostname.example.com
#
#
```

## Limitations

Some functions require puppetlabs-stdlib (>= 4.6.0) and all functions are only
Expand Down
20 changes: 20 additions & 0 deletions templates/puppet_managed.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%- | String $message = 'WARNING This file is managed by puppet. Do not edit!',
String $begin_line = '#',
String $end_line = '',
Int $line_length = 70,
String $metadata_title = 'Metadata:',
Hash $metadata = {}
| -%>
<%- $comment_length = $begin_line.length() + $end_line.length() -%>
<%= $begin_line %><% if $end_line != '' { %><% $tmp = $comment_length %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<%= $begin_line %><% if $end_line != '' { %><% $tmp = $comment_length %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<%= $begin_line %> <% $message %><% if $end_line != '' { %><% $tmp = $comment_length + message.length() + 1%><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<% if $metadata { -%>
<%= $begin_line %><% if $end_line != '' { %><% $tmp = $comment_length %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<%= $begin_line %> <%= $metadata_title %><% if $end_line != '' { %><% $tmp = $comment_length + $metadata_title.length() + 1 %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<% $metadata.keys.each |$key| { -%>
<%= $begin_line %> <% $key %>=<%= $metadata[$key] %><% if $end_line != '' { %><% $tmp = $comment_length + $key.length() $metadata[$key].length() + 3 %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<% } -%>
<% } -%>
<%= $begin_line %><% if $end_line != '' { %><% $tmp = $comment_length %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>
<%= $begin_line %><% if $end_line != '' { %><% $tmp = $comment_length %><% loop do %><% if $tmp >= $line_length { break } %> <% $tmp = $tmp + 1 %><% end %><%= $end_line %><% } %>

0 comments on commit df7ab8d

Please sign in to comment.