mako_rss 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 290598ad944edc63e67424f6a7fe9000eef34764
4
- data.tar.gz: 4549a791353d7f41cff731aef8c8b4ded2a65d96
3
+ metadata.gz: 36e2ef1d6c047979056ee71f1bc6b1b60ad42f8c
4
+ data.tar.gz: da1e7fc95881733c0263c3f9a5e0bb9cdba579de
5
5
  SHA512:
6
- metadata.gz: d512d6f6a001ddb3125370831fd69796b32ad69d28fb2ad6306e8f9fb6a5e294a04643fa8b22837e6674775528239825f5c553c2206f4e2f6c6dd7e4a143f5b2
7
- data.tar.gz: 03b3a7d9f2aae435f16dff3d93ccb1a223cfee968b61e8dee27f191b71d6457846e54da565ef142982efd8c89bebca2a86f05984a8680b4a1a9d48b04568d340
6
+ metadata.gz: c171053333bb66e7781ecac1e3239447fa896358002eeae728f92608a9e4c62fa4f72cebd29855fecf1845d45e0770d9bc49438b141ddba6f954338e65080548
7
+ data.tar.gz: bd83759022b68479a87eed75d5bb662af64f2c154e3fb6469d526fdce5e8b615bec48bf7351d2dd6382798d6516c16e8f12f6692ec9822fd669a3b9927563947
data/lib/mako/article.rb CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  module Mako
4
4
  class Article
5
- attr_reader :title, :published, :summary, :url
5
+ attr_reader :title, :published, :summary, :uri
6
6
 
7
7
  def initialize(args)
8
8
  @title = args.fetch(:title, '')
9
9
  @published = args.fetch(:published)
10
+ @uri = URI.parse(args.fetch(:url))
10
11
  @summary = sanitize(args.fetch(:summary))
11
- @url = args.fetch(:url)
12
12
  end
13
13
 
14
14
  # Converts published Time object to formatted string
@@ -18,17 +18,29 @@ module Mako
18
18
  @published.strftime('%A, %d %B %Y at %I:%M %P')
19
19
  end
20
20
 
21
+ # Converts URI object into string
22
+ #
23
+ # @return [String]
24
+ def url
25
+ uri.to_s
26
+ end
27
+
21
28
  private
22
29
 
23
- # @private
24
- # Removes img tags (if configured) and transforms h1 tags into
25
- # p tags with the class bold
30
+ # Transforms img tags into a tags (if configured) and transforms h1 tags
31
+ # into p tags with the class bold
26
32
  #
27
33
  # @param [String] html an html document string
28
34
  # @return [String] a sanitized html document string
29
35
  def sanitize(html)
30
36
  doc = Nokogiri::HTML::DocumentFragment.parse(html)
31
- doc.css('img').each(&:remove) if Mako.config.sanitize_images
37
+ if Mako.config.sanitize_images
38
+ doc.css('img').each do |n|
39
+ n.name = 'a'
40
+ n.content = "📷 #{n['alt']}" || '📷 Image'
41
+ n['href'] = URI.parse(n['src']).absolutize!(uri)
42
+ end
43
+ end
32
44
  doc.css('h1,h2,h3,h4,h5,h6').each { |n| n.name = 'p'; n.set_attribute('class', 'bold') }
33
45
  doc.to_s
34
46
  end
@@ -9,6 +9,7 @@ module Mako
9
9
  end
10
10
  feeds = Mako::FeedFinder.new(uris: args).find
11
11
  write_to_subscriptions(feeds)
12
+ Mako.logger.info "Subscribed to the following feeds: #{feeds}"
12
13
  end
13
14
 
14
15
  def self.write_to_subscriptions(feed_urls)
data/lib/mako/core.rb CHANGED
@@ -49,7 +49,6 @@ module Mako
49
49
 
50
50
  private
51
51
 
52
- # @private
53
52
  # Prints configuration file, source, and destination directory to STDOUT.
54
53
  def log_configuration_information
55
54
  Mako.logger.info "Configuration File: #{Mako.config.config_file}"
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module URI
4
+ class Generic
5
+ # Compares parsed URI with a base URI and adds the host section, if needed
6
+ #
7
+ # @param base_uri [URI]
8
+ def absolutize!(base_uri)
9
+ base_uri.host == host ? to_s : base_uri.merge(self).to_s
10
+ end
11
+ end
12
+ end
data/lib/mako/core_ext.rb CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'core_ext/numeric'
4
4
  require_relative 'core_ext/time'
5
+ require_relative 'core_ext/uri'
@@ -23,7 +23,6 @@ module Mako
23
23
 
24
24
  private
25
25
 
26
- # @private
27
26
  # Takes raw XML and parses it into a Feedjira::Feed object
28
27
  #
29
28
  # @return [Feedjira::Feed]
@@ -30,21 +30,19 @@ module Mako
30
30
  else
31
31
  html = Nokogiri::HTML(request[:body])
32
32
  potential_feed_uris = html.xpath(XPATHS.detect { |path| !html.xpath(path).empty? })
33
- next if potential_feed_uris.empty?
33
+ if potential_feed_uris.empty?
34
+ Mako.errors.add_error "Could not find feed for #{request[:uri]}"
35
+ next
36
+ end
34
37
  uri_string = potential_feed_uris.first.value
35
38
  feed_uri = URI.parse(uri_string)
36
- if request[:uri].host == feed_uri.host
37
- feed_uri.to_s
38
- else
39
- request[:uri].merge(feed_uri).to_s
40
- end
39
+ feed_uri.absolutize!(request[:uri])
41
40
  end
42
41
  end.compact
43
42
  end
44
43
 
45
44
  private
46
45
 
47
- # @private
48
46
  # Make requests for each URI passed in and return an array of hashes
49
47
  # with either just the URI (in the case that the URI passed in was already
50
48
  # a feed URI), or the URI and the response body.
@@ -22,7 +22,6 @@ module Mako
22
22
 
23
23
  private
24
24
 
25
- # @private
26
25
  # Returns the rendered string for the correct file type.
27
26
  #
28
27
  # @return [String]
data/lib/mako/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mako
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mako_rss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Pike
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -181,6 +181,7 @@ files:
181
181
  - lib/mako/core_ext.rb
182
182
  - lib/mako/core_ext/numeric.rb
183
183
  - lib/mako/core_ext/time.rb
184
+ - lib/mako/core_ext/uri.rb
184
185
  - lib/mako/errors.rb
185
186
  - lib/mako/feed.rb
186
187
  - lib/mako/feed_constructor.rb