polyrex-feed-reader 0.5.4 → 0.5.5

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: 01f09a83dff9840dc00f6a34617af7d181f9fe4c
4
- data.tar.gz: a990755a83d3faa0f4df2e6de79b8286781831c4
3
+ metadata.gz: 85019351de16c7097af235b167c26bb725c30afd
4
+ data.tar.gz: 35b68a4f5da9abe5cbbf72e696b701042bd3f023
5
5
  SHA512:
6
- metadata.gz: 97b0b5bd18ab70b8213d4e3ea717ded02bc514ed23b57295cb00ed0e5131ddd51fb5a4abc020cda37ae5b20313f2f7aa24739c3f647c4c39f34d8e6d2404e8b0
7
- data.tar.gz: 15f4ffbb979c28224a8b5185233201c9509e9c1fa2f67fb47bcbd616e59c5815f711c07821bc189c58f7d4d50c3b04eeaefa0af8e52eae23b86c606fb53fa220
6
+ metadata.gz: 5ef6e17bed5406b734d6249755ad13a9b897c2b8ef0ab31c58d3b462445590986978fad95c3f0073f44d6045e85737d52115ac7414b91010d04f6f122b07e6c0
7
+ data.tar.gz: 78ee2d7e9bc126f715291b01d2ceaa0f155473d721cd18cf04d410769c35bf4bdb3f9b5f3821899462b840bc51a63704c02c67d86d4c7d0691fd7692d8a68dbd
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
+ <xsl:output method="html" indent="yes" />
4
+ <xsl:template match="*">
5
+ <html>
6
+ <head>
7
+ <!--<link rel='stylesheet' type='text/css' href='dynarex-feed.css' media='screen, projection, tv, print'></link>-->
8
+ <style type="text/css">
9
+
10
+ body {background-color: #aa5}
11
+ #records {background-color: #888;}
12
+ #records>ul {background-color: #ecf;list-style-type: none; margin: 0.2em; padding: 0.2em}
13
+ #records>ul>li { background-color: #956;}
14
+
15
+ #records>ul>li:nth-child(even) { background:#4b3; }
16
+ #records>ul>li>div {
17
+ background-color: #9ca;
18
+ -moz-column-count: 3; -moz-column-gap: 1em; -moz-column-rule: 1px solid black; -webkit-column-count: 3; -webkit-column-gap: 1em; -webkit-column-rule: 1px solid black;
19
+ margin:0.7em 0.3em; padding: 0.4em;
20
+
21
+ }
22
+ #records>ul>li:nth-child(even)>div { background-color: #ba8; }
23
+ #records>ul>li>div>a>h1 {background-color: transparent; font-size: 1.0em;}
24
+
25
+
26
+ </style>
27
+ </head>
28
+ <body>
29
+ <div id="wrap" class="dynarex">
30
+ <ul>
31
+ <li><a href="/">home</a></li>
32
+ <li><a href="/feeds/">feeds</a></li>
33
+ </ul>
34
+ <xsl:apply-templates select="summary"/>
35
+ <xsl:apply-templates select="records"/>
36
+ </div>
37
+ </body>
38
+ </html>
39
+ </xsl:template>
40
+ <xsl:template match="summary">
41
+ <div id="summary">
42
+ <a href="{link}"><h1><xsl:value-of select="title" disable-output-escaping="true"/></h1></a>
43
+ </div>
44
+ </xsl:template>
45
+
46
+ <xsl:template match="records">
47
+ <xsl:text>
48
+ </xsl:text><div id="records">
49
+
50
+ <xsl:text>
51
+ </xsl:text>
52
+ <ul><xsl:text>
53
+ </xsl:text>
54
+
55
+
56
+ <xsl:for-each select="item">
57
+
58
+ <li><div><a name="{@id}"/>
59
+ <a href="{link}"><h1><xsl:value-of select="title"/></h1></a>
60
+ <p><xsl:value-of select="description" disable-output-escaping="yes"/></p>
61
+ <p>last updated: <xsl:value-of select="date"/></p>
62
+ </div>
63
+ </li>
64
+
65
+ </xsl:for-each>
66
+
67
+ </ul><xsl:text>
68
+ </xsl:text>
69
+ </div>
70
+ </xsl:template>
71
+
72
+ </xsl:stylesheet>
data/lib/feeds.css CHANGED
@@ -10,17 +10,25 @@ body div div {
10
10
  background-color: #9fa;
11
11
  }
12
12
 
13
- div div>ul {
14
- background-color: #eba;
13
+ .feed>ul {
14
+ background-color: transparent;
15
15
  list-style-type: none;
16
16
  margin: 0.1em; padding: 0.2em;
17
17
  }
18
18
 
19
19
  div div>ul>li {
20
- background-color: #efa;
20
+ background-color: transparent;
21
21
  }
22
22
 
23
23
  div div>ul>li a {
24
24
  background-color: #aaa;
25
25
  text-decoration: none;
26
26
  }
27
+
28
+
29
+ .a_hot {background-color: #fdd;}
30
+ .b_warm {background-color: #ea9;}
31
+ .c_cold {background-color: #aae;}
32
+ .d_coldx1week {background-color: #385;}
33
+ .e_coldx1month {background-color: #385;}
34
+ .f_coldx6months {background-color: #385;}
data/lib/feeds.xsl CHANGED
@@ -4,12 +4,12 @@
4
4
 
5
5
  <xsl:template match='feeds'>
6
6
 
7
- <html>
8
- <head>
9
- <title><xsl:value-of select="summary/title" /></title>
10
- <link rel="stylesheet" type="text/css" href="feeds.css" />
11
- </head>
12
-
7
+ <html>
8
+ <head>
9
+ <title><xsl:value-of select="summary/title" /></title>
10
+ <link rel="stylesheet" type="text/css" href="feeds.css" />
11
+ </head>
12
+
13
13
  <body onload="" style="font-family:helvetica,arial;">
14
14
 
15
15
  <xsl:apply-templates select='summary'/>
@@ -32,7 +32,7 @@
32
32
  </xsl:template>
33
33
 
34
34
  <xsl:template match='column/summary'>
35
- <h2><xsl:value-of select='id'/></h2>
35
+
36
36
  </xsl:template>
37
37
 
38
38
  <xsl:template match='records/section'>
@@ -50,15 +50,16 @@
50
50
 
51
51
 
52
52
  <xsl:template match='records/feed'>
53
-
53
+ <div class="feed {summary/recent}">
54
54
  <xsl:apply-templates select='summary'>
55
55
 
56
56
  </xsl:apply-templates>
57
57
  <ul><xsl:apply-templates select='records'/></ul>
58
+ </div>
58
59
  </xsl:template>
59
60
 
60
61
  <xsl:template match='feed/summary'>
61
- <h3><xsl:value-of select='title'/></h3>
62
+ <a href="{substring-before(xhtml,'.')}.html"><h3><xsl:value-of select='title'/></h3></a>
62
63
  <span><xsl:value-of select='last_modified'/></span>
63
64
  </xsl:template>
64
65
 
@@ -22,63 +22,73 @@ class PolyrexFeedReader
22
22
 
23
23
  end
24
24
 
25
- def fetch_feeds()
25
+ def feeds_to_html()
26
+
27
+ feeds do |feed, filename|
28
+
29
+ puts "transforming %s " % filename
30
+ xsltproc 'dynarex-feed.xsl', File.read(filename), filename.sub(/xml$/,'html')
31
+ end
32
+ end
26
33
 
27
- feeds = @polyrex.xpath('//column/records/section/records/feed/summary')
34
+ def fetch_feeds()
28
35
 
29
- feeds.each do |feed|
36
+ feeds do |feed, filename|
30
37
 
31
- puts "fetching %s " % feed.text('rss_url').inspect
38
+ puts "fetching %s " % feed.rss_url.inspect
32
39
 
33
- rtd = RSStoDynarex.new feed.text('rss_url')
40
+ rtd = RSStoDynarex.new feed.rss_url
34
41
  dynarex = rtd.to_dynarex
35
- dynarex.save "%s.xml" % feed.text('title')\
36
- .downcase.gsub(/\s/,'').gsub(/\W/,'_')
42
+
43
+ dynarex.save(filename) do |xml|
44
+ a = xml.lines.to_a
45
+ line1 = a.shift
46
+ a.unshift %Q{<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="dynarex-feed.xsl"?>\n}
47
+ a.unshift line1
48
+ a.join
49
+ end
37
50
  end
51
+
38
52
  end
39
53
 
40
54
  def refresh
41
55
 
42
- @polyrex.records.each do |column|
56
+ feeds do |feed, filename|
43
57
 
44
- column.records.each do |section|
45
-
46
- section.records.each do |feed|
58
+ puts 'adding : ' + filename.inspect
47
59
 
48
- filename = "%s.xml" % feed.title\
49
- .downcase.gsub(/\s/,'').gsub(/\W/,'_')
50
- puts 'filename : ' + filename.inspect
51
- d = Dynarex.new filename
52
- feed.last_accessed = datetimestamp()
53
- feed.last_modified = datetimestamp() if feed.last_modified.empty?
60
+ d = Dynarex.new filename
54
61
 
55
- items = d.to_h[0..2]
62
+ feed.last_accessed = datetimestamp()
63
+ feed.last_modified = datetimestamp() if feed.last_modified.empty?
64
+ feed.xhtml = filename
56
65
 
57
- if feed.records.length > 0 and \
58
- items.first[:title] == feed.item[0].title then
59
- feed.recent = recency(feed.last_modified)
60
- next
61
- end
66
+ items = d.to_h[0..2]
62
67
 
63
- feed.recent = '1hot'
64
- feed.records.remove_all
65
- items.each.with_index do |x, i|
66
-
67
- h = {title: x[:title], link: x[:link]}
68
+ if feed.records.length > 0 and \
69
+ items.first[:title] == feed.item[0].title then
70
+ feed.recent = recency(feed.last_modified)
71
+ next
72
+ end
68
73
 
69
- if i == 0 then
74
+ feed.recent = 'a_hot'
75
+ feed.records.remove_all
76
+ items.each.with_index do |x, i|
70
77
 
71
- raw_desc = CGI.unescapeHTML(x[:description]).gsub(/<\/?[^>]*>/, "")
72
- desc = raw_desc.length > 300 ? raw_desc[0..296] + ' ...' : raw_desc
73
- h[:description] = desc
74
- end
78
+ h = {title: x[:title], link: "%s#%s" % [filename.sub(/xml$/,'html'),i]}
75
79
 
76
- feed.create.item h
77
- end
80
+ if i == 0 then
78
81
 
79
- feed.last_modified = datetimestamp()
82
+ raw_desc = CGI.unescapeHTML(x[:description]).gsub(/<\/?[^>]*>/, "")
83
+ desc = raw_desc.length > 300 ? raw_desc[0..296] + ' ...' : raw_desc
84
+ h[:description] = desc
80
85
  end
86
+
87
+ feed.create.item h
81
88
  end
89
+
90
+ feed.last_modified = datetimestamp()
91
+
82
92
  end
83
93
  end
84
94
 
@@ -87,21 +97,14 @@ class PolyrexFeedReader
87
97
  def save_css(filepath='feeds.css')
88
98
 
89
99
  lib = File.dirname(__FILE__)
90
- #xsl_buffer = File.read(lib + '/feeds.css')
91
- css_buffer = File.read('feeds.css')
100
+ css_buffer = File.read(lib + '/feeds.css')
101
+ #css_buffer = File.read('feeds.css')
92
102
 
93
103
  File.write filepath, css_buffer
94
104
  end
95
105
 
96
106
  def save_html(filepath='feeds.html')
97
-
98
- lib = File.dirname(__FILE__)
99
- #xsl_buffer = File.read(lib + '/feeds.xsl')
100
- xsl_buffer = File.read('feeds.xsl')
101
-
102
- xslt = Nokogiri::XSLT(xsl_buffer)
103
- html = xslt.transform(Nokogiri::XML(@polyrex.to_xml)).to_s
104
- File.write filepath, html
107
+ xsltproc 'feeds.xsl', @polyrex.to_xml, filepath
105
108
  end
106
109
 
107
110
  def save_xml(filepath='feeds.xml')
@@ -118,6 +121,23 @@ class PolyrexFeedReader
118
121
  ordinal(day), month, year]
119
122
  end
120
123
 
124
+ def feeds()
125
+
126
+ @polyrex.records.each do |column|
127
+
128
+ column.records.each do |section|
129
+
130
+ section.records.each do |feed|
131
+
132
+ filename = "%s.xml" % feed.title.downcase.gsub(/\s/,'').gsub(/\W/,'_')
133
+ yield(feed, filename)
134
+
135
+ end
136
+ end
137
+ end
138
+
139
+ end
140
+
121
141
  def ordinal(i)
122
142
  i.to_s + ( (10...20).include?(i) ? 'th' :
123
143
  %w{ th st nd rd th th th th th th }[i % 10] )
@@ -127,15 +147,25 @@ class PolyrexFeedReader
127
147
  def recency(time)
128
148
 
129
149
  case (Time.now - Time.parse(time))
130
- when second(1)..minutes(5) then '1hot'
131
- when minutes(5)..hours(4) then '2warm'
132
- when hours(4)..week(1) then '3cold'
133
- when week(1)..month(1) then '4coldx1week'
134
- when month(1)..months(6) then '5coldx1month'
135
- else '6coldx6months'
150
+ when second(1)..minutes(5) then 'a_hot'
151
+ when minutes(5)..hours(4) then 'b_warm'
152
+ when hours(4)..week(1) then 'c_cold'
153
+ when week(1)..month(1) then 'd_coldx1week'
154
+ when month(1)..months(6) then 'e_coldx1month'
155
+ else 'f_coldx6months'
136
156
  end
137
157
  end
138
158
 
159
+ def xsltproc(xslfilename, xml, filepath='feeds.html')
160
+
161
+ lib = File.dirname(__FILE__)
162
+ xsl_buffer = File.read(lib + '/' + xslfilename)
163
+ #xsl_buffer = File.read(xslfilename)
164
+
165
+ xslt = Nokogiri::XSLT(xsl_buffer)
166
+ html = xslt.transform(Nokogiri::XML(xml)).to_s
167
+ File.write filepath, html
168
+ end
139
169
 
140
170
  def seconds(i) i end
141
171
  def minutes(i) i * MINUTE end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex-feed-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -29,7 +29,7 @@ cert_chain:
29
29
  LxhpHfLSRfOWDFimU0YGVs8dISSHOneULhblAYTTb7tvv2Zr8wG/bdlLhWuwoz23
30
30
  L5EDjzznPMmVNG60mdktue6PKdOEFp7N
31
31
  -----END CERTIFICATE-----
32
- date: 2013-12-08 00:00:00.000000000 Z
32
+ date: 2013-12-10 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: polyrex
@@ -82,6 +82,7 @@ files:
82
82
  - lib/polyrex-feed-reader.rb
83
83
  - lib/feeds.xsl
84
84
  - lib/feeds.css
85
+ - lib/dynarex-feed.xsl
85
86
  homepage: https://github.com/jrobertson/polyrex-feed-reader
86
87
  licenses:
87
88
  - MIT
metadata.gz.sig CHANGED
Binary file