mirror of
https://github.com/chocolate-doom/tools.git
synced 2024-11-24 05:11:03 +00:00
Modify changelog generator script: combine adjacent lines of text into
the same line and then break long lines of text into multiple lines. Subversion-branch: /tools Subversion-revision: 723
This commit is contained in:
parent
07f3876061
commit
faa44988e1
1 changed files with 116 additions and 1 deletions
117
svnhistory
117
svnhistory
|
@ -7,11 +7,126 @@ class Change
|
|||
@description = ""
|
||||
end
|
||||
|
||||
# Combine multiple lines of text into long run-on lines. Empty
|
||||
# lines of text denote paragraphs. Lines beginning with '*'
|
||||
# are also recognised as bullet point lists.
|
||||
|
||||
def combine_lines(input)
|
||||
result = ""
|
||||
|
||||
input.each_line do |s|
|
||||
s = s.chomp
|
||||
|
||||
if result.length > 0 && result[-1, 1] != "\n"
|
||||
|
||||
# Don't do any of this if we just started a new line
|
||||
|
||||
if s =~ /^\s*$/
|
||||
# empty line; make this break a paragraph.
|
||||
result += "\n\n"
|
||||
elsif s =~ /^\s*\*/
|
||||
# bullet point
|
||||
result += "\n"
|
||||
else
|
||||
result += " "
|
||||
end
|
||||
end
|
||||
|
||||
result += s
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
# Reformat the description and break into lines
|
||||
|
||||
def break_lines(input)
|
||||
result = ""
|
||||
|
||||
input.each_line do |s|
|
||||
|
||||
if s =~ /^\s*$/
|
||||
# empty line
|
||||
result += "\n"
|
||||
else
|
||||
|
||||
# Amount to indent each line by so that they align
|
||||
# with the initial bullet point (if this line is a
|
||||
# bullet point)
|
||||
|
||||
indent_length = if s =~ /^(\s*\*\s*)/
|
||||
$1.length
|
||||
else
|
||||
0
|
||||
end
|
||||
|
||||
# Split this line into words, then add them to nextline
|
||||
# one at a time until it reaches a 70 character limit.
|
||||
|
||||
nextline = s[0, indent_length]
|
||||
s = s[indent_length, s.length]
|
||||
|
||||
words = s.split(/\s+/)
|
||||
|
||||
words.each do |word|
|
||||
|
||||
# If the next word will run over the limit, break
|
||||
# onto a new line.
|
||||
|
||||
if nextline.length > indent_length \
|
||||
&& nextline.length + word.length + 1 > 70
|
||||
|
||||
result += nextline + "\n"
|
||||
nextline = " " * indent_length
|
||||
end
|
||||
|
||||
# Space to separate from the previous word, but only
|
||||
# if this is not the start of a line
|
||||
|
||||
if nextline.length > indent_length
|
||||
if nextline[-1, 1] == "."
|
||||
|
||||
# Two spaces after a period
|
||||
|
||||
nextline += " "
|
||||
end
|
||||
nextline += " "
|
||||
end
|
||||
|
||||
nextline += word
|
||||
end
|
||||
|
||||
# Print the last "unfinished" line
|
||||
|
||||
if nextline.length > indent_length
|
||||
result += nextline + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def remove_trailing_newlines(s)
|
||||
while s[-2, 2] == "\n\n"
|
||||
s = s.chop
|
||||
end
|
||||
|
||||
s
|
||||
end
|
||||
|
||||
def print_change
|
||||
puts "#{@time} #{@author}"
|
||||
@description.each_line do |s|
|
||||
puts "\t"
|
||||
|
||||
munged = combine_lines(@description)
|
||||
munged = break_lines(munged)
|
||||
munged = remove_trailing_newlines(munged)
|
||||
munged.each_line do |s|
|
||||
puts "\t" + s
|
||||
end
|
||||
|
||||
puts
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue