Skip to content
Snippets Groups Projects
Commit 1818bc00 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

ini_file: Sort [default] sections before others.

It is common (but not universal) for INI-style files to have a section
named [default], or [DEFAULT], which holds defaults for all other
sections.  For example, the 'configparser' Python module implements
that behavious.

While the [default] section typically doesn't *have* to be placed
before the sections it provides defaults for, it tends to make the
file easier to read if it *is* placed first in the file.

We thus here make sure to put all sections named "default" (case-
insensitive) first in the generated file.
parent 31d202e2
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,17 @@ ...@@ -3,7 +3,17 @@
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
# #
-%> -%>
<% @settings.sort().each do |section_name, section_vars| -%> <%
# Sort sections named "default" (case in-sensitive) before others
sorted_sections = @settings.keys().select { |k|
k.downcase() == 'default'
}.sort()
sorted_sections += @settings.keys().reject { |k|
sorted_sections.include?(k)
}.sort()
sorted_sections.each do |section_name|
section_vars = @settings[section_name]
-%>
[<%= section_name %>] [<%= section_name %>]
<% # Want to align = signs, but only for "short" names <% # Want to align = signs, but only for "short" names
max_align_pos = 24 max_align_pos = 24
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment