From 918a61591e036e13f1e9c43afbee4a76f09ede93 Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@nsc.liu.se>
Date: Mon, 6 May 2024 08:47:22 +0200
Subject: [PATCH] Handle tabs when indenting <VirtualHost> content.

Expand tabs before indenting the lines provided as the configuration
for a named virtual host (apache::named_vhost).  This will give users
the expected indentation in the generated vhost-NAME.conf file even
if they use TAB characters in their config lines.

This is only for aesthetics; the semantics of the configuration should
not be affected.
---
 templates/named_vhost.conf.erb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/templates/named_vhost.conf.erb b/templates/named_vhost.conf.erb
index 66aa99e..9fba854 100644
--- a/templates/named_vhost.conf.erb
+++ b/templates/named_vhost.conf.erb
@@ -92,6 +92,11 @@ NameVirtualHost <%= addr %>
 <% end -%>
 <VirtualHost <%= server_addrs.join(' ') %>>
 
-<%= vhostcfg.join("\n").gsub(/^./, '    \&') %>
+<% vhostcfg.each do |chunk|
+      # Expand tabs and indent four spaces
+      chunk = chunk.gsub(/([^\t\n]*)\t/) { $1 + " " * (8 - ($1.size % 8)) }
+-%>
+<%=   chunk.rstrip.gsub(/^./, '    \&') %>
+<% end -%>
 
 </VirtualHost>
-- 
GitLab