daily_notices 0.7.1 → 0.8.0

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
  SHA256:
3
- metadata.gz: 9d29cfb2e116756c7657e573834d48753642668d988d8f1445f2d557e05225e6
4
- data.tar.gz: 105253e156c300d52f96f7f4a37714927e32b3c38ae19872102c738fab069f42
3
+ metadata.gz: a93fc95ef818bf423cff6739c54fc21e2209be3d502e2074c7099edc21944334
4
+ data.tar.gz: f5424396c72252e53689f70a590a82b08cdab56eb88d71562e3425c9a1974fbe
5
5
  SHA512:
6
- metadata.gz: b67265385e875a1e06298a942184287493117e490390e8e562769e7dcc9055b2362bf7a957e80e1763c75aa01aa89c00bdb20816ffd6913d940b6f5f227741de
7
- data.tar.gz: a97e40f82b5b09ecca4d821e40f1d2e422007087548f4ea96c7a9874204aed7ff8488f75294cdd8fde477db67ea765f789354e7f959ba8611ece4818a0bf4a12
6
+ metadata.gz: b3446e333d86c3fb26100a208c6820a3436f9ea2a08e1ed96e0b6513d80086a6faa1d90fd1dfd8b8c303c8dcfd8b279cd1fb2342c7972d94ffdc351542373fbe
7
+ data.tar.gz: 92bb88b4aef1af8c5e32663bc8bc0d5fc56eba096c004dd3221ec5b549f4a1a054c2b95bab4d2d0c4efb576e99ed74a6b8f025685c4214ab860b7c9d01a19d4b
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/daily_notices.rb CHANGED
@@ -5,43 +5,44 @@
5
5
 
6
6
  require 'dx_sliml'
7
7
  require 'rx_sliml'
8
- require 'fileutils'
9
8
  require 'rss_creator'
9
+ require 'rxfreadwrite'
10
10
 
11
11
 
12
12
  class DailyNotices
13
-
13
+ include RXFReadWriteModule
14
+
14
15
  attr_accessor :title, :description, :link, :dx_xslt, :rss_xslt
15
16
 
16
- def initialize(filepath='', url_base: 'http:/127.0.0.1/', identifier: '',
17
- dx_xslt: '', rss_xslt: '', target_page: :recordset,
18
- target_xslt: '', title: 'daily notices', log: nil,
17
+ def initialize(filepath='', url_base: 'http:/127.0.0.1/', identifier: '',
18
+ dx_xslt: '', rss_xslt: '', target_page: :recordset,
19
+ target_xslt: '', title: 'daily notices', log: nil,
19
20
  debug: false)
20
-
21
+
21
22
  @filepath, @url_base, @dx_xslt, @rss_xslt, @target_page, @target_xslt, \
22
23
  @identifier, @log, @debug = filepath, url_base, dx_xslt, rss_xslt, \
23
24
  target_page, target_xslt, identifier, log, debug
24
25
 
25
-
26
+
26
27
  # note: card is intended for storing meta data in JSON format
27
-
28
- @schema ||= 'items[title, identifier, image]/item(title, description, ' +
29
- 'card, time, link)'
30
- @default_key ||= 'uid'
31
-
28
+
29
+ @schema = 'items[title, identifier, image, bio, location, website,' +
30
+ ' banner_image]/item(title, description, card, time, link)'
31
+ @default_key = 'uid'
32
+
32
33
  if dx_xslt.nil? then
33
34
 
34
35
  subdir = File.basename filepath
35
36
  dir = url_base[/http:\/\/[^\/]+\/(.*)/,1]
36
37
 
37
38
  dxxsltfilename = "dx#{Time.now.to_i.to_s}.xsl"
38
- dxxsltfilepath = '/' + [dir, subdir, dxxsltfilename].join('/')
39
- File.write File.join(filepath, dxxsltfilename), \
39
+ dxxsltfilepath = '/' + [dir, subdir, dxxsltfilename].join('/')
40
+ FileX.write File.join(filepath, dxxsltfilename), \
40
41
  DxSliml.new(dx: @schema).to_xslt
41
-
42
+
42
43
  @dx_xslt = dxxsltfilepath
43
44
  end
44
-
45
+
45
46
  if rss_xslt.nil? then
46
47
 
47
48
  subdir = File.basename filepath
@@ -49,97 +50,124 @@ class DailyNotices
49
50
 
50
51
  rssxsltfilename = "rssx#{Time.now.to_i.to_s}.xsl"
51
52
  rssxsltfilepath = '/' + [dir, subdir, rssxsltfilename].join('/')
52
- File.write File.join(filepath, rssxsltfilename), \
53
+ FileX.write File.join(filepath, rssxsltfilename), \
53
54
  RssSliml.new().to_xslt
54
-
55
+
55
56
  @rss_xslt = rssxsltfilepath
56
- end
57
-
57
+ end
58
+
58
59
  @day = Time.now.day
59
60
  @title = title
60
61
  new_day()
61
-
62
+
62
63
  # open the Dynarex file or create a new Dynarex file
63
64
 
64
65
  @rssfile = File.join(@filepath, 'rss.xml')
65
66
 
66
- if File.exists? @rssfile then
67
- @rss = RSScreator.new @rssfile, dx_xslt: @rss_xslt,
68
- custom_fields: ['topic']
67
+ if FileX.exists? @rssfile then
68
+ @rss = RSScreator.new @rssfile, dx_xslt: @rss_xslt,
69
+ custom_fields: ['topic'], log: @log
69
70
  else
70
71
 
71
- @rss = RSScreator.new @rssfile, dx_xslt: @rss_xslt,
72
- custom_fields: ['topic']
72
+ @rss = RSScreator.new @rssfile, dx_xslt: @rss_xslt,
73
+ custom_fields: ['topic'], log: @log
74
+
73
75
  @rss.xslt = @rss_xslt
74
76
  @rss.title = @title || identifier.capitalize + ' daily notices'
75
77
  @rss.description = 'Generated using the daily_notices gem'
76
78
  @rss.link = @url_base
77
- end
78
-
79
+ end
80
+
79
81
  # :recordset or : record
80
82
  @target_page = target_page
81
83
  end
82
-
83
- def create(id: Time.now.to_i.to_s,
84
- item: {time: Time.now.strftime('%H:%M %p - %d %b %Y'), title: nil})
84
+
85
+ def create(id: Time.now.to_i.to_s,
86
+ item: {time: Time.now.strftime('%H:%M %p - %d %b %Y'),
87
+ title: nil})
85
88
 
86
89
  @log.info 'daily_notices/create: item: ' + item.inspect if @log
87
90
  h = item
88
91
 
89
92
  new_day() if @day != Time.now.day
90
93
 
91
- if @dx.all.any? and
94
+ if @dx.all.any? and
92
95
  @dx.all.first.description == CGI.unescape(h[:description].to_s) then
93
96
 
94
97
  return :duplicate
95
98
 
96
99
  end
97
100
 
98
- h[:link] ||= create_link(id)
101
+ h[:link] ||= create_link(id)
99
102
  h[:title] ||= h[:description]
100
103
  .split(/\n/,2).first.gsub(/\<\/?\w+[^>]*>/,'')[0..140]
101
- h[:time] ||= Time.now.strftime('%H:%M %p · %b %d %Y')
104
+ h[:time] ||= Time.now.strftime('%H:%M %p · %b %d %Y')
105
+
102
106
 
103
107
  #@dx.create({description: description, time: time}, id: id)
104
108
  puts 'before @dx.create' if @debug
105
- @dx.create(h, id: id)
106
- puts 'after @dx.create' if @debug
109
+ @log.info 'daily_notices/create: before' if @log
110
+
111
+ # deep clone the Hash object
112
+ h3 = Marshal.load( Marshal.dump(h) )
113
+ h[:card] = h[:card].to_json if h[:card] and h[:card].is_a? Hash
114
+
115
+ @dx.create(h, id: id)
116
+ @log.info 'daily_notices/create: after' if @log
117
+ #puts 'after @dx.create' if @debug
118
+
107
119
  @dx.save @indexpath
108
-
120
+
109
121
  render_html_files(id)
110
122
 
111
123
  # Add it to the RSS document
112
124
 
113
-
114
- @rss.add(item: h, id: id)
125
+ if h3[:card] and h3[:card].is_a? Hash then
126
+
127
+ card = h3[:card]
128
+ h2 = card[card.keys.first]
129
+
130
+ content = case card.keys.first
131
+ when :summary_large_image
132
+ "\n<h1>%s</h1><p>%s</p>" % [h2[:title], h2[:desc]]
133
+ end
134
+
135
+ h3[:title] += h2[:title] if h3[:title].empty?
136
+ h3[:description] += content
137
+
138
+ end
139
+
140
+ @log.debug 'daily_notices/create: h3: ' + h3.inspect if @log
141
+ @rss.add(item: h3, id: id)
115
142
  @rss.save @rssfile
116
-
143
+ # open up the RSS file and fill in the title and description fields
144
+
117
145
  on_add(@indexpath, id)
118
-
146
+
119
147
  return true
120
148
 
121
149
  end
122
-
150
+
123
151
  alias add create
124
-
125
-
152
+
153
+
126
154
  def delete(id)
127
-
155
+
128
156
  [@dx, @rss].each {|x| x.delete(id.to_s); x.save}
129
157
 
130
158
  archive_path = Time.at(id.to_i).strftime("%Y/%b/%-d").downcase
131
- indexpath = File.join(@filepath, archive_path, id.to_s)
159
+ indexpath = File.join(@filepath, archive_path, id.to_s)
160
+
161
+ FileX.rm_rf indexpath
132
162
 
133
- FileUtils.rm_rf indexpath
134
-
135
163
  id.to_s + ' deleted'
136
-
164
+
137
165
  end
138
-
166
+
139
167
  def description()
140
168
  @rss.description
141
169
  end
142
-
170
+
143
171
  def description=(val)
144
172
  @rss.description = val
145
173
  end
@@ -148,64 +176,64 @@ class DailyNotices
148
176
  image_url, target_url = val.split
149
177
  @rss.image_url = image_url
150
178
  @rss.image_target_url = target_url
151
- end
152
-
179
+ end
180
+
153
181
  def title()
154
182
  @rss.title
155
183
  end
156
-
184
+
157
185
  def title=(val)
158
186
  @rss.title = val
159
187
  end
160
-
188
+
161
189
  def link()
162
190
  @rss.link
163
191
  end
164
-
192
+
165
193
  def link=(val)
166
194
  @rss.link = val
167
195
  end
168
196
 
169
-
170
- # If you wish override this method or use it in block form to add a
197
+
198
+ # If you wish override this method or use it in block form to add a
171
199
  # notifier, callback routine or webhook, whenever a new record is added.
172
200
  #
173
201
  def on_add(xmlpath, id)
174
-
202
+
175
203
  yield(xmlpath, id) if block_given?
176
-
177
- end
178
-
204
+
205
+ end
206
+
179
207
  def save()
180
- @rss.save @rssfile
208
+ @rss.save @rssfile
181
209
  end
182
-
210
+
183
211
  def to_dx()
184
212
  Dynarex.new @dx.to_xml
185
213
  end
186
-
187
- private
188
-
214
+
215
+ private
216
+
189
217
  def create_link(id)
190
218
  [File.join(@url_base, File.basename(@filepath), 'status', id)].join('/')
191
219
  end
192
-
220
+
193
221
  # configures the target page (using a Dynarex document) for a new day
194
222
  #
195
223
  def new_day()
196
-
224
+
197
225
  puts 'inside new_day' if @debug
198
-
226
+
199
227
  @archive_path = Time.now.strftime("%Y/%b/%-d").downcase
200
-
228
+
201
229
  @indexpath = File.join(@filepath, @archive_path, 'index.xml')
202
- FileUtils.mkdir_p File.dirname(@indexpath)
203
-
204
-
205
- if File.exists? @indexpath then
230
+ FileX.mkdir_p File.dirname(@indexpath)
231
+
232
+
233
+ if FileX.exists? @indexpath then
206
234
  @dx = Dynarex.new @indexpath
207
235
  else
208
-
236
+
209
237
  puts 'creating a new dx file' if @debug
210
238
  @dx = Dynarex.new @schema, debug: @debug
211
239
  @dx.order = 'descending'
@@ -213,48 +241,48 @@ class DailyNotices
213
241
  @dx.xslt = @dx_xslt
214
242
  @dx.title = @title
215
243
  @dx.identifier = @identifier
216
- end
217
-
244
+ end
245
+
218
246
  end
219
-
247
+
220
248
  def render_html_files(id)
221
-
249
+
222
250
  puts 'inside render_html_files' if @debug
223
-
251
+
224
252
  if @target_page == :recordset then
225
- File.write File.join(@filepath, @archive_path, 'index.html'), \
253
+ FileX.write File.join(@filepath, @archive_path, 'index.html'), \
226
254
  @dx.to_html(domain: @url_base)
227
255
  else
228
256
 
229
257
  target_path = File.join(@filepath, @archive_path, id, 'index.html')
230
- FileUtils.mkdir_p File.dirname(target_path)
258
+ FileX.mkdir_p File.dirname(target_path)
231
259
 
232
260
  rx = @dx.find(id)
233
261
 
234
262
  puts 'rx: ' + rx.inspect if @debug
235
263
  kvx = rx.to_kvx
236
-
237
- yield kvx if block_given?
264
+
265
+ yield kvx if block_given?
238
266
  puts 'before kvx.to_xml' if @debug
239
267
  puts 'kvx.to_xml : ' + kvx.to_xml.inspect
240
268
  puts 'before 2 kvx.to_xml' if @debug
241
269
  rxdoc = Rexle.new(kvx.to_xml)
242
270
  puts 'after kvx.to_xml' if @debug
243
-
271
+
244
272
  rxdoc.instructions << ['xml-styelsheet',\
245
273
  "title='XSL_formatting' type='text/xsl' href='#{@target_xslt}'"]
246
- File.write target_path.sub(/\.html$/,'.xml', ), rxdoc.xml(pretty: true)
247
-
248
- unless File.exists? @target_xslt then
274
+ FileX.write target_path.sub(/\.html$/,'.xml', ), rxdoc.xml(pretty: true)
249
275
 
250
- File.write @target_xslt,
276
+ unless FileX.exists? @target_xslt then
277
+
278
+ FileX.write @target_xslt,
251
279
  RxSliml.new(fields: %i(description time)).to_xslt
252
280
  end
253
-
254
- File.write target_path, rx.to_html(xslt: @target_xslt)
255
281
 
256
- end
282
+ FileX.write target_path, rx.to_html(xslt: @target_xslt)
283
+
284
+ end
257
285
 
258
286
  end
259
-
287
+
260
288
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily_notices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  mq989lGt58a/Y5CLIB7CrHXwKhKPrMrl9wrNJQaGhmKCpC48MvGPzmGUKYO3OTRK
36
36
  QCT4F3Esm7/YTYtL3CQJWI1T
37
37
  -----END CERTIFICATE-----
38
- date: 2021-03-19 00:00:00.000000000 Z
38
+ date: 2022-02-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rss_creator
@@ -43,20 +43,20 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.4'
46
+ version: '0.6'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.4.2
49
+ version: 0.6.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.4'
56
+ version: '0.6'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.4.2
59
+ version: 0.6.0
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: dx_sliml
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -101,22 +101,22 @@ dependencies:
101
101
  name: rss_sliml
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 0.2.0
107
104
  - - "~>"
108
105
  - !ruby/object:Gem::Version
109
106
  version: '0.2'
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: 0.2.0
117
114
  - - "~>"
118
115
  - !ruby/object:Gem::Version
119
116
  version: '0.2'
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 0.2.0
120
120
  description:
121
121
  email: digital.robertson@gmail.com
122
122
  executables: []
@@ -143,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.7.10
146
+ rubygems_version: 3.2.22
148
147
  signing_key:
149
148
  specification_version: 4
150
149
  summary: A public facing noticeboard which is centered around an RSS feed.
metadata.gz.sig CHANGED
Binary file