File indexing completed on 2024-04-14 04:40:46

0001 #!/usr/bin/env ruby
0002 #
0003 # Script for generating a HTML page from Amarok's text ChangeLog
0004 #
0005 # (c) 2005-2006,2009
0006 #    Mark Kretschmann <kretschmann@kde.org>,
0007 #    Ian Monroe <ian@monroe.nu>,
0008 #    Magnus Bergmark <magnus.bergmark@gmail.com>
0009 # License: GPL V2
0010 
0011 require 'cgi'
0012 
0013 $input  = File.new( "ChangeLog",  File::RDONLY )
0014 $output = File.new( "ChangeLog.html", File::CREAT | File::RDWR | File::TRUNC )
0015 
0016 $changelog = CGI::escapeHTML($input.read)
0017 
0018 # Remove the vim stuff
0019 $changelog.gsub!(/# vim:.*$/, '')
0020 
0021 # Remove whitespace from lines with only whitespace
0022 $changelog.gsub!(/^\s+$/, '')
0023 
0024 # Collapse multiple empty lines
0025 $changelog.gsub!(/\n{2,}/, "\n")
0026 
0027 # Replace bug number with direct link to bugs.kde.org
0028 $changelog.gsub!(/BR (\d+)/, '<a href="https://bugs.kde.org/show_bug.cgi?id=\\1">\\0</a>')
0029 
0030 # Make bullets
0031 bullet_item_regexp =
0032   /
0033     ^\s{3,4}           # Start of line and three to four whitespace
0034     \*\s               # The actual bullet
0035     (
0036       [^\n]*           # Match everything up to the first newline
0037       (\s{6}[^\n]+)*   # Match every following line if its indented
0038     )
0039   /xm;
0040 
0041 $changelog.gsub!(bullet_item_regexp) do |match|
0042   # Remove all the indentation spaces, too
0043   "\t<li>#{$1.gsub(/\s{2,}/, ' ')}</li>"
0044 end
0045 
0046 # Beautify heading
0047 $changelog.gsub!(/Amarok ChangeLog\n\=*\n/, "<h1>Amarok ChangeLog</h1>\n")
0048 
0049 # Create headers
0050 %w{FEATURES CHANGES BUGFIXES}.each do |header|
0051   $changelog.gsub!("#{header}:\n", "<h3>#{header.capitalize}</h3>")
0052 end
0053 
0054 # Format version headers
0055 $changelog.gsub!(/VERSION(.*$)/, '<h2>Version\\1</h2>');
0056 
0057 # Create <ul> and </ul> pairs around the headers
0058 # Lists start after a <h3></h3> and ends with the first other headline
0059 $changelog.gsub!(%r{(</h3>)(.*?)(<h\d>)}m, "\\1\n<ul>\n\\2\n</ul>\n\n\\3")
0060 
0061 # Now, we must parse the old syntax. It'll begin with version 1.2.1
0062 old_syntax_marker = "<h2>Version 1.2.1:</h2>"
0063 $changelog.sub!(/(#{old_syntax_marker})(.*)/m) do |old_contents|
0064   # The syntax here is pretty similar to the old lists, but we don't have any nice
0065   # bullet points in the file already. We will instead look at indentation
0066   bullet_item_regexp =
0067     /
0068       ^\s{2}             # Start of line and two whitespace
0069       (
0070         [^\n]*           # Match everything up to the first newline
0071         (\s{4}[^\n]+)*   # Match every following line if its indented
0072       )
0073     /xm;
0074 
0075   old_contents.gsub!(bullet_item_regexp) do |match|
0076     # Remove all the indentation spaces, too
0077     "\t<li>#{$1.gsub(/\s{2,}/, ' ')}</li>"
0078   end
0079 
0080   # We also need to place <ul> and </ul> pairs everywhere
0081   # Lists start after a <h3></h3> and ends with the first other headline or EOF
0082   old_contents.gsub!(%r{(</h2>)(.*?)(<h\d>|\Z)}m, "\\1\n<ul>\n\\2\n</ul>\n\n\\3")
0083 
0084   old_contents
0085 end
0086 
0087 # Write destination file
0088 $output.write( $changelog )
0089