Skip to content

Commit

Permalink
Fix rendering of nested hash inside array
Browse files Browse the repository at this point in the history
This is needed to support external_services options like
https://prosody.im/doc/modules/mod_external_services

Signed-off-by: Florian Pritz <[email protected]>
  • Loading branch information
Bluewind committed Apr 17, 2024
1 parent e3ea6fb commit 831f504
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions spec/defines/virtualhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@
}
end

context 'with nested array and hash custom options' do
let(:params) { { custom_options: { external_services: [{ 'type' => 'turns', 'algorithm' => 'turn' }] } } }

it {
is_expected.to contain_file(path_avail). \
with_content(%r#^external_services = {\n {\n type = "turns";\n algorithm = "turn";\n }\n}#)
}
end

context 'with disco items' do
let(:params) { { disco_items: %w[foo bar] } }

Expand Down
2 changes: 1 addition & 1 deletion templates/prosody.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ s2s_secure_domains = {
def print_recursive(object, indentation = 0)
case object
when Array
'{ "' + object.join('"; "') + '" }'
"{\n" + ' ' * (indentation + 2) + object.map {|v| print_recursive(v, indentation + 2)}.join('; ') + "\n" + (' ' * indentation) + '}'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
Expand Down
2 changes: 1 addition & 1 deletion templates/virtualhost.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VirtualHost "<%= @name %>"
def print_recursive(object, indentation = 0)
case object
when Array
'{ "' + object.join('"; "') + '" }'
"{\n" + ' ' * (indentation + 2) + object.map {|v| print_recursive(v, indentation + 2)}.join('; ') + "\n" + (' ' * indentation) + '}'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
Expand Down

0 comments on commit 831f504

Please sign in to comment.