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 253f382
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 != '' %><% ($comment_length...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<%= $begin_line %><% if $end_line != '' %><% ($comment_length...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<%= $begin_line %> <% $message %><% if $end_line != '' %><% $tmp = $comment_length + $message.length() + 1%><% ($tmp...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<% if $metadata -%>
<%= $begin_line %><% if $end_line != '' %><% ($comment_length...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<%= $begin_line %> <%= $metadata_title %><% if $end_line != '' %><% $tmp = $comment_length + $message.length() + 1 %><% ($tmp...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<% $metadata.each | $key | -%>
<%= $begin_line %> <% $key %>=<%= $metadata[$key] %><% if $end_line != '' %><% $tmp = $comment_length + $key.length() $metadata[$key].length() + 3 %><% ($tmp...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<% end -%>
<% end -%>
<%= $begin_line %><% if $end_line != '' %><% ($comment_length...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>
<%= $begin_line %><% if $end_line != '' %><% ($comment_length...$line_length).step(1).each |a|%> <% end %><% $end_line %><% end %>

0 comments on commit 253f382

Please sign in to comment.