rss2mail 0.4.2 → 0.4.3

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: da44450970cae6a855ed36595edbf43fbbb726eb
4
- data.tar.gz: 4ef9eb4347a2c48a511a8d9c06e1e5a1de96b2f9
3
+ metadata.gz: 19c5eb6339d4ffc691faac4c7b350fd85439f00b
4
+ data.tar.gz: 973e021b179b3c2ab6d58ac6d31388e5279ea628
5
5
  SHA512:
6
- metadata.gz: 501b93b1ece8e8fbf11868c04b30a6d6ed6b40b3318677100a6888d10fbcf821cc7e68ad4a15493369605295becfc605fafc6b7baf5a0afc64e35c8329194dbf
7
- data.tar.gz: 7a69c1b5ca75868bd6bc9ba3aeb86c0f668bac13aa8bda6a5518f90f04b6ef6208496491c8402d48218626208ea4e9888ceb13c537ed7bfa0a4dbe06247fb689
6
+ metadata.gz: 2dc5517ca3bfa91ae4b4c1755fb9006ffab3f310b7d84a6769c48c866d6af10d109459aa04df9efbf794cf34abd856f5ed9d3d34811bee143b7064ab24757d50
7
+ data.tar.gz: e2485e05eff43f7d0b18d4a1d2861b929f52018e9fd96036d5cd85dad87dc6e1817176679d363d018184844587a14037d47c2d12390524f49d724603a5ec769b
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to rss2mail version 0.4.2
5
+ This documentation refers to rss2mail version 0.4.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -13,7 +13,7 @@ recipients. See <tt>example/</tt> directory for a sample configuration file.
13
13
 
14
14
  == LINKS
15
15
 
16
- Documentation:: https://blackwinter.github.io/rss2mail/
16
+ Documentation:: https://blackwinter.github.com/rss2mail
17
17
  Source code:: https://github.com/blackwinter/rss2mail
18
18
  RubyGem:: https://rubygems.org/gems/rss2mail
19
19
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ begin
14
14
  homepage: :blackwinter,
15
15
  extra_files: FileList['templates/*'].to_a,
16
16
  dependencies: %w[
17
- cyclops nokogiri ruby-nuggets safe_yaml
17
+ cyclops nokogiri nuggets safe_yaml
18
18
  simple-rss sinatra unidecoder
19
19
  ],
20
20
 
data/lib/rss2mail/app.rb CHANGED
@@ -41,7 +41,7 @@ end
41
41
  helpers ERB::Util
42
42
 
43
43
  get '/' do
44
- prepare(false)
44
+ prepare
45
45
 
46
46
  if @feed_url = RSS2Mail::Util.discover_feed(@url = params[:url])
47
47
  @title = Nokogiri.HTML(open(@feed_url)).at_css('title').content rescue nil
@@ -53,46 +53,46 @@ end
53
53
  post '/' do
54
54
  prepare
55
55
 
56
- @title, @to = params[:title] || '', params[:to]
57
- @title = @feed_url[/[^\/]+\z/][/[\w.]+/] if @title.empty?
58
-
59
- update { |feeds, feed|
60
- new_feed = { url: @feed_url, title: @title, to: @to }
61
- feed ? feed.update(new_feed) : feeds << new_feed
62
- }
56
+ @feed_url = params[:feed_url] or error(400)
63
57
 
64
- erb :index
65
- end
58
+ @target = params[:target]
59
+ @target = @targets.find { |t| t.to_s == @target } || :daily
66
60
 
67
- delete '/' do
68
- prepare
61
+ if params[:delete] == 'delete'
62
+ update { |feeds, feed| feeds.delete(feed) }
63
+ elsif params[:skip] == 'toggle'
64
+ update { |feeds, feed| feed[:skip] = !feed[:skip] }
65
+ else
66
+ @title, @to = params[:title] || '', params[:to]
67
+ @title = @feed_url[/[^\/]+\z/][/[\w.]+/] if @title.empty?
69
68
 
70
- update { |feeds, feed|
71
- feeds.delete(feed) or error(404)
72
- @title, @to = feed.values_at(:title, :to)
73
- }
69
+ update(true) { |feeds, feed|
70
+ new_feed = { url: @feed_url, title: @title, to: @to }
71
+ feed ? feed.update(new_feed) : feeds << new_feed
72
+ }
73
+ end
74
74
 
75
75
  erb :index
76
76
  end
77
77
 
78
- def prepare(feed = true)
78
+ def prepare
79
79
  user = request.env['REMOTE_USER'] or error(400)
80
80
 
81
81
  @feeds_file = File.join(settings.root, 'feeds.d', "#{user}.yaml")
82
82
  @feeds = RSS2Mail::Util.load_feeds(@feeds_file) || {}
83
83
  @targets = @feeds.keys.sort_by { |t, _| t.to_s }
84
+ end
84
85
 
85
- if feed
86
- @feed_url = params[:feed_url] or error(400)
86
+ def update(create = false)
87
+ feeds = @feeds[@target]
87
88
 
88
- @target = params[:target]
89
- @target = @targets.find { |t| t.to_s == @target } || :daily
90
- end
91
- end
89
+ feed = feeds.find { |f| f[:url] == @feed_url }
90
+ error(404) unless feed || create
91
+
92
+ yield feeds, feed
92
93
 
93
- def update
94
- yield feeds = @feeds[@target], feeds.find { |f| f[:url] == @feed_url }
95
94
  RSS2Mail::Util.dump_feeds(@feeds_file, @feeds)
95
+ @title, @to = feed.values_at(:title, :to) unless create
96
96
  end
97
97
 
98
98
  __END__
@@ -117,6 +117,12 @@ __END__
117
117
  font-weight: bold;
118
118
  }
119
119
 
120
+ input[type="submit"] + a {
121
+ margin-left: 2px;
122
+ font-weight: bold;
123
+ color: inherit;
124
+ }
125
+
120
126
  button {
121
127
  background: none;
122
128
  border: none;
@@ -127,6 +133,10 @@ __END__
127
133
  line-height: 0.6;
128
134
  padding: 0;
129
135
  }
136
+
137
+ small + button {
138
+ margin-left: 2px;
139
+ }
130
140
  </style>
131
141
  </head>
132
142
  <body>
@@ -160,6 +170,7 @@ __END__
160
170
  </select>
161
171
  <br />
162
172
  <input type="submit" value="subscribe" />
173
+ <a href="<%= url('/') %>" title="clear">[×]</a>
163
174
  </form>
164
175
 
165
176
  <h2>subscriptions</h2>
@@ -173,12 +184,14 @@ __END__
173
184
  <% for feed in @feeds[target].sort_by { |f| f[:title].downcase } %>
174
185
  <li>
175
186
  <form method="post">
187
+ <input type="hidden" name="target" value="<%=h target %>" />
188
+ <input type="hidden" name="feed_url" value="<%=h feed[:url] %>" />
189
+
176
190
  <a href="<%=h feed[:url] %>" class="<%= 'skip' if feed[:skip] %>"><%=h feed[:title] %></a>
177
191
  <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>
192
+
193
+ <button type="submit" name="skip" value="toggle" title="<%= feed[:skip] ? 'unskip' : 'skip' %>"><%= feed[:skip] ? '+' : '-' %></button>
194
+ <button type="submit" name="delete" value="delete" title="delete">×</button>
182
195
  </form>
183
196
  </li>
184
197
  <% end %>
data/lib/rss2mail/util.rb CHANGED
@@ -42,20 +42,28 @@ module RSS2Mail
42
42
 
43
43
  URI_RE = URI.regexp(%w[http https])
44
44
 
45
+ XPATH = '//link[@rel="alternate"]'
46
+
45
47
  # cf. <http://www.rssboard.org/rss-autodiscovery>
46
- def discover_feed(url, or_self = false)
48
+ def discover_feed(url, fallback = false)
47
49
  unless url.nil? || url.empty? || url == 'about:blank'
48
- doc = Nokogiri.HTML(open_feed(url))
49
-
50
- if link = doc.xpath('//link[@rel="alternate"]').find { |i| i[:type] =~ FEED_RE }
51
- if href = link[:href]
52
- return href =~ URI_RE ? href :
53
- URI.join((base = doc.at_xpath('//base')) && base[:href] || url, href).to_s
54
- end
50
+ begin
51
+ doc = Nokogiri.HTML(open_feed(url))
52
+ rescue => err
53
+ warn "Unable to discover feed `#{url}': #{err} (#{err.class})"
54
+ else
55
+ doc.xpath(XPATH).each { |link|
56
+ if link[:type] =~ FEED_RE && href = link[:href]
57
+ return href =~ URI_RE ? href : begin
58
+ base = doc.at_xpath('//base')
59
+ URI.join(base && base[:href] || url, href).to_s
60
+ end
61
+ end
62
+ }
55
63
  end
56
64
  end
57
65
 
58
- url if or_self
66
+ url if fallback
59
67
  end
60
68
 
61
69
  def open_feed(url, options = {}, &block)
@@ -4,7 +4,7 @@ module RSS2Mail
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 4
7
- TINY = 2
7
+ TINY = 3
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.2
4
+ version: 0.4.3
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-05-15 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cyclops
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-nuggets
42
+ name: nuggets
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -170,7 +170,7 @@ metadata: {}
170
170
  post_install_message:
171
171
  rdoc_options:
172
172
  - "--title"
173
- - rss2mail Application documentation (v0.4.2)
173
+ - rss2mail Application documentation (v0.4.3)
174
174
  - "--charset"
175
175
  - UTF-8
176
176
  - "--line-numbers"
@@ -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.x
194
+ rubygems_version: 2.4.1
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Send RSS feeds as e-mail