Class: Reap::Announcement

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options={}, &block)
  populate(options, &block)

  @cutoff   ||= 30
  @template ||= "{ANNOUNCE}{,.txt}"
end

Instance Attribute Details

#cutoffObject

Returns the value of attribute cutoff.



16
17
18
# File 'lib/reap/announcement.rb', line 16

def cutoff
  @cutoff
end

#metadataObject

Project metadata



14
15
16
# File 'lib/reap/announcement.rb', line 14

def 
  @metadata
end

#templateObject

Returns the value of attribute template.



18
19
20
# File 'lib/reap/announcement.rb', line 18

def template
  @template
end

Instance Method Details

#messageObject

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 message
  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
  message = readme.dup

  #message.gsub!('$readme$', readme || '')
  message.sub!(/^\s*please\ see(\ the)?\ notes(.*?)$/i, "\n" + notelog) if notelog
  message.sub!(/^\s*please\ see(\ the)?\ change(.*?)$/i, "\n" + changelog) if changelog

  template = message.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)
      message.gsub!("$#{name}$", value.to_s.strip)
    else
      puts "Warning: Unknown project metadata field -- #{name}."
    end
  end

  message.gsub!(/(^|[ ])[$].*?(?=[ ]|$)/,'') # remove unused vars
  message.gsub!(/\n\s*\n\s*\n/m,"\n\n")      # remove any triple blank lines
  message.rstrip!
 
  message = "\n" + message

  return message
end

#to_sObject



129
130
131
# File 'lib/reap/announcement.rb', line 129

def to_s
  message
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