rss_creator 0.4.0 → 0.5.1

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
  SHA256:
3
- metadata.gz: 647757a294410e98e341314c9f85c097059161320456321ff8472deb90c363d6
4
- data.tar.gz: 396951cc15ffcd5ae92790392a4ad139310acd35cdd2d7b1f59d0e15696a6bd2
3
+ metadata.gz: 1e9a19b111850395e005bf30f5988a3d9fa3e77b18e7ea64ecd946223f6b0132
4
+ data.tar.gz: b874598f45e34d85d949b1a6a86f13b43ea52a0db1ee5404fc6a94dbb2d27cdd
5
5
  SHA512:
6
- metadata.gz: 465c8405ef8d2f6ff853f418d35eaf4eb6d07f301f02664d31a59b41357a27486a49d5b159e8b941c69697b1464ec623dab641dcbcfd77612e704e9861565abd
7
- data.tar.gz: 2308016cbad0de11a04ccfdbb2bfa2e345ac440700fedb7cea0c1f9aeac1164fc152fd0569fa8f55a69db3e82c32ac3695be5e0f003cc867a56bb54422263ef2
6
+ metadata.gz: 620d7a274a083fdc661b1dc5aa11515ecb2c1d41373028e8e29cd12a7f8ba60da94f5e3a008e0f359e914647ed9918d534a76f53fed9fe6ec3256322d694002a
7
+ data.tar.gz: e6122e91ce400ed1ed538e1d18add56be3dad0d1674901d0b1773c157e37266a5663563ee13df9234e63de2d5b32f87f2147d911a9aa5facc20f58cfe54a6903
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/rss_creator.rb CHANGED
@@ -7,49 +7,53 @@ require 'rss_to_dynarex'
7
7
 
8
8
 
9
9
  class RSScreator
10
+ include RXFHelperModule
10
11
 
11
- attr_accessor :title, :description, :link, :limit, :xslt, :image_url,
12
+ attr_accessor :title, :description, :link, :limit, :xslt, :image_url,
12
13
  :image_target_url
13
14
 
14
- def initialize(filepath='rss.xml', dx_xslt: nil, dx_filename: 'feed.xml',
15
- custom_fields: [], limit: 10, debug: false)
15
+ def initialize(filepath='rss.xml', dx_xslt: nil, dx_filename: 'feed.xml',
16
+ custom_fields: [], limit: 10, log: nil, debug: false)
16
17
 
17
18
 
18
- @filepath, @debug = filepath, debug
19
+ @filepath, @log, @debug = filepath, log, debug
19
20
 
20
21
  dxfilepath = File.join(File.dirname(filepath), dx_filename)
21
-
22
- if filepath and File.exists? dxfilepath then
22
+
23
+ if filepath and FileX.exists? dxfilepath then
23
24
 
24
25
  @dx = Dynarex.new dxfilepath
25
26
  @title, @description, @link = @dx.title, @dx.description, @dx.link
27
+ @image_url = @dx.image
26
28
 
27
29
  else
28
- if filepath and File.exists? filepath
29
-
30
+ if filepath and FileX.exists? filepath
31
+
30
32
  rtd = RSStoDynarex.new filepath
31
33
  @dx = rtd.to_dynarex
32
34
 
33
35
  @title, @description, @link = @dx.title, @dx.description, @dx.link
34
-
36
+ @image_url = @dx.image if @dx.image and @dx.image.length > 1
37
+ @image_target_url = @link if @link and @link.length > 1
38
+
35
39
  else
36
40
 
37
-
38
- schema = 'channel[title, description, link]/' + \
41
+
42
+ schema = 'channel[title, description, link, image]/' + \
39
43
  'item(title, link, description, date'
40
44
  schema += ', ' + custom_fields.join(', ') if custom_fields.any?
41
45
  schema += ')'
42
-
46
+
43
47
  @dx = Dynarex.new schema
44
48
  end
45
49
 
46
- @dx.order = 'descending'
50
+ @dx.order = 'descending'
47
51
  @dx.default_key = 'uid'
48
- @dx.xslt = dx_xslt if dx_xslt
52
+ @dx.xslt = dx_xslt if dx_xslt
53
+
49
54
 
50
-
51
55
  end
52
-
56
+
53
57
  @dx.xslt_schema = 'channel[title:title,description:description,' + \
54
58
  'link:link]/item(title:title,description:description,' + \
55
59
  'link:link,pubDate:date)'
@@ -62,31 +66,33 @@ class RSScreator
62
66
 
63
67
  end
64
68
 
65
- def add(item: {title: '', link: '', description: ''}, id: nil)
69
+ def add(itemx={title: '', link: '', description: ''}, item: itemx, id: nil)
70
+
71
+ @log.debug 'RssCreator#add item: ' + item.inspect if @log
66
72
 
67
73
  unless item[:title] and item[:link] then
68
- raise 'RSScreator: title or link can\'t be blank'
74
+ raise 'RSScreator: title or link can\'t be blank'
69
75
  end
70
-
76
+
71
77
  record = {date: Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")}.merge(item)
72
78
  @dx.create(record, id: id)
73
-
79
+
74
80
  @dirty = true
75
-
81
+
76
82
  end
77
83
 
78
84
  def save(new_filepath=nil)
79
85
 
80
86
  filepath = new_filepath ? new_filepath : @filepath
81
- File.write filepath, print_rss
87
+ FileX.write filepath, print_rss
82
88
  @dx.save File.join(File.dirname(filepath), @dxfilename) if @dxfilename
83
89
  end
84
-
90
+
85
91
  def description=(val)
86
92
  @description = val
87
93
  @dirty = true
88
94
  end
89
-
95
+
90
96
  def delete(id)
91
97
  @dx.delete id.to_s
92
98
  end
@@ -97,24 +103,24 @@ class RSScreator
97
103
  def dynarex()
98
104
  @dx
99
105
  end
100
-
106
+
101
107
  def image_url=(val)
102
108
  @image_url = val
103
109
  @dirty = true
104
110
  end
105
-
111
+
106
112
  alias image= image_url=
107
-
113
+
108
114
  def image_target_url=(val)
109
115
  @image_target_url = val
110
116
  @dirty = true
111
- end
117
+ end
112
118
 
113
119
  def link=(val)
114
120
  @link = val
115
121
  @dirty = true
116
- end
117
-
122
+ end
123
+
118
124
  def title=(val)
119
125
  @title = val
120
126
  @dirty = true
@@ -127,42 +133,43 @@ class RSScreator
127
133
  private
128
134
 
129
135
  def print_rss()
130
-
136
+
131
137
  return @rss unless @dirty
132
138
 
133
139
  if @title.nil? or @description.nil? then
134
- raise 'RSScreator: title or description can\'t be blank'
140
+ raise 'RSScreator: title or description can\'t be blank'
135
141
  end
136
142
 
137
143
  @dx.title, @dx.description, @dx.link = @title, @description, @link || ''
138
-
144
+ @dx.image = @image_url if @dx.respond_to? :image
145
+
139
146
  @rss = if @xslt then
140
-
147
+
141
148
  @dx.to_rss({limit: @limit}) do |doc|
142
-
149
+
143
150
  doc.instructions << ['xml-stylesheet',\
144
151
  "title='XSL_formatting' type='text/xsl' href='#{@xslt}'"]
145
-
146
- end
147
-
152
+
153
+ end
154
+
148
155
  else
149
-
156
+
150
157
  @dx.to_rss({limit: @limit}) do |doc|
151
-
158
+
152
159
  if @image_url then
153
-
160
+
154
161
  img = Rexle::Element.new('image')
155
162
  img.add Rexle::Element.new('url').add_text @image_url
156
163
  img.add Rexle::Element.new('link').add_text @image_target_url
157
-
164
+
158
165
  doc.root.element('channel/item').insert_before img
159
-
160
- end
161
-
166
+
167
+ end
168
+
162
169
  end
163
-
170
+
164
171
  end
165
-
172
+
166
173
  @dirty = false
167
174
  @rss
168
175
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss_creator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  CmoNNvIZ3zS4vUkMoFR7S0bXN/xdxzLVn5uGLJ8FwP76BqKlR2+xV5Bj+40hyMDP
36
36
  s+qwrtoA3kBtGhpVjCn/TE5q
37
37
  -----END CERTIFICATE-----
38
- date: 2021-02-24 00:00:00.000000000 Z
38
+ date: 2022-01-19 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rss_to_dynarex
metadata.gz.sig CHANGED
Binary file