rmsgen 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,8 @@ Feature: Inquiring about multiple urls
3
3
  As a helper
4
4
  I want to be be able to input information on multiple urls
5
5
 
6
- @setup_polnote_directory
7
- Scenario: Two urls
8
- Given a file named "polnote" with:
6
+ Scenario: It asks for a title and link text
7
+ Given a polnote:
9
8
  """
10
9
  A story about something.
11
10
 
@@ -15,17 +14,12 @@ Feature: Inquiring about multiple urls
15
14
 
16
15
  http://test.com
17
16
  """
18
- And I cd to ".."
19
- Given a file named "config.yml" with:
20
- """
21
- email_dir: polnotes
22
- """
23
- Given I run `rmsgen -c config.yml` interactively
24
- And I type "The Title"
25
- And I type "something"
26
- And I type "something"
17
+ Given I run rmsgen
18
+ And I type "The Title" for the title
19
+ And I type "something" for the link text
20
+ And I type "something else" for the link text
27
21
  Then the output should contain:
28
22
  """
29
23
  <p>A story about <a href='http://test.com'>something</a>.</p>
30
- <p>And <a href='http://test.com'>something</a> else</p>
24
+ <p>And <a href='http://test.com'>something else</a></p>
31
25
  """
@@ -3,9 +3,8 @@ Feature: Generate polnote from full email
3
3
  As a helper
4
4
  I want a pol note from a full raw email
5
5
 
6
- @setup_polnote_directory
7
6
  Scenario: Raw email is stripped to just the body
8
- Given a file named "polnote" with:
7
+ Given a polnote:
9
8
  """
10
9
  Return-Path: <rms@gnu.org>
11
10
  X-Original-To: stallman-helpers@netpurgatory.com
@@ -43,12 +42,7 @@ Feature: Generate polnote from full email
43
42
  Skype: No way! That's nonfree (freedom-denying) software.
44
43
  Use free telephony http://directory.fsf.org/category/tel/
45
44
  """
46
- And I cd to ".."
47
- Given a file named "config.yml" with:
48
- """
49
- email_dir: polnotes
50
- """
51
- Given I run `rmsgen -c config.yml` interactively
45
+ Given I run rmsgen
52
46
  And I type "A title"
53
47
  And I type "Text"
54
48
  Then the output should contain:
@@ -4,19 +4,18 @@ Feature: Helper sets title
4
4
  I want to be asked for title text
5
5
  and shown the proper html output
6
6
 
7
- @setup_polnote_directory
8
- Scenario: Helper sets title
9
- Given a file named "polnote" with:
7
+ Background:
8
+ Given a polnote:
10
9
  """
11
10
  A story about something.
12
11
  """
12
+ And I run rmsgen
13
13
 
14
- And I cd to ".."
15
- And a file named "config.yml" with:
16
- """
17
- email_dir: polnotes
18
- """
14
+ Scenario: Helper sets title
15
+ When I type "I Like Turtles"
16
+ Then I should see a title for "I Like Turtles"
19
17
 
20
- When I run `rmsgen -c config.yml` interactively
21
- And I type "I Like Turtles"
18
+ Scenario: Helper capitalizes each word in the title
19
+ When I type "i like turtles"
22
20
  Then I should see a title for "I Like Turtles"
21
+
@@ -5,20 +5,15 @@ Feature: Managing a standard polnote
5
5
 
6
6
  @setup_polnote_directory
7
7
  Scenario: A standard polnote
8
- Given a file named "polnote" with:
8
+ Given a polnote:
9
9
  """
10
10
  A story about something.
11
11
 
12
12
  http://test.com
13
13
  """
14
- And I cd to ".."
15
- Given a file named "config.yml" with:
16
- """
17
- email_dir: polnotes
18
- """
19
- Given I run `rmsgen -c config.yml` interactively
20
- And I type "The Title"
21
- And I type "something"
14
+ Given I run rmsgen
15
+ And I type "The Title" for the title
16
+ And I type "something" for the link text
22
17
 
23
18
  Then the output should contain:
24
19
  """
@@ -7,6 +7,7 @@ Given /^I am ready to do polnotes/ do
7
7
  end
8
8
 
9
9
  Given /^an urgent polnote exists$/ do
10
+ cd 'polnotes'
10
11
  polnote = fixture("urgent_note")
11
12
  write_file("urgent", polnote)
12
13
  cd '..'
@@ -1,8 +0,0 @@
1
- Before('@setup_polnote_directory') do
2
- Given %{a directory named "polnotes"}
3
- Given %{I cd to "polnotes"}
4
- end
5
-
6
- Before('@urgent_note') do
7
- Given %{an urgent polnote exists}
8
- end
@@ -4,29 +4,24 @@ Feature: Urgent Polnotes
4
4
  I want to see the html output for the polnote section
5
5
  and for the urgent section
6
6
 
7
- @setup_polnote_directory @urgent_note
8
7
  Scenario: I see the html for the polnote section
8
+ Given I am ready to do polnotes
9
+ Given an urgent polnote exists
9
10
  Given a file named "config.yml" with:
10
11
  """
11
12
  email_dir: polnotes
12
13
  """
13
- Given I run `rmsgen -c config.yml` interactively
14
+ Given I run rmsgen
14
15
 
15
- When I type "Urgent Note"
16
- And I type "01 July 2011"
17
- And I type "tell"
16
+ When I type "Urgent Note" for the title
17
+ And I type "01 July 2011"
18
+ And I type "tell" for the link text
18
19
 
19
20
  Then I should see a title for "Urgent Note"
20
21
  And the output should contain:
21
22
  """
22
23
  What day does it expire?
23
24
  """
24
-
25
- And the output should contain:
26
- """
27
- <!-- Expires 01 July 2011 -->
28
- """
29
-
30
25
  Then the output should not contain:
31
26
  """
32
27
  <p>For one week:</p>
@@ -3,7 +3,7 @@ module Rmsgen
3
3
  def initialize(dir=nil)
4
4
  splat_dir = "#{dir}/*"
5
5
  @raw_notes = Dir[splat_dir].map { |f| File.read(f) }
6
- @notes = @raw_notes.map { |note| Rmsgen::Polnote.new(note) }
6
+ @notes = @raw_notes.map { |note| Rmsgen::Polnote.new(:body => note) }
7
7
  end
8
8
  def all
9
9
  @notes
@@ -2,10 +2,13 @@ module Rmsgen
2
2
  class IMAPPolnoteGroup
3
3
  require 'net/imap'
4
4
 
5
- def initialize(imap, options={})
6
- @imap = imap
5
+ attr_reader :note_ids
6
+
7
+ def initialize(options={})
8
+ @imap_options = options
7
9
  @login = options['imap_login']
8
10
  @password = options['imap_password']
11
+ @note_ids = init_note_ids || []
9
12
  end
10
13
 
11
14
  def fetch_notes
@@ -14,10 +17,10 @@ module Rmsgen
14
17
  find_all_from_rms
15
18
  end
16
19
 
17
- def note_ids
20
+ def init_note_ids
18
21
  authenticate
19
22
  follow_inbox
20
- @imap.search(["FROM", 'rms@gnu.org'])
23
+ imap.search(["FROM", 'rms@gnu.org'])
21
24
  end
22
25
 
23
26
  def find(id)
@@ -26,14 +29,13 @@ module Rmsgen
26
29
  end
27
30
 
28
31
  def archive_polnote(id)
29
- authenticate
30
32
  follow_inbox
31
33
  archived = false
32
- @imap.search(["FROM", 'rms@gnu.org']).each do |note_id|
34
+ imap.search(["FROM", 'rms@gnu.org']).each do |note_id|
33
35
  if note_id.to_i == id.to_i
34
- @imap.copy id.to_i, 'INBOX.old-messages'
35
- @imap.store(id.to_i, "+FLAGS", [:Deleted])
36
- @imap.expunge
36
+ imap.copy id.to_i, 'INBOX.old-messages'
37
+ imap.store(id.to_i, "+FLAGS", [:Deleted])
38
+ imap.expunge
37
39
  archived = true
38
40
  end
39
41
  end
@@ -42,24 +44,26 @@ module Rmsgen
42
44
 
43
45
  private
44
46
 
47
+ def imap
48
+ @imap ||= Net::IMAP.new(@imap_options['imap_server'])
49
+ end
50
+
45
51
  def authenticate
46
- @imap.authenticate 'LOGIN', @login, @password
52
+ imap.authenticate 'LOGIN', @login, @password
47
53
  end
48
54
 
49
55
  def follow_inbox
50
- @imap.select 'INBOX'
56
+ imap.select 'INBOX'
51
57
  end
52
58
 
53
59
  def find_all_from_rms
54
- if note_ids && note_ids.any?
55
- note_ids.map { |id| fetch_message_body(id) }
56
- end
60
+ @note_ids.map { |id| fetch_message_body(id) }
57
61
  end
58
62
 
59
63
  def fetch_message_body(id)
60
- fetch_result = @imap.fetch id, 'BODY[TEXT]'
64
+ fetch_result = imap.fetch id, 'RFC822'
61
65
  if fetch_result && fetch_result.any?
62
- fetch_result[0].attr['BODY[TEXT]']
66
+ fetch_result[0].attr['RFC822']
63
67
  end
64
68
  end
65
69
  end
@@ -63,7 +63,12 @@ module Rmsgen
63
63
  end
64
64
 
65
65
  def inquire_about_expiration
66
- @polnote.expires_on = @script.prompt_for_expiry_date
66
+ if @answers.empty?
67
+ answer = @script.prompt_for_expiry_date
68
+ else
69
+ answer = @answers.shift
70
+ end
71
+ @polnote.expires_on = answer
67
72
  end
68
73
 
69
74
  def append_to_previous_paragraph part
@@ -3,12 +3,14 @@ module Rmsgen
3
3
  attr_accessor :id, :title, :body, :expires_on
4
4
 
5
5
  URGENT_SUBJECT = 'Subject: Urgent note'
6
- TEMPLATE = File.join(File.dirname(__FILE__), '..', 'templates', 'polnote.erb')
7
6
 
8
- def initialize(source, options={})
9
- @body = source.dup
10
- @urgent = source.include? URGENT_SUBJECT
11
- @id = options[:id]
7
+ POLNOTE_TEMPLATE = File.join(File.dirname(__FILE__), '..', 'templates', 'polnote.erb')
8
+ URGENT_TEMPLATE = File.join(File.dirname(__FILE__), '..', 'templates', 'urgent.erb')
9
+
10
+ def initialize(attributes={})
11
+ @body = attributes[:body]
12
+ @urgent = sanitize_urgent_attribute(attributes[:urgent]) || (@body && @body.include?(URGENT_SUBJECT))
13
+ @id = attributes[:id]
12
14
  compress!
13
15
  end
14
16
 
@@ -29,7 +31,11 @@ module Rmsgen
29
31
  end
30
32
 
31
33
  def to_html
32
- ERB.new(File.read(TEMPLATE)).result(binding)
34
+ ERB.new(File.read(POLNOTE_TEMPLATE)).result(binding)
35
+ end
36
+
37
+ def to_urgent_html
38
+ ERB.new(File.read(URGENT_TEMPLATE)).result(binding)
33
39
  end
34
40
 
35
41
  private
@@ -37,5 +43,11 @@ module Rmsgen
37
43
  def compress!
38
44
  @body = Compresser.new(self).body
39
45
  end
46
+
47
+ def sanitize_urgent_attribute(attribute)
48
+ return false if attribute == 'false'
49
+ return true if attribute == 'true'
50
+ attribute
51
+ end
40
52
  end
41
53
  end
@@ -9,14 +9,11 @@ module Rmsgen
9
9
  end
10
10
 
11
11
  def run!
12
- if @notes
13
- @notes.each do |note|
14
- system('clear')
15
- polnote = Rmsgen::Inquirer.inquire_about_note(note)
16
- write(polnote)
17
- end
18
- else
19
- puts 'no polnotes in queue'
12
+ puts 'no polnotes in queue' if @notes.empty?
13
+ @notes.each do |note|
14
+ system('clear')
15
+ polnote = Rmsgen::Inquirer.inquire_about_note(note)
16
+ write(polnote)
20
17
  end
21
18
  end
22
19
 
@@ -39,18 +36,17 @@ module Rmsgen
39
36
  else
40
37
  notes = fetch_notes_from_imap
41
38
  end
42
- notes.map { |note| Rmsgen::Polnote.new(note) } if notes
39
+ notes.map { |note| Rmsgen::Polnote.new(:body => note) } if notes
43
40
  end
44
41
 
45
42
  def fetch_notes_from_imap
46
43
  options = {
44
+ 'imap_server' => @config['imap_server'],
47
45
  'imap_login' => @config['imap_login'],
48
46
  'imap_password' => @config['imap_password']
49
47
  }
50
48
 
51
- imap = Net::IMAP.new(@config['imap_server'])
52
- Rmsgen::IMAPPolnoteGroup.new(imap, options).fetch_notes
49
+ Rmsgen::IMAPPolnoteGroup.new(options).fetch_notes
53
50
  end
54
-
55
51
  end
56
52
  end
@@ -1,14 +1,17 @@
1
1
  module Rmsgen
2
2
  class Titleizer
3
+ SPACE = ' '
4
+ UNDERSCORE = '_'
5
+
3
6
  TEMPLATE = File.join(File.dirname(__FILE__), '..', 'templates', 'title.erb')
4
7
 
5
8
  attr_reader :title
6
9
 
7
10
  def initialize(polnote, options={})
8
- @body = polnote.body
9
- @title = options[:title]
11
+ @title = options[:title]
12
+ @body = polnote.body
13
+ @script = Script.new($stdout)
10
14
 
11
- @script = Script.new($stdout)
12
15
  run!
13
16
  end
14
17
 
@@ -16,28 +19,34 @@ module Rmsgen
16
19
  ERB.new(File.read(TEMPLATE)).result(binding)
17
20
  end
18
21
 
19
- def today_format
20
- Date.today.strftime('%d %B %Y')
22
+ def to_html
23
+ body
21
24
  end
22
25
 
23
- def today_underscore
24
- today_format.gsub(' ', '_')
26
+ private
27
+
28
+ def run!
29
+ @title = capitalize(get_title_from_options_or_script)
25
30
  end
26
31
 
27
- def title_underscore
28
- @title.gsub(' ', '_')
32
+ def get_title_from_options_or_script
33
+ @title || @script.prompt_for_title
29
34
  end
30
35
 
31
- def to_html
32
- body
36
+ def capitalize(title=SPACE)
37
+ title.split(SPACE).map(&:capitalize).join(SPACE)
33
38
  end
34
39
 
35
- private
36
-
37
- def run!
38
- @title = @script.prompt_for_title unless @title
39
- body
40
+ def today_format
41
+ Date.today.strftime('%d %B %Y')
40
42
  end
41
43
 
44
+ def today_underscore
45
+ today_format.gsub(SPACE, UNDERSCORE)
46
+ end
47
+
48
+ def title_underscore
49
+ @title.gsub(SPACE, UNDERSCORE)
50
+ end
42
51
  end
43
52
  end
@@ -1,3 +1,3 @@
1
1
  module Rmsgen
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,2 +1,2 @@
1
- <%= "<!-- Expires #{@expires_on} -->" if @expires_on %><%= @title %><% parts.map do |part| %><% if part =~ /<!--/ %><%= part %><% else %><p><%= part %></p><% end %>
1
+ <%= @title %><% parts.map do |part| %><% if part =~ /<!--/ %><%= part %><% else %><p><%= part %></p><% end %>
2
2
  <% end %>
@@ -0,0 +1,3 @@
1
+ <li><%= "<!-- Expires #{@expires_on} -->" if @expires_on %>
2
+ <% parts.map do |part| %><% if part =~ /<!--/ %><%= part %><% else %><p><%= part %></p><% end %><% end %>
3
+ </li>
@@ -2,8 +2,9 @@ require 'rmsgen'
2
2
 
3
3
  describe Rmsgen::IMAPPolnoteGroup do
4
4
  context 'fetching notes' do
5
- let(:imap) { double('imap') }
5
+ let(:imap) { double('foo') }
6
6
  let(:options) do {
7
+ 'imap_server' => 'foo.bar.com',
7
8
  'imap_login' => 'login',
8
9
  'imap_password' => 'password'}
9
10
  end
@@ -11,8 +12,9 @@ describe Rmsgen::IMAPPolnoteGroup do
11
12
  let(:do_fetch) do
12
13
  imap.should_receive(:search).any_number_of_times
13
14
  imap.should_receive(:authenticate).any_number_of_times
15
+ Net::IMAP.should_receive(:new).any_number_of_times.and_return(imap)
14
16
  imap.should_receive(:select).any_number_of_times
15
- Rmsgen::IMAPPolnoteGroup.new(imap, options).fetch_notes
17
+ Rmsgen::IMAPPolnoteGroup.new(options).fetch_notes
16
18
  end
17
19
 
18
20
  it 'authenticates with imap server' do
@@ -36,7 +38,7 @@ describe Rmsgen::IMAPPolnoteGroup do
36
38
 
37
39
  imap.stub(:search) { search_result }
38
40
 
39
- imap.should_receive(:fetch).with(message_id, 'BODY[TEXT]')
41
+ imap.should_receive(:fetch).with(message_id, 'RFC822')
40
42
  do_fetch
41
43
  end
42
44
  end
data/spec/inqirer_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Rmsgen::Inquirer do
7
7
  let(:stdout) { StringIO.new }
8
8
 
9
9
  describe "inquires about a note which is indented" do
10
- let(:note) { Rmsgen::Polnote.new("foo\n\nhttp://\n\n bar") }
10
+ let(:note) { Rmsgen::Polnote.new(:body => "foo\n\nhttp://\n\n bar") }
11
11
 
12
12
  subject { Rmsgen::Inquirer.new(note, stdout) }
13
13
 
@@ -22,7 +22,7 @@ describe Rmsgen::Inquirer do
22
22
  end
23
23
 
24
24
  describe "it inquires about each link in a note" do
25
- let(:note) { Rmsgen::Polnote.new("foo\n\nhttp://\n\nbar\n\nhttp://") }
25
+ let(:note) { Rmsgen::Polnote.new(:body => "foo\n\nhttp://\n\nbar\n\nhttp://") }
26
26
  subject { Rmsgen::Inquirer.new(note, stdout) }
27
27
 
28
28
  before do
@@ -37,7 +37,7 @@ describe Rmsgen::Inquirer do
37
37
 
38
38
  describe "inquiring about a duration" do
39
39
  it "asks for the end date of the duration" do
40
- note = Rmsgen::Polnote.new("For one week:\n\nUrgent: blah blah blah")
40
+ note = Rmsgen::Polnote.new(:body => "For one week:\n\nUrgent: blah blah blah")
41
41
  $stdin = FakeGetMany.new("July 1")
42
42
  Rmsgen::Inquirer.new(note, stdout)
43
43
  note.expires_on.should be == "July 1"
@@ -46,7 +46,7 @@ describe Rmsgen::Inquirer do
46
46
 
47
47
  describe 'when a blank answer is given' do
48
48
  it 'returns the polnote text without links' do
49
- note = Rmsgen::Polnote.new("foo bar\n\nhttp://")
49
+ note = Rmsgen::Polnote.new(:body => "foo bar\n\nhttp://")
50
50
  $stdin = FakeGetMany.new("")
51
51
  inquirer = Rmsgen::Inquirer.new(note, stdout)
52
52
  inquirer.body.should be == "foo bar"
data/spec/polnote_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Rmsgen::Polnote do
9
9
 
10
10
  context "urgent polnote truthfully responds to urgent?" do
11
11
  let(:urgent) { fixture(:urgent_note) }
12
- let(:polnote) { Rmsgen::Polnote.new(urgent) }
12
+ let(:polnote) { Rmsgen::Polnote.new(:body => urgent) }
13
13
 
14
14
  it "truthfully responds to urgent?" do
15
15
  polnote.urgent?.should be true
@@ -20,7 +20,7 @@ describe Rmsgen::Polnote do
20
20
  let(:imap_note) { fixture(:imap_note) }
21
21
 
22
22
  it "has parts" do
23
- note = Rmsgen::Polnote.new(imap_note)
23
+ note = Rmsgen::Polnote.new(:body => imap_note)
24
24
  note.parts.should == ['hello', 'world']
25
25
  end
26
26
  end
@@ -35,7 +35,7 @@ describe Rmsgen::Polnote do
35
35
 
36
36
  $stdout = StringIO.new
37
37
  $stdin = FakeGetMany.new(text_a, polnote_url, text_b)
38
- polnote = Rmsgen::Polnote.new(note)
38
+ polnote = Rmsgen::Polnote.new(:body => note)
39
39
  polnote.inquire
40
40
  polnote.to_html.should ==
41
41
  %Q{<p>Somewhere over the <a href='http://rainbow.org'>rainbow</a>.</p>
@@ -52,7 +52,7 @@ describe Rmsgen::Polnote do
52
52
  text_a = "Somewhere"
53
53
  text_b = "Candy"
54
54
  $stdin = FakeGetMany.new(text_a, text_b)
55
- polnote = Rmsgen::Polnote.new(multiline_note)
55
+ polnote = Rmsgen::Polnote.new(:body => multiline_note)
56
56
  polnote.inquire
57
57
  polnote.to_html.should == "<p> <a href='http://unicorns.org'>Somewhere</a> over the rainbow skies are blue</p>\n<p>Candy is sweet and unicorns are too</p>\n\n"
58
58
  end
data/spec/runtime_spec.rb CHANGED
@@ -23,7 +23,7 @@ describe Rmsgen::Runtime do
23
23
  imap_note = mock(:note)
24
24
  notes = [imap_note]
25
25
 
26
- imap_note.stub(:attr) { {"BODY[TEXT]"=>"hello world"} }
26
+ imap_note.stub(:attr) { {"RFC822"=>"hello world"} }
27
27
  imap.stub(:authenticate)
28
28
  imap.stub(:select)
29
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmsgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-09 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-09-19 00:00:00.000000000Z
14
13
  dependencies: []
15
14
  description: A library to help generate html markup from RMS emails
16
15
  email:
@@ -62,6 +61,7 @@ files:
62
61
  - lib/rmsgen/version.rb
63
62
  - lib/templates/polnote.erb
64
63
  - lib/templates/title.erb
64
+ - lib/templates/urgent.erb
65
65
  - rmsgen.gemspec
66
66
  - spec/fake_gets.rb
67
67
  - spec/fixtures/imap_note
@@ -75,7 +75,6 @@ files:
75
75
  - spec/polnote_spec.rb
76
76
  - spec/runtime_spec.rb
77
77
  - spec/support/fake_gets.rb
78
- has_rdoc: true
79
78
  homepage: ''
80
79
  licenses: []
81
80
  post_install_message:
@@ -96,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
95
  version: '0'
97
96
  requirements: []
98
97
  rubyforge_project: rmsgen
99
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.10
100
99
  signing_key:
101
100
  specification_version: 3
102
101
  summary: A library to help generate html markup from RMS emails