2017-03-30 17:09:57 +00:00
|
|
|
# coding: utf-8
|
2016-12-29 16:03:03 +00:00
|
|
|
def parse_news file_name
|
|
|
|
news = []
|
|
|
|
current_line = []
|
|
|
|
version = 'HEAD'
|
|
|
|
date = 'unknown'
|
|
|
|
type = 'Other changes'
|
2017-03-30 17:09:57 +00:00
|
|
|
ignore = true
|
2016-12-29 16:03:03 +00:00
|
|
|
|
|
|
|
flush = lambda do
|
2018-01-01 00:35:12 +00:00
|
|
|
current_line = current_line.join("\n").gsub(%r{\A\n+|\n+\z}, '')
|
|
|
|
|
2016-12-29 16:03:03 +00:00
|
|
|
if !current_line.empty?
|
|
|
|
news << {
|
2018-01-01 00:35:12 +00:00
|
|
|
:content => current_line,
|
2016-12-29 16:03:03 +00:00
|
|
|
:version => version,
|
|
|
|
:date => date,
|
|
|
|
:type => type
|
|
|
|
}
|
|
|
|
end
|
2018-01-01 00:35:12 +00:00
|
|
|
|
|
|
|
current_line = []
|
2016-12-29 16:03:03 +00:00
|
|
|
end
|
|
|
|
|
2017-04-14 12:46:07 +00:00
|
|
|
IO.read(file_name).
|
|
|
|
gsub(%r{<!--.*?-->}, '').
|
|
|
|
split(%r{\n}).
|
|
|
|
each do |line|
|
2016-12-29 16:03:03 +00:00
|
|
|
|
|
|
|
flush.call if %r{^[#*]}.match(line)
|
|
|
|
|
|
|
|
# # Version 9.7.1 "Pandemonium" 2016-12-27
|
|
|
|
# # Version 0.6.4 2003-08-27
|
|
|
|
|
|
|
|
if match = %r{ ^\# \s+ Version \s+ (?<version> [0-9.-]+) (?: \s+ " (?<codename>.+) " )? \s+ (?<year>\d+)-(?<month>\d+)-(?<day>\d+) }x.match(line)
|
|
|
|
version = match[:version]
|
|
|
|
date = sprintf("%04d-%02d-%02d", match[:year].to_i, match[:month].to_i, match[:day].to_i)
|
|
|
|
type = 'Other changes'
|
2017-03-30 17:09:57 +00:00
|
|
|
ignore = false
|
|
|
|
|
|
|
|
elsif match = %r{ ^\# \s+ Version \s+ \? }x.match(line)
|
|
|
|
ignore = true
|
|
|
|
|
|
|
|
elsif ignore
|
|
|
|
next
|
2016-12-29 16:03:03 +00:00
|
|
|
|
|
|
|
elsif %r{ ^\#\# \s+ (.+) }x.match(line)
|
|
|
|
type = $1
|
|
|
|
|
|
|
|
else
|
2018-01-01 00:35:12 +00:00
|
|
|
flush.call if /^\*/.match(line)
|
|
|
|
current_line << line.gsub(%r{^\*\s*}, '').sub(%r{^\s\s}, '')
|
2016-12-29 16:03:03 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
flush.call
|
|
|
|
|
|
|
|
news.chunk { |e| e[:version] }
|
|
|
|
end
|