daily_notices 0.2.5 → 0.2.6

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: 75034a8aa3252cd59b321633226576d61ee6a93d
4
- data.tar.gz: 4965100aa48581d31c295024c5d5ffe006931f73
3
+ metadata.gz: 353e3bdad29518178624bf3ea0b24418e0d2959f
4
+ data.tar.gz: 159c643c037d2e894d48fb6970df4405a9187fc6
5
5
  SHA512:
6
- metadata.gz: 2f1cea284a304832ae95965ef756b449566f3b7831c56ba39f7eef545a356ff3b5339755318db0618c15270c11268b64c6cc6edfe24ed75a0b2f603781515764
7
- data.tar.gz: 23712e25ce1a7b666b25a78f07067d6efc655b0f61efeba0a46613bfcd8fb673af308bca2853aefda3a1c0cd12e9d5d2ae6829bfabff3fd2f0a521269cbeec28
6
+ metadata.gz: 0a34945600ffb313350ccb98d473ecac2df4c47bf2dc93e095f0b70ef22eb0d7608a2e4f1bf1d0dbc1a816990e7cf2910b7a13ca772c5cf62eac10202e5296c9
7
+ data.tar.gz: 8b035e7400edb371f7627bd9c56f05a95021978a9a3e7da0fa998981e6778080dff9713cd81c629ea172e1d9e569eeeb287fa736b9449c7e37ac41878c2d81f6
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/daily_notices.rb CHANGED
@@ -12,29 +12,13 @@ class DailyNotices
12
12
  attr_accessor :title, :description, :link, :dx_xslt, :rss_xslt
13
13
 
14
14
  def initialize(filepath='', url_base: 'http:/127.0.0.1/', \
15
- dx_xslt: '', rss_xslt: '')
15
+ dx_xslt: '', rss_xslt: '', target_page: :recordset, target_xslt: '')
16
16
 
17
- @filepath, @url_base, @dx_xslt, @rss_xslt = filepath, \
18
- url_base, dx_xslt, rss_xslt
19
-
20
- @archive_path = Time.now.strftime("%Y/%b/%d").downcase
21
-
22
- # If the file doesn't already exist in the
23
- # archive directory then symlink it
24
- @indexpath = File.join(@filepath, @archive_path, 'index.xml')
25
- FileUtils.mkdir_p File.dirname(@indexpath)
26
-
27
- @schema = 'items/item(description, time)'
28
- @default_key = 'uid'
29
-
30
- if File.exists? @indexpath then
31
- @dx = Dynarex.new @indexpath
32
- else
33
- @dx = Dynarex.new @schema
34
- @dx.order = 'descending'
35
- @dx.default_key = @default_key
36
- @dx.xslt = @dx_xslt
37
- end
17
+ @filepath, @url_base, @dx_xslt, @rss_xslt, @target_page, @target_xslt = \
18
+ filepath, url_base, dx_xslt, rss_xslt, target_page, target_xslt
19
+
20
+ @day = Time.now.day
21
+ new_day()
38
22
 
39
23
  # open the Dynarex file or create a new Dynarex file
40
24
 
@@ -50,15 +34,25 @@ class DailyNotices
50
34
  @rss.link = @url_base
51
35
  end
52
36
 
37
+ # :recordset or : record
38
+ @target_page = target_page
53
39
  end
54
40
 
55
41
  def create(description, time=Time.now, title: nil, \
56
42
  id: Time.now.strftime('%H%M%S'))
57
43
 
44
+ new_day() if @day != Time.now.day
45
+
58
46
  @dx.create({description: description, time: time}, id: id)
59
47
  @dx.save @indexpath
60
- File.write File.join(@filepath, @archive_path, 'index.html'), \
61
- @dx.to_html(domain: @url_base)
48
+
49
+ if @target_page == :recordset then
50
+ File.write File.join(@filepath, @archive_path, 'index.html'), \
51
+ @dx.to_html(domain: @url_base)
52
+ else
53
+ File.write File.join(@filepath, @archive_path, id, 'index.html'), \
54
+ @dx.find(id).to_html(xslt: @target_xslt)
55
+ end
62
56
 
63
57
  # Add it to the RSS document
64
58
  title ||= description.split(/\n/,2).first[0..140]
@@ -66,6 +60,8 @@ class DailyNotices
66
60
  @archive_path, '#' + id)].join('/')
67
61
  @rss.add( {title: title, link: link, description: description}, id: id)
68
62
  @rss.save @rssfile
63
+
64
+ on_add(@indexpath, id)
69
65
 
70
66
 
71
67
  end
@@ -96,4 +92,36 @@ class DailyNotices
96
92
  @rss.description = val
97
93
  end
98
94
 
95
+ # If you wish override this method or use it in block form to add a
96
+ # notifier, callback routine or webhook, whenever a new record is added.
97
+ #
98
+ def on_add(xmlpath, id)
99
+
100
+ yield(xmlpath, id) if block_given?
101
+
102
+ end
103
+
104
+ private
105
+
106
+ def new_day()
107
+
108
+ @archive_path = Time.now.strftime("%Y/%b/%d").downcase
109
+
110
+ @indexpath = File.join(@filepath, @archive_path, 'index.xml')
111
+ FileUtils.mkdir_p File.dirname(@indexpath)
112
+
113
+ schema = 'items/item(description, time)'
114
+ default_key = 'uid'
115
+
116
+ if File.exists? @indexpath then
117
+ @dx = Dynarex.new @indexpath
118
+ else
119
+ @dx = Dynarex.new schema
120
+ @dx.order = 'descending'
121
+ @dx.default_key = default_key
122
+ @dx.xslt = @dx_xslt
123
+ end
124
+
125
+ end
126
+
99
127
  end
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  6KZopP6uiDZcPfIWtD5QSbhxe2cyGqlu4Xnb4imiAb9DWj8g5YP45vWTp1a71ytC
32
32
  TGdJpNvN31W5+w==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-10-29 00:00:00.000000000 Z
34
+ date: 2015-10-30 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rss_creator
metadata.gz.sig CHANGED
Binary file