rss2mail 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017417bfb43b6f08d3d3c796a060ea0acf87f5de
4
- data.tar.gz: 7f7368f9f3d2bf056d4252fbf79cf1c24b4f27ef
3
+ metadata.gz: da44450970cae6a855ed36595edbf43fbbb726eb
4
+ data.tar.gz: 4ef9eb4347a2c48a511a8d9c06e1e5a1de96b2f9
5
5
  SHA512:
6
- metadata.gz: 437ecbd3b9f6bb2fb5a1087f0ee8f3bc0371531216c3e5bcd9d6725d0690fc22da8447215de6b2d6adfa89b6bd7c2629ef923bef8b2b4a65866fb2fc117600f5
7
- data.tar.gz: c896efbe7131abe1ba37a88a1ec9af9cd6c9fb4bac427aea5a4a483953f8cccc953a6926474b2ed4b18b742ac7f0e89b5b87d1e837935b7b6d91c649afc9bd5d
6
+ metadata.gz: 501b93b1ece8e8fbf11868c04b30a6d6ed6b40b3318677100a6888d10fbcf821cc7e68ad4a15493369605295becfc605fafc6b7baf5a0afc64e35c8329194dbf
7
+ data.tar.gz: 7a69c1b5ca75868bd6bc9ba3aeb86c0f668bac13aa8bda6a5518f90f04b6ef6208496491c8402d48218626208ea4e9888ceb13c537ed7bfa0a4dbe06247fb689
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to rss2mail version 0.4.1
5
+ This documentation refers to rss2mail version 0.4.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -4,19 +4,21 @@ begin
4
4
  require 'hen'
5
5
 
6
6
  Hen.lay! {{
7
- :gem => {
8
- :name => %q{rss2mail},
9
- :version => RSS2Mail::VERSION,
10
- :summary => %q{Send RSS feeds as e-mail},
11
- :author => %q{Jens Wille},
12
- :email => %q{jens.wille@gmail.com},
13
- :license => %q{AGPL-3.0},
14
- :homepage => :blackwinter,
15
- :extra_files => FileList['templates/*'].to_a,
16
- :dependencies => %w[
7
+ gem: {
8
+ name: %q{rss2mail},
9
+ version: RSS2Mail::VERSION,
10
+ summary: %q{Send RSS feeds as e-mail},
11
+ author: %q{Jens Wille},
12
+ email: %q{jens.wille@gmail.com},
13
+ license: %q{AGPL-3.0},
14
+ homepage: :blackwinter,
15
+ extra_files: FileList['templates/*'].to_a,
16
+ dependencies: %w[
17
17
  cyclops nokogiri ruby-nuggets safe_yaml
18
18
  simple-rss sinatra unidecoder
19
- ]
19
+ ],
20
+
21
+ required_ruby_version: '>= 1.9.3'
20
22
  }
21
23
  }}
22
24
  rescue LoadError => err
data/lib/rss2mail/app.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # A component of rss2mail, the RSS to e-mail forwarder. #
7
7
  # #
8
- # Copyright (C) 2007-2013 Jens Wille #
8
+ # Copyright (C) 2007-2014 Jens Wille #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@gmail.com> #
@@ -28,12 +28,11 @@
28
28
 
29
29
  require 'sinatra'
30
30
  require 'rss2mail/util'
31
- require 'safe_yaml/load'
32
31
 
33
32
  use Rack::Auth::Basic do |user, pass|
34
33
  @auth ||= begin
35
- file = File.join(settings.root, 'auth.yaml')
36
- File.readable?(file) ? SafeYAML.load_file(file) : {}
34
+ auth_file = File.join(settings.root, 'auth.yaml')
35
+ File.readable?(auth_file) ? SafeYAML.load_file(auth_file) : {}
37
36
  end
38
37
 
39
38
  @auth[user] == pass
@@ -42,7 +41,7 @@ end
42
41
  helpers ERB::Util
43
42
 
44
43
  get '/' do
45
- prepare
44
+ prepare(false)
46
45
 
47
46
  if @feed_url = RSS2Mail::Util.discover_feed(@url = params[:url])
48
47
  @title = Nokogiri.HTML(open(@feed_url)).at_css('title').content rescue nil
@@ -54,29 +53,46 @@ end
54
53
  post '/' do
55
54
  prepare
56
55
 
57
- @feed_url = params[:feed_url] or error(400)
58
-
59
- @target = params[:target]
60
- @target = @targets.find { |t| t.to_s == @target } || :daily
61
-
62
56
  @title, @to = params[:title] || '', params[:to]
63
57
  @title = @feed_url[/[^\/]+\z/][/[\w.]+/] if @title.empty?
64
58
 
65
- unless (feeds = @feeds[@target]).find { |f| f[:url] == @feed_url }
66
- feeds << { :url => @feed_url, :title => @title, :to => @to }
67
- File.open(@feeds_file, 'w') { |f| YAML.dump(@feeds, f) }
68
- end
59
+ update { |feeds, feed|
60
+ new_feed = { url: @feed_url, title: @title, to: @to }
61
+ feed ? feed.update(new_feed) : feeds << new_feed
62
+ }
63
+
64
+ erb :index
65
+ end
66
+
67
+ delete '/' do
68
+ prepare
69
+
70
+ update { |feeds, feed|
71
+ feeds.delete(feed) or error(404)
72
+ @title, @to = feed.values_at(:title, :to)
73
+ }
69
74
 
70
75
  erb :index
71
76
  end
72
77
 
73
- def prepare
78
+ def prepare(feed = true)
74
79
  user = request.env['REMOTE_USER'] or error(400)
75
80
 
76
81
  @feeds_file = File.join(settings.root, 'feeds.d', "#{user}.yaml")
77
- @feeds = File.readable?(@feeds_file) ?
78
- SafeYAML.load_file(@feeds_file, :deserialize_symbols => true) : {}
82
+ @feeds = RSS2Mail::Util.load_feeds(@feeds_file) || {}
79
83
  @targets = @feeds.keys.sort_by { |t, _| t.to_s }
84
+
85
+ if feed
86
+ @feed_url = params[:feed_url] or error(400)
87
+
88
+ @target = params[:target]
89
+ @target = @targets.find { |t| t.to_s == @target } || :daily
90
+ end
91
+ end
92
+
93
+ def update
94
+ yield feeds = @feeds[@target], feeds.find { |f| f[:url] == @feed_url }
95
+ RSS2Mail::Util.dump_feeds(@feeds_file, @feeds)
80
96
  end
81
97
 
82
98
  __END__
@@ -91,25 +107,50 @@ __END__
91
107
  <% if settings.style %>
92
108
  <link rel="stylesheet" type="text/css" href="<%=h settings.style %>" />
93
109
  <% end %>
94
- <style type="text/css">a.skip { text-decoration: line-through; }</style>
110
+ <style type="text/css">
111
+ a.skip {
112
+ text-decoration: line-through;
113
+ }
114
+
115
+ input[type="submit"] {
116
+ margin-top: 0.6em;
117
+ font-weight: bold;
118
+ }
119
+
120
+ button {
121
+ background: none;
122
+ border: none;
123
+ cursor: pointer;
124
+ color: inherit;
125
+ font-size: large;
126
+ font-weight: bold;
127
+ line-height: 0.6;
128
+ padding: 0;
129
+ }
130
+ </style>
95
131
  </head>
96
132
  <body>
97
- <h1>rss2mail - send rss feeds as e-mail</h1>
133
+ <h1>rss2mail send rss feeds as e-mail</h1>
98
134
 
99
135
  <h2>subscribe</h2>
100
136
 
101
137
  <form method="post">
102
- <input type="text" id="feed_url" name="feed_url" value="<%= @feed_url || @url %>" size="54" />
138
+ <input type="text" id="feed_url" name="feed_url" value="<%=h @feed_url || @url %>" size="54" />
103
139
  <% if @url.nil? || @url.empty? %>
104
140
  <label for="feed_url">»url«</label>
105
141
  <% else %>
106
- [<a href="<%= @url %>">link</a><% if @feed_url %> | <a href="<%= @feed_url %>">feed</a><% end %>]
142
+ [<a href="<%=h @url %>">link</a><% if @feed_url %> | <a href="<%=h @feed_url %>">feed</a><% end %>]
107
143
  <% end %>
108
144
  <br />
109
145
  <input type="text" id="title" name="title" value="<%=h @title %>" size="54" />
110
146
  <label for="title">»title«</label>
111
147
  <br />
112
- <input type="text" id="to" name="to" value="<%=h @to %>" size="54" />
148
+ <input type="text" id="to" name="to" value="<%=h @to %>" size="54" list="tos" />
149
+ <datalist id="tos">
150
+ <% for to in @feeds.values.map { |feeds| feeds.map { |feed| feed[:to] } }.flatten.uniq.sort %>
151
+ <option value="<%=h to %>" />
152
+ <% end %>
153
+ </datalist>
113
154
  <label for="to">»to«</label>
114
155
  <br />
115
156
  <select id="target" name="target">
@@ -118,7 +159,7 @@ __END__
118
159
  <% end %>
119
160
  </select>
120
161
  <br />
121
- <input type="submit" value="subscribe!" style="margin-top: 0.6em; font-weight: bold" />
162
+ <input type="submit" value="subscribe" />
122
163
  </form>
123
164
 
124
165
  <h2>subscriptions</h2>
@@ -131,8 +172,14 @@ __END__
131
172
  <ul>
132
173
  <% for feed in @feeds[target].sort_by { |f| f[:title].downcase } %>
133
174
  <li>
134
- <a href="<%= feed[:url] %>" class="<%= 'skip' if feed[:skip] %>"><%=h feed[:title] %></a>
135
- <small>(<%=h Array(feed[:to]).join(', ') %>)</small>
175
+ <form method="post">
176
+ <a href="<%=h feed[:url] %>" class="<%= 'skip' if feed[:skip] %>"><%=h feed[:title] %></a>
177
+ <small>(<%=h Array(feed[:to]).join(', ') %>)</small>
178
+ <input type="hidden" name="_method" value="delete" />
179
+ <input type="hidden" name="target" value="<%=h target %>" />
180
+ <input type="hidden" name="feed_url" value="<%=h feed[:url] %>" />
181
+ <button type="submit" title="delete">×</button>
182
+ </form>
136
183
  </li>
137
184
  <% end %>
138
185
  </ul>
@@ -142,7 +189,7 @@ __END__
142
189
 
143
190
  <p><em>
144
191
  powered by <a href="http://blackwinter.github.com/rss2mail">RSS2Mail</a>
145
- and <a href="http://sinatrarb.com">Sinatra</a> -- v<%=h RSS2Mail::VERSION %>
192
+ and <a href="http://sinatrarb.com">Sinatra</a> v<%=h RSS2Mail::VERSION %>
146
193
  </em></p>
147
194
  </body>
148
195
  </html>
data/lib/rss2mail/cli.rb CHANGED
@@ -68,9 +68,7 @@ module RSS2Mail
68
68
  }
69
69
 
70
70
  (options.delete(:files) || default_files).each { |feeds_file|
71
- feeds = begin
72
- SafeYAML.load_file(feeds_file, deserialize_symbols: true)
73
- rescue Errno::ENOENT
71
+ feeds = RSS2Mail::Util.load_feeds(feeds_file) or begin
74
72
  warn "Feeds file not found: #{feeds_file}"
75
73
  next
76
74
  end
@@ -84,9 +82,7 @@ module RSS2Mail
84
82
  Feed.new(feed, options).deliver(templates) unless feed[:skip]
85
83
  }
86
84
 
87
- unless options[:debug]
88
- File.open(feeds_file, 'w') { |file| YAML.dump(feeds, file) }
89
- end
85
+ RSS2Mail::Util.dump_feeds(feeds_file, feeds) unless options[:debug]
90
86
  }
91
87
  end
92
88
 
data/lib/rss2mail/rss.rb CHANGED
@@ -114,13 +114,13 @@ module RSS2Mail
114
114
  end
115
115
 
116
116
  def date
117
- @date ||= value_for({ :date => %w[pubDate updated dc_date] }, :content) { |field, value|
117
+ @date ||= value_for({ date: %w[pubDate updated dc_date] }, :content) { |field, value|
118
118
  field == 'updated' && value.respond_to?(:content) ? Time.at(value.content.to_i) : value
119
119
  }
120
120
  end
121
121
 
122
122
  def author
123
- @author ||= value_for({ :author => %w[contributor dc_creator] }, %w[name content])
123
+ @author ||= value_for({ author: %w[contributor dc_creator] }, %w[name content])
124
124
  end
125
125
 
126
126
  def body(tag = nil, encoding = nil)
@@ -162,7 +162,7 @@ module RSS2Mail
162
162
  end
163
163
 
164
164
  def get_description(unescape_html)
165
- description = value_for({ :description => %w[summary content] }, :content)
165
+ description = value_for({ description: %w[summary content] }, :content)
166
166
 
167
167
  if description && unescape_html
168
168
  description.gsub!(/&lt;/, '<')
@@ -196,7 +196,7 @@ module RSS2Mail
196
196
 
197
197
  def clean_subject(str)
198
198
  str.replace_diacritics!
199
- str.gsub!(SUB_RE) { |m| SUB[m] }
199
+ str.gsub!(SUB_RE, SUB)
200
200
  str.to_ascii
201
201
  end
202
202
 
data/lib/rss2mail/util.rb CHANGED
@@ -26,6 +26,7 @@
26
26
 
27
27
  require 'open-uri'
28
28
  require 'nokogiri'
29
+ require 'safe_yaml/load'
29
30
 
30
31
  require 'rss2mail/version'
31
32
 
@@ -61,6 +62,15 @@ module RSS2Mail
61
62
  open(url, options.merge('User-Agent' => USER_AGENT), &block)
62
63
  end
63
64
 
65
+ def load_feeds(feeds_file)
66
+ return unless File.readable?(feeds_file)
67
+ SafeYAML.load_file(feeds_file, deserialize_symbols: true)
68
+ end
69
+
70
+ def dump_feeds(feeds_file, feeds)
71
+ File.open(feeds_file, 'w') { |file| YAML.dump(feeds, file) }
72
+ end
73
+
64
74
  end
65
75
 
66
76
  end
@@ -4,7 +4,7 @@ module RSS2Mail
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 4
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss2mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cyclops
@@ -170,7 +170,7 @@ metadata: {}
170
170
  post_install_message:
171
171
  rdoc_options:
172
172
  - "--title"
173
- - rss2mail Application documentation (v0.4.1)
173
+ - rss2mail Application documentation (v0.4.2)
174
174
  - "--charset"
175
175
  - UTF-8
176
176
  - "--line-numbers"
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="
185
185
  - !ruby/object:Gem::Version
186
- version: '0'
186
+ version: 1.9.3
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.2.2
194
+ rubygems_version: 2.2.2.x
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Send RSS feeds as e-mail