polyrex-calendar 0.1.22 → 0.1.23
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/kplanner.xsl +0 -0
- data/lib/kplanner_month.xsl +0 -0
- data/lib/monthday.css +0 -0
- data/lib/monthday_layout.css +0 -0
- data/lib/polyrex-calendar.rb +185 -58
- data.tar.gz.sig +0 -0
- metadata +6 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 812128340cca8d02db68ea71ed8b86c8d062f83c
|
4
|
+
data.tar.gz: e87ce48043da7284605ce595fbb2041fc95b1dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63d5e56bfb6655e376095d4d7aa7b0424926817e7d992e499dfdae27c9103bc956114f2770ee9af4bf27b3e428930bcac77dcd1993e00752775b13d9639f4f6
|
7
|
+
data.tar.gz: 4e006ce2307af7f5fe91d0d35e8e651739ce1a58f6e5c8f77ddbea250f6ae456a609a9b3d19db47b84bd47613f8f62bd1df98d6e76d6f0a1f87384c5aabbb267
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/kplanner.xsl
ADDED
File without changes
|
File without changes
|
data/lib/monthday.css
ADDED
File without changes
|
File without changes
|
data/lib/polyrex-calendar.rb
CHANGED
@@ -13,25 +13,41 @@ DAY = HOUR * 24
|
|
13
13
|
WEEK = DAY * 7
|
14
14
|
MONTH = DAY * 30
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
module LIBRARY
|
18
|
+
|
19
|
+
def fetch_file(filename)
|
20
|
+
#lib = File.dirname(__FILE__)
|
21
|
+
#File.read filename
|
22
|
+
lib = 'http://rorbuilder.info/r/ruby/polyrex-calendar'
|
23
|
+
open(File.join(lib, filename),
|
24
|
+
'UserAgent' => 'PolyrexCalendar'){|x| x.read }
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_webpage(xml, xsl)
|
28
|
+
|
29
|
+
# transform the xml to html
|
30
|
+
doc = Nokogiri::XML(xml)
|
31
|
+
xslt = Nokogiri::XSLT(xsl)
|
32
|
+
xslt.transform(doc).to_s
|
19
33
|
end
|
20
|
-
end
|
34
|
+
end
|
21
35
|
|
22
36
|
class PolyrexCalendar
|
37
|
+
include LIBRARY
|
23
38
|
|
24
39
|
attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
|
25
40
|
attr_reader :day
|
26
|
-
|
41
|
+
|
27
42
|
def initialize(calendar_file=nil, options={})
|
28
43
|
|
29
|
-
|
30
|
-
|
31
|
-
}.merge(options)
|
32
|
-
year = opts[:year]
|
33
|
-
@year = year ? year.to_s : Time.now.year.to_s
|
44
|
+
opts = {year: Time.now.year.to_s}.merge(options)
|
45
|
+
@year = opts[:year]
|
34
46
|
|
47
|
+
@schema = 'calendar[year]/month[no,title,year]/' + \
|
48
|
+
'week[no, rel_no, mon, label]/day[wday, xday, title, event, date, ' + \
|
49
|
+
'ordinal, overlap, bankholiday]/' + \
|
50
|
+
'entry[time_start, time_end, duration, title]'
|
35
51
|
|
36
52
|
if calendar_file then
|
37
53
|
@polyrex = Polyrex.new calendar_file
|
@@ -49,23 +65,52 @@ class PolyrexCalendar
|
|
49
65
|
else
|
50
66
|
@id = '1'
|
51
67
|
generate_calendar
|
52
|
-
end
|
68
|
+
end
|
69
|
+
|
70
|
+
@xsl = fetch_file 'calendar.xsl'
|
71
|
+
@css = fetch_file 'layout.css'
|
72
|
+
|
73
|
+
Polyrex.class_eval do
|
74
|
+
include LIBRARY
|
75
|
+
|
76
|
+
attr_accessor :xslt, :css_layout, :css_style, :filename
|
77
|
+
|
78
|
+
def inspect()
|
79
|
+
"#<Polyrex:%s" % __id__
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_webpage()
|
83
|
+
|
84
|
+
year_xsl = fetch_file self.xslt
|
85
|
+
year_layout_css = fetch_file self.css_layout
|
86
|
+
year_css = fetch_file self.css_style
|
87
|
+
|
88
|
+
File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
|
89
|
+
File.open(self.xslt,'w'){|f| f.write year_xsl }
|
90
|
+
#html = Rexslt.new(month_xsl, self.to_xml).to_xml
|
91
|
+
|
92
|
+
html = generate_webpage self.to_xml, year_xsl
|
93
|
+
{self.filename => html,
|
94
|
+
self.css_layout => year_layout_css, self.css_style => year_css}
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
53
99
|
|
54
|
-
@xsl = File.read lib + '/calendar.xsl'
|
55
|
-
@css = File.read lib + '/layout.css'
|
56
|
-
|
57
100
|
PolyrexObjects::Month.class_eval do
|
101
|
+
include LIBRARY
|
102
|
+
|
103
|
+
attr_accessor :xslt, :css_layout, :css_style
|
58
104
|
|
59
105
|
def inspect()
|
60
106
|
"#<PolyrexObjects::Month:%s" % __id__
|
61
107
|
end
|
62
108
|
|
63
109
|
def to_webpage()
|
64
|
-
lib = File.dirname(__FILE__)
|
65
110
|
|
66
|
-
month_xsl
|
67
|
-
month_layout_css =
|
68
|
-
month_css
|
111
|
+
month_xsl = fetch_file self.xslt
|
112
|
+
month_layout_css = fetch_file self.css_layout
|
113
|
+
month_css = fetch_file self.css_style
|
69
114
|
|
70
115
|
File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
|
71
116
|
File.open('month.xsl','w'){|f| f.write month_xsl }
|
@@ -77,11 +122,9 @@ class PolyrexCalendar
|
|
77
122
|
e = doc.root.element("records/week/records/day/summary[date='#{date}']")
|
78
123
|
e.add Rexle::Element.new('css_style').add_text('selected')
|
79
124
|
|
80
|
-
|
81
|
-
html = xslt.transform(Nokogiri::XML(doc.xml)).to_s
|
125
|
+
html = generate_webpage doc.xml, month_xsl
|
82
126
|
{self.title.downcase[0..2] + '_calendar.html' => html,
|
83
|
-
|
84
|
-
|
127
|
+
self.css_layout => month_layout_css, self.css_style => month_css}
|
85
128
|
end
|
86
129
|
|
87
130
|
def wk(n)
|
@@ -90,33 +133,31 @@ class PolyrexCalendar
|
|
90
133
|
end
|
91
134
|
|
92
135
|
PolyrexObjects::Week.class_eval do
|
136
|
+
include LIBRARY
|
93
137
|
|
94
138
|
def inspect()
|
95
139
|
"#<PolyrexObjects::Week:%s" % __id__
|
96
140
|
end
|
97
141
|
|
98
142
|
def to_webpage()
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
week_css = File.read lib + '/week.css'
|
105
|
-
|
143
|
+
|
144
|
+
week_xsl = fetch_file 'week_calendar.xsl'
|
145
|
+
week_layout_css = fetch_file 'week_layout.css'
|
146
|
+
week_css = fetch_file 'week.css'
|
147
|
+
|
106
148
|
File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
|
107
149
|
File.open('week.xsl','w'){|f| f.write week_xsl }
|
108
150
|
#html = Rexslt.new(week_xsl, self.to_xml).to_xml
|
109
151
|
#html = xsltproc 'week_calendar.xsl', self.to_xml
|
110
|
-
|
152
|
+
|
111
153
|
# add a css selector for the current day
|
112
154
|
date = Time.now.strftime("%Y-%b-%d")
|
113
155
|
doc = Rexle.new self.to_xml
|
114
156
|
e = doc.root.element("records/day/summary[date='#{date}']")
|
115
157
|
|
116
|
-
e.add Rexle::Element.new('css_style').add_text('selected')
|
117
|
-
|
118
|
-
html =
|
119
|
-
|
158
|
+
e.add Rexle::Element.new('css_style').add_text('selected')
|
159
|
+
|
160
|
+
html = generate_webpage doc.xml, week_xsl
|
120
161
|
{'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
|
121
162
|
'week.css' => week_css}
|
122
163
|
end
|
@@ -133,13 +174,6 @@ class PolyrexCalendar
|
|
133
174
|
@polyrex.to_xml pretty: true
|
134
175
|
end
|
135
176
|
|
136
|
-
def to_webpage()
|
137
|
-
# jr2441213 html = Rexslt.new(@xsl, @polyrex.to_xml).to_xml
|
138
|
-
xslt = Nokogiri::XSLT(@xsl)
|
139
|
-
html = xslt.transform(Nokogiri::XML(@polyrex.to_xml)).to_s
|
140
|
-
{'calendar.html' => html, 'layout.css' => @css}
|
141
|
-
end
|
142
|
-
|
143
177
|
def import_events(objx)
|
144
178
|
@id = @polyrex.id_counter
|
145
179
|
method('import_'.+(objx.class.to_s.downcase).to_sym).call(objx)
|
@@ -152,8 +186,91 @@ class PolyrexCalendar
|
|
152
186
|
%Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">)
|
153
187
|
end
|
154
188
|
|
155
|
-
def
|
156
|
-
|
189
|
+
def kitchen_planner()
|
190
|
+
|
191
|
+
px = Polyrex.new(@schema, id_counter: @id)
|
192
|
+
px.summary.year = @year
|
193
|
+
(1..12).each {|n| px.add self.month(n, strict: true) }
|
194
|
+
|
195
|
+
px.xslt = 'kplanner.xsl'
|
196
|
+
px.css_layout = 'monthday_layout.css'
|
197
|
+
px.css_style = 'monthday.css'
|
198
|
+
px.filename = summary.year.to_s + '-kitchen-planner.html'
|
199
|
+
|
200
|
+
px
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
def year_planner()
|
205
|
+
|
206
|
+
px = Polyrex.new(@schema, id_counter: @id)
|
207
|
+
px.summary.year = @year
|
208
|
+
(1..12).each {|n| px.add self.month(n, strict: true) }
|
209
|
+
|
210
|
+
px.xslt = 'calendar.xsl'
|
211
|
+
px.css_layout = 'layout.css'
|
212
|
+
px.css_style = 'year.css'
|
213
|
+
px.filename = px.summary.year.to_s + '-planner.html'
|
214
|
+
|
215
|
+
px
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
def month(m, strict: false)
|
220
|
+
|
221
|
+
cal_month = @polyrex.records[m-1]
|
222
|
+
|
223
|
+
if strict == true then
|
224
|
+
|
225
|
+
days_in_month = cal_month.xpath('records/week/records/.')\
|
226
|
+
.select {|x| Date.parse(x.text('summary/date')).month == m}
|
227
|
+
|
228
|
+
doc_month = Rexle.new cal_month.to_xml
|
229
|
+
records = doc_month.root.element 'records'
|
230
|
+
records.insert_before Rexle::Element.new('records')
|
231
|
+
|
232
|
+
records.delete
|
233
|
+
|
234
|
+
h = PolyrexObjects.new(@schema).to_h
|
235
|
+
pxmonth = h['Month'].new doc_month.root
|
236
|
+
|
237
|
+
a = days_in_month
|
238
|
+
i = a[0].text('summary/wday').to_i
|
239
|
+
|
240
|
+
a2 = if i > 1 then
|
241
|
+
Array.new(i - 1) + a
|
242
|
+
elsif i < 1 then
|
243
|
+
Array.new(6) + a
|
244
|
+
else
|
245
|
+
a
|
246
|
+
end
|
247
|
+
|
248
|
+
a2.each_slice(7) do |days_in_week|
|
249
|
+
|
250
|
+
pxweek = h['Week'].new Rexle.new('<week><summary/><records/></week>').root
|
251
|
+
|
252
|
+
days_in_week.each do |day|
|
253
|
+
|
254
|
+
day = Rexle.new("<day><summary/><records/></day>") unless day
|
255
|
+
pxweek.add h['Day'].new(day.root)
|
256
|
+
end
|
257
|
+
|
258
|
+
pxmonth.add pxweek
|
259
|
+
end
|
260
|
+
|
261
|
+
pxmonth.xslt = 'monthday_calendar.xsl'
|
262
|
+
pxmonth.css_layout = 'monthday_layout.css'
|
263
|
+
pxmonth.css_style = 'monthday.css'
|
264
|
+
pxmonth
|
265
|
+
|
266
|
+
else
|
267
|
+
cal_month.xslt = 'month_calendar.xsl'
|
268
|
+
cal_month.css_layout = 'month_layout.css'
|
269
|
+
cal_month.css_style = 'month.css'
|
270
|
+
|
271
|
+
cal_month
|
272
|
+
end
|
273
|
+
|
157
274
|
end
|
158
275
|
|
159
276
|
def months
|
@@ -215,6 +332,22 @@ class PolyrexCalendar
|
|
215
332
|
def import_bankholidays(dynarex)
|
216
333
|
import_dynarex(dynarex, :bankholiday=)
|
217
334
|
end
|
335
|
+
|
336
|
+
def import_recurring_events(dynarex)
|
337
|
+
|
338
|
+
title = dynarex.summary[:event_title]
|
339
|
+
cc = ChronicCron.new dynarex.summary[:description].split(/,/,2).first
|
340
|
+
time_start= "%s:%02d" % cc.to_time.to_a.values_at(2,1)
|
341
|
+
|
342
|
+
dynarex.flat_records.each do |event|
|
343
|
+
|
344
|
+
dt = DateTime.parse(event[:date])
|
345
|
+
m,w,i = @day[dt.to_date]
|
346
|
+
record = {title: title, time_start: time_start}
|
347
|
+
|
348
|
+
@polyrex.records[m].week[w].day[i].create.entry record
|
349
|
+
end
|
350
|
+
end
|
218
351
|
|
219
352
|
private
|
220
353
|
|
@@ -222,8 +355,8 @@ class PolyrexCalendar
|
|
222
355
|
|
223
356
|
dynarex.flat_records.each do |event|
|
224
357
|
|
225
|
-
|
226
|
-
m,w,i = @day[
|
358
|
+
dt = DateTime.parse(event[:date])
|
359
|
+
m,w,i = @day[dt.to_date]
|
227
360
|
@polyrex.records[m].week[w].day[i].method(daytype).call event[:title]
|
228
361
|
end
|
229
362
|
end
|
@@ -319,9 +452,7 @@ class PolyrexCalendar
|
|
319
452
|
end
|
320
453
|
|
321
454
|
@a = months
|
322
|
-
|
323
|
-
'day[wday, xday, title, event, date, ordinal, overlap, bankholiday]/' + \
|
324
|
-
'entry[time_start, time_end, duration, title]'
|
455
|
+
|
325
456
|
@polyrex = Polyrex.new(@schema, id_counter: @id)
|
326
457
|
year_start = months[0][0][-1]
|
327
458
|
@polyrex.summary.year = @year
|
@@ -362,14 +493,14 @@ class PolyrexCalendar
|
|
362
493
|
week_i += 1 if x.wday == 6
|
363
494
|
h = {wday: x.wday.to_s, xday: x.day.to_s, \
|
364
495
|
title: Date::DAYNAMES[k], date: x.strftime("%Y-%b-%d"), \
|
365
|
-
ordinal: x.day.to_i
|
496
|
+
ordinal: ordinal(x.day.to_i)}
|
366
497
|
else
|
367
498
|
#if blank find the nearest date in the week and calculate this date
|
368
499
|
# check right and if nothing then it's at the end of the month
|
369
500
|
x = week[-1] ? (week[-1] - (7-(k+1))) : week[0] + k
|
370
501
|
h = {wday: x.wday.to_s, xday: x.day.to_s, \
|
371
502
|
title: Date::DAYNAMES[k], date: x.strftime("%Y-%b-%d"), \
|
372
|
-
ordinal: x.day.to_i
|
503
|
+
ordinal: ordinal(x.day.to_i), overlap: 'true'}
|
373
504
|
end
|
374
505
|
|
375
506
|
create.day(h)
|
@@ -381,6 +512,10 @@ class PolyrexCalendar
|
|
381
512
|
|
382
513
|
end
|
383
514
|
|
515
|
+
def ordinal
|
516
|
+
( (10...20).include?(self) ? 'th' : %w{ th st nd rd th th th th th th }[self % 10] )
|
517
|
+
end
|
518
|
+
|
384
519
|
def slotted_sort(a)
|
385
520
|
|
386
521
|
upper = 36000 # upper slot value
|
@@ -406,13 +541,5 @@ class PolyrexCalendar
|
|
406
541
|
a = b.+([nil] * max_slots).take(max_slots).reverse
|
407
542
|
end
|
408
543
|
|
409
|
-
def generate_webpage(xml, xsl)
|
410
|
-
|
411
|
-
# transform the xml to html
|
412
|
-
doc = Nokogiri::XML(xml)
|
413
|
-
xslt = Nokogiri::XSLT(xsl)
|
414
|
-
html = xslt.transform(doc).to_xml
|
415
|
-
html
|
416
544
|
|
417
|
-
end
|
418
545
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
CIpMEIXEnQwmcmWL07xvpUquKTab0tCXtmcfjr74KP2KCm5guZyxeXaj9lD1OrnC
|
30
30
|
Kgt/mRI2beG8K7QY81GGMsQjiG95Dcko
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2014-01-
|
32
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: polyrex
|
@@ -79,15 +79,19 @@ executables: []
|
|
79
79
|
extensions: []
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
|
+
- lib/kplanner_month.xsl
|
82
83
|
- lib/calendar.xsl
|
83
84
|
- lib/month_calendar.xsl
|
84
85
|
- lib/week.css
|
85
86
|
- lib/layout.css
|
86
87
|
- lib/week_layout.css
|
87
88
|
- lib/polyrex-calendar.rb~
|
89
|
+
- lib/monthday_layout.css
|
88
90
|
- lib/polyrex-calendar.rb
|
89
91
|
- lib/week_calendar.xsl
|
90
92
|
- lib/calendar.xsl~
|
93
|
+
- lib/kplanner.xsl
|
94
|
+
- lib/monthday.css
|
91
95
|
- lib/month_layout.css
|
92
96
|
- lib/month.css
|
93
97
|
homepage: https://github.com/jrobertson/polyrex-calendar
|
metadata.gz.sig
CHANGED
Binary file
|