Class: Reap::Announcement
- Inherits:
-
Object
- Object
- Reap::Announcement
- Defined in:
- lib/reap/announcement.rb
Overview
Announcement
Announcment class is used to generate an announcement message. By default this is a Release Announcment.
Instance Attribute Summary collapse
-
#cutoff ⇒ Object
Returns the value of attribute cutoff.
-
#metadata ⇒ Object
Project metadata.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Announcement
constructor
A new instance of Announcement.
-
#message ⇒ Object
Make a release announcement.
- #to_s ⇒ Object
- #unfold_paragraphs(string) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Announcement
Returns a new instance of Announcement.
22 23 24 25 26 27 |
# File 'lib/reap/announcement.rb', line 22 def initialize(={}, &block) populate(, &block) @cutoff ||= 30 @template ||= "{ANNOUNCE}{,.txt}" end |
Instance Attribute Details
#cutoff ⇒ Object
Returns the value of attribute cutoff.
16 17 18 |
# File 'lib/reap/announcement.rb', line 16 def cutoff @cutoff end |
#metadata ⇒ Object
Project metadata
14 15 16 |
# File 'lib/reap/announcement.rb', line 14 def @metadata end |
#template ⇒ Object
Returns the value of attribute template.
18 19 20 |
# File 'lib/reap/announcement.rb', line 18 def template @template end |
Instance Method Details
#message ⇒ Object
Make a release announcement. Generates and can email a release announcements. These are nicely formated message and can email the message to the specified address(es).
The following settings apply:
template Announcement file/template.
cutoff Max number of lines of changelog to show.
A template file can be specified that uses “$setting” as substitutes for poject information.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/reap/announcement.rb', line 41 def template = Dir.glob(template(), File::FNM_CASEFOLD).first if template readme = File.read(template) readme = unfold_paragraphs(readme) else readme = '' #readme << "= #{metadata.title} v#{metadata.version}\n\n" readme << "#{.description}\n\n" readme << "#{.homepage}\n\n" readme << "Please see the NOTES file.\n\n" readme << "Please see the CHANGES file.\n" end # changelog file = Dir.glob('change{s,log}{,.txt}', File::FNM_CASEFOLD)[0] changelog = file ? File.read(file).strip : '' #changelog = unfold_paragraphs(changelog) changelog = changelog.split("\n")[0..cutoff].join("\n") unless changelog =~ /^=/ changelog = "\n== Changes\n\n" + changelog end # noteslog file = Dir.glob('note{s,log}{,.txt}', File::FNM_CASEFOLD)[0] notelog = file ? File.read(file).strip : '' notelog = unfold_paragraphs(notelog) unless notelog =~ /^=/ notelog = "\n== Release Notes\n\n" + notelog end # Strip tiny version zero. #if keys['version'] =~ /[.].*?[.]/ # keys['version'] = keys['version'].chomp('.0') #end # Make announcement message = readme.dup #message.gsub!('$readme$', readme || '') .sub!(/^\s*please\ see(\ the)?\ notes(.*?)$/i, "\n" + notelog) if notelog .sub!(/^\s*please\ see(\ the)?\ change(.*?)$/i, "\n" + changelog) if changelog template = .dup template.scan(/\$(\w+?)\$/m) do |key| #key = key.strip name = $1.strip #key[1..-1] if .respond_to?(name.downcase) value = .send(name.downcase) .gsub!("$#{name}$", value.to_s.strip) else puts "Warning: Unknown project metadata field -- #{name}." end end .gsub!(/(^|[ ])[$].*?(?=[ ]|$)/,'') # remove unused vars .gsub!(/\n\s*\n\s*\n/m,"\n\n") # remove any triple blank lines .rstrip! = "\n" + return end |
#to_s ⇒ Object
129 130 131 |
# File 'lib/reap/announcement.rb', line 129 def to_s end |
#unfold_paragraphs(string) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/reap/announcement.rb', line 109 def unfold_paragraphs(string) blank = false text = '' string.split(/\n/).each do |line| if /\S/ !~ line text << "\n\n" blank = true else if /^(\s+|[*])/ =~ line text << (line.rstrip + "\n") else text << (line.rstrip + " ") end blank = false end end return text end |