lib/chef_attrdoc.rb in chef_attrdoc-1.0.1 vs lib/chef_attrdoc.rb in chef_attrdoc-1.0.2

- old
+ new

@@ -137,24 +137,19 @@ def self.write_readme(readme, parsed) File.open(readme, File::RDWR) do |f| # TODO find a cleaner way and do this in one step content = f.read if content =~ /\nAttributes\s*=+\s*\n/ - updated = content.gsub(/(?<before>.*\nAttributes\s*=+\s*\n)(?m:.+?)(?<after>\n.+\s*\n=+.*)/, + updated = content.gsub(/(?<before>.*\nAttributes\s*=+\s*?\n)\n*(?m:.+?)(?<after>\n.+\s*\n=+.*)/, '\k<before>CHEF_ATTRDOC_UPDATING_TEMPLATE\k<after>') - - # XXX hack because I couldn't figure out how to get another - # newline in between the <before> and the content - updated.sub!('CHEF_ATTRDOC_UPDATING_TEMPLATE', - "\nCHEF_ATTRDOC_UPDATING_TEMPLATE") elsif content =~ /\n\#+\s*Attributes\s*\n/ - updated = content.gsub(/(?<before>.*\n\#+\s*Attributes\s*\n)(.+?)(?<after>\n\#+.*)/m, + updated = content.gsub(/(?<before>.*\n\#+\s*Attributes\s*?\n)\n*(.+?)(?<after>\n\#+.*)/m, '\k<before>CHEF_ATTRDOC_UPDATING_TEMPLATE\k<after>') else raise StandardError, "Could not find Attributes heading in #{readme}. Please make sure your README file has proper markdown formatting and includes an Attributes heading." end - updated.sub! 'CHEF_ATTRDOC_UPDATING_TEMPLATE', parsed + updated.sub! 'CHEF_ATTRDOC_UPDATING_TEMPLATE', "\n" + parsed f.rewind f.write(updated) f.flush f.truncate(f.pos) end