daily_notices 0.7.1 → 0.7.2

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