polyrex-calendar 0.3.10 → 0.3.11
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.tar.gz.sig +0 -0
- data/lib/polyrex-calendar.rb +8 -9
- data/lib/polyrex-calendar.rb~ +549 -83
- metadata +78 -33
- 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: a12d35568f6415a47e583e6991deadda6ad821aa
|
4
|
+
data.tar.gz: 492af65848a1efa54b982bd933aae06b3d5b1c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e146ccf872111f38f8f0b7512baac6d776755409fb288f178564abb1ee8f590c9369c09a7c007d56d6e3116158119c073683665ea4804d26de699da19e113448
|
7
|
+
data.tar.gz: e5020e116c468e67bea52bf40ea4155f3d8c20ba582b8b91ed4893b86e2f08ec6d4d90c13c1a70b77decd27626853bfcc7d8a43e5f366af772e2d75fd0f4f6d7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/polyrex-calendar.rb
CHANGED
@@ -7,6 +7,7 @@ require 'date'
|
|
7
7
|
require 'nokogiri'
|
8
8
|
require 'chronic_duration'
|
9
9
|
require 'chronic_cron'
|
10
|
+
require 'rxfhelper'
|
10
11
|
|
11
12
|
|
12
13
|
MONTH = DAY * 30
|
@@ -27,7 +28,8 @@ module LIBRARY
|
|
27
28
|
def fetch_file(filename)
|
28
29
|
|
29
30
|
lib = File.dirname(__FILE__)
|
30
|
-
File.read
|
31
|
+
File.read filename
|
32
|
+
|
31
33
|
end
|
32
34
|
|
33
35
|
def generate_webpage(xml, xsl)
|
@@ -37,6 +39,10 @@ module LIBRARY
|
|
37
39
|
xslt = Nokogiri::XSLT(xsl)
|
38
40
|
xslt.transform(doc).to_s
|
39
41
|
end
|
42
|
+
|
43
|
+
def read(s)
|
44
|
+
RXFHelper.read(s).first
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
class Polyrex
|
@@ -50,7 +56,7 @@ class Polyrex
|
|
50
56
|
|
51
57
|
def to_webpage()
|
52
58
|
|
53
|
-
year_xsl =
|
59
|
+
year_xsl = self.xslt ? read(self.xslt) : fetch_file(self.xslt)
|
54
60
|
year_layout_css = fetch_file self.css_layout
|
55
61
|
year_css = fetch_file self.css_style
|
56
62
|
File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
|
@@ -79,8 +85,6 @@ class PolyrexObjects::Month
|
|
79
85
|
month_layout_css = fetch_file self.css_layout
|
80
86
|
month_css = fetch_file self.css_style
|
81
87
|
|
82
|
-
#html = Rexslt.new(month_xsl, self.to_xml).to_xml
|
83
|
-
|
84
88
|
# add a css selector for the current day
|
85
89
|
date = Time.now.strftime("%Y-%b-%d")
|
86
90
|
|
@@ -116,8 +120,6 @@ class PolyrexObjects::Week
|
|
116
120
|
|
117
121
|
File.write 'self.xml', self.to_xml(pretty: true)
|
118
122
|
File.write 'week.xsl', week_xsl
|
119
|
-
#html = Rexslt.new(week_xsl, self.to_xml).to_xml
|
120
|
-
#html = xsltproc 'week_calendar.xsl', self.to_xml
|
121
123
|
|
122
124
|
# add a css selector for the current day
|
123
125
|
date = Time.now.strftime("%Y-%b-%d")
|
@@ -252,8 +254,6 @@ class PolyrexCalendar
|
|
252
254
|
+ "summary[sdate='#{date}']")
|
253
255
|
e.attributes[:class] = 'selected' if e
|
254
256
|
|
255
|
-
|
256
|
-
px.xslt = 'calendar.xsl'
|
257
257
|
px.css_layout = 'layout.css'
|
258
258
|
px.css_style = 'year.css'
|
259
259
|
px.filename = px.summary.year.to_s + '-planner.html'
|
@@ -603,5 +603,4 @@ class PolyrexCalendar
|
|
603
603
|
a = b.+([nil] * max_slots).take(max_slots).reverse
|
604
604
|
end
|
605
605
|
|
606
|
-
|
607
606
|
end
|
data/lib/polyrex-calendar.rb~
CHANGED
@@ -1,35 +1,204 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# file: polyrex-calendar.rb
|
4
4
|
|
5
5
|
require 'polyrex'
|
6
6
|
require 'date'
|
7
7
|
require 'nokogiri'
|
8
|
+
require 'chronic_duration'
|
9
|
+
require 'chronic_cron'
|
10
|
+
|
11
|
+
|
12
|
+
MONTH = DAY * 30
|
13
|
+
|
14
|
+
|
15
|
+
h = {
|
16
|
+
calendar: 'calendar[year]',
|
17
|
+
month: 'month[n, title]',
|
18
|
+
week: 'week[n, mon, no, label]',
|
19
|
+
day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
|
20
|
+
entry: 'entry[time_start, time_end, duration, title]'
|
21
|
+
}
|
22
|
+
visual_schema = h.values.join '/'
|
23
|
+
PolyrexObjects.new(visual_schema)
|
24
|
+
|
25
|
+
module LIBRARY
|
26
|
+
|
27
|
+
def fetch_file(filename)
|
28
|
+
|
29
|
+
lib = File.dirname(__FILE__)
|
30
|
+
File.read File.join(lib, filename )
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_webpage(xml, xsl)
|
34
|
+
|
35
|
+
# transform the xml to html
|
36
|
+
doc = Nokogiri::XML(xml)
|
37
|
+
xslt = Nokogiri::XSLT(xsl)
|
38
|
+
xslt.transform(doc).to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Polyrex
|
43
|
+
include LIBRARY
|
44
|
+
|
45
|
+
attr_accessor :xslt, :css_layout, :css_style, :filename
|
46
|
+
|
47
|
+
def inspect()
|
48
|
+
"#<Polyrex:%s" % __id__
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_webpage()
|
52
|
+
|
53
|
+
year_xsl = fetch_file self.xslt
|
54
|
+
year_layout_css = fetch_file self.css_layout
|
55
|
+
year_css = fetch_file self.css_style
|
56
|
+
File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
|
57
|
+
File.open(self.xslt,'w'){|f| f.write year_xsl }
|
58
|
+
#html = Rexslt.new(month_xsl, self.to_xml).to_xml
|
59
|
+
|
60
|
+
html = generate_webpage self.to_xml, year_xsl
|
61
|
+
{self.filename => html,
|
62
|
+
self.css_layout => year_layout_css, self.css_style => year_css}
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class PolyrexObjects::Month
|
68
|
+
include LIBRARY
|
69
|
+
|
70
|
+
attr_accessor :xslt, :css_layout, :css_style
|
71
|
+
|
72
|
+
def inspect()
|
73
|
+
"#<PolyrexObjects::Month:%s" % __id__
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_webpage()
|
77
|
+
|
78
|
+
month_xsl = fetch_file self.xslt
|
79
|
+
month_layout_css = fetch_file self.css_layout
|
80
|
+
month_css = fetch_file self.css_style
|
81
|
+
|
82
|
+
#html = Rexslt.new(month_xsl, self.to_xml).to_xml
|
83
|
+
|
84
|
+
# add a css selector for the current day
|
85
|
+
date = Time.now.strftime("%Y-%b-%d")
|
86
|
+
|
87
|
+
e = self.element("records/week/records/day/summary[sdate='#{date}']")
|
88
|
+
e.attributes[:class] = 'selected' if e
|
89
|
+
|
90
|
+
File.write 'self.xml', self.to_xml(pretty: true)
|
91
|
+
File.write 'month.xsl', month_xsl
|
92
|
+
|
93
|
+
|
94
|
+
html = generate_webpage self.to_xml, month_xsl
|
95
|
+
{self.title.downcase[0..2] + '_calendar.html' => html,
|
96
|
+
self.css_layout => month_layout_css, self.css_style => month_css}
|
97
|
+
end
|
98
|
+
|
99
|
+
def wk(n)
|
100
|
+
self.records[n-1]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class PolyrexObjects::Week
|
105
|
+
include LIBRARY
|
106
|
+
|
107
|
+
def inspect()
|
108
|
+
"#<PolyrexObjects::Week:%s" % __id__
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_webpage()
|
112
|
+
|
113
|
+
week_xsl = fetch_file 'week_calendar.xsl'
|
114
|
+
week_layout_css = fetch_file 'week_layout.css'
|
115
|
+
week_css = fetch_file 'week.css'
|
116
|
+
|
117
|
+
File.write 'self.xml', self.to_xml(pretty: true)
|
118
|
+
File.write 'week.xsl', week_xsl
|
119
|
+
#html = Rexslt.new(week_xsl, self.to_xml).to_xml
|
120
|
+
#html = xsltproc 'week_calendar.xsl', self.to_xml
|
121
|
+
|
122
|
+
# add a css selector for the current day
|
123
|
+
date = Time.now.strftime("%Y-%b-%d")
|
124
|
+
|
125
|
+
e = self.element("records/day/summary[sdate='#{date}']")
|
126
|
+
e.attributes[:class] = 'selected' if e
|
127
|
+
|
128
|
+
|
129
|
+
html = generate_webpage self.to_xml, week_xsl
|
130
|
+
{'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
|
131
|
+
'week.css' => week_css}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class PolyrexObjects::Day
|
136
|
+
|
137
|
+
def date()
|
138
|
+
Date.parse(self.sdate)
|
139
|
+
end
|
140
|
+
|
141
|
+
def wday()
|
142
|
+
self.date.wday
|
143
|
+
end
|
144
|
+
|
145
|
+
def day()
|
146
|
+
self.date.day
|
147
|
+
end
|
148
|
+
end
|
8
149
|
|
9
150
|
class PolyrexCalendar
|
151
|
+
include LIBRARY
|
10
152
|
|
11
153
|
attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
|
154
|
+
attr_reader :day
|
12
155
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
lib = File.dirname(__FILE__)
|
25
|
-
month_xsl = File.open(lib + '/month_calendar.xsl','r').read
|
26
|
-
month_css = File.open(lib + '/month_layout.css','r').read
|
27
|
-
doc = Nokogiri::XML(self.to_xml); xslt = Nokogiri::XSLT(month_xsl)
|
28
|
-
html = xslt.transform(doc).to_xml
|
29
|
-
{self.name.downcase[0..2] + '_calendar.html' => html, 'month_layout.css' => month_css}
|
30
|
-
end
|
156
|
+
def initialize(calendar_file=nil, options={})
|
157
|
+
|
158
|
+
opts = {year: Time.now.year.to_s}.merge(options)
|
159
|
+
@year = opts[:year]
|
160
|
+
|
161
|
+
h = {
|
162
|
+
calendar: 'calendar[year]',
|
163
|
+
month: 'month[n, title]',
|
164
|
+
week: 'week[n]',
|
165
|
+
day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
|
166
|
+
entry: 'entry[time_start, time_end, duration, title]'
|
31
167
|
}
|
168
|
+
@schema = %i(calendar month day entry).map{|x| h[x]}.join '/'
|
169
|
+
@visual_schema = h.values.join '/'
|
170
|
+
|
171
|
+
|
172
|
+
if calendar_file then
|
173
|
+
@polyrex = Polyrex.new calendar_file
|
174
|
+
@id = @polyrex.id_counter
|
175
|
+
|
176
|
+
else
|
177
|
+
@id = '1'
|
178
|
+
# generate the calendar
|
179
|
+
|
180
|
+
a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
|
181
|
+
|
182
|
+
@polyrex = Polyrex.new(@schema, id_counter: @id)
|
183
|
+
@polyrex.summary.year = @year
|
184
|
+
|
185
|
+
a.group_by(&:month).each do |month, days|
|
186
|
+
|
187
|
+
@polyrex.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create|
|
188
|
+
days.each do |x|
|
189
|
+
create.day sdate: x.strftime("%Y-%b-%d"), xday: x.day.to_s, title: Date::DAYNAMES[x.wday]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
32
193
|
|
194
|
+
end
|
195
|
+
|
196
|
+
visual_schema = h.values.join '/'
|
197
|
+
PolyrexObjects.new(visual_schema)
|
198
|
+
|
199
|
+
@xsl = fetch_file 'calendar.xsl'
|
200
|
+
@css = fetch_file 'layout.css'
|
201
|
+
|
33
202
|
end
|
34
203
|
|
35
204
|
def to_a()
|
@@ -40,102 +209,399 @@ class PolyrexCalendar
|
|
40
209
|
@polyrex.to_xml pretty: true
|
41
210
|
end
|
42
211
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def import_events(dynarex)
|
49
|
-
dynarex.flat_records.each do |event|
|
50
|
-
m,w,i = @day[Date.parse(event[:date])]
|
51
|
-
@polyrex.records[m].week[w].day[i].event = event[:title]
|
52
|
-
end
|
212
|
+
def import_events(objx)
|
213
|
+
@id = @polyrex.id_counter
|
214
|
+
method('import_'.+(objx.class.to_s.downcase).to_sym).call(objx)
|
53
215
|
self
|
54
216
|
end
|
217
|
+
|
218
|
+
alias import! import_events
|
55
219
|
|
56
|
-
def
|
57
|
-
|
220
|
+
def inspect()
|
221
|
+
%Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">)
|
58
222
|
end
|
59
223
|
|
60
|
-
def
|
61
|
-
|
224
|
+
def kitchen_planner()
|
225
|
+
|
226
|
+
px = @polyrex
|
227
|
+
|
228
|
+
# add a css selector for the current day
|
229
|
+
date = DateTime.now.strftime("%Y-%b-%d")
|
230
|
+
e = px.element("records/month/records/day/summary[sdate='#{date}']")
|
231
|
+
e.attributes[:class] = 'selected' if e
|
232
|
+
|
233
|
+
px.xslt = 'kplanner.xsl'
|
234
|
+
px.css_layout = 'monthday_layout.css'
|
235
|
+
px.css_style = 'monthday.css'
|
236
|
+
px.filename = @year + '-kitchen-planner.html'
|
237
|
+
|
238
|
+
px
|
239
|
+
|
62
240
|
end
|
63
241
|
|
64
|
-
|
242
|
+
def year_planner()
|
65
243
|
|
66
|
-
|
244
|
+
px = Polyrex.new(@visual_schema, id_counter: @id)
|
245
|
+
px.summary.year = @year
|
246
|
+
|
247
|
+
(1..12).each {|n| px.add self.month(n, monday_week: true) }
|
248
|
+
|
249
|
+
# add a css selector for the current day
|
250
|
+
date = DateTime.now.strftime("%Y-%b-%d")
|
251
|
+
e = px.element("records/month/records/week/records/day/" \
|
252
|
+
+ "summary[sdate='#{date}']")
|
253
|
+
e.attributes[:class] = 'selected' if e
|
254
|
+
|
255
|
+
|
256
|
+
px.xslt = 'calendar.xsl'
|
257
|
+
px.css_layout = 'layout.css'
|
258
|
+
px.css_style = 'year.css'
|
259
|
+
px.filename = px.summary.year.to_s + '-planner.html'
|
260
|
+
|
261
|
+
px
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
def month(m, monday_week: false)
|
266
|
+
|
267
|
+
if monday_week == true
|
268
|
+
|
269
|
+
pxmonth = make_month(m) do |a, wday|
|
270
|
+
|
271
|
+
# Monday start
|
272
|
+
# wdays: 1 = Monday, 0 = Sunday
|
273
|
+
|
274
|
+
r = case wday
|
275
|
+
|
276
|
+
# the 1st day of the month is a Monday, add no placeholders
|
277
|
+
when 1 then a
|
278
|
+
|
279
|
+
# the 1st day is a Sunday, add 6 placeholders before that day
|
280
|
+
when 0 then Array.new(6) + a
|
281
|
+
|
282
|
+
# add a few placeholders before the 1st day
|
283
|
+
else Array.new(wday - 1) + a
|
284
|
+
end
|
285
|
+
|
286
|
+
r
|
67
287
|
|
68
|
-
d = Date.parse(@year.to_s + '-Jan-01')
|
69
|
-
a = []
|
70
|
-
(a << d; d += 1) while d.year == Time.now.year
|
71
288
|
|
72
|
-
months = a.group_by(&:month).map do |key, month|
|
73
|
-
i = month.index(month.detect{|x| x.wday == 0})
|
74
|
-
unless i == 0 then
|
75
|
-
weeks = [month.slice!(0,i)] + month.each_slice(7).to_a
|
76
|
-
(weeks[0] = ([nil] * 6 + weeks[0]).slice(-7..-1))
|
77
|
-
else
|
78
|
-
weeks = month.each_slice(7).to_a
|
79
289
|
end
|
80
290
|
|
81
|
-
|
82
|
-
|
291
|
+
pxmonth.xslt = 'monthday_calendar.xsl'
|
292
|
+
pxmonth.css_layout = 'monthday_layout.css'
|
293
|
+
pxmonth.css_style = 'monthday.css'
|
294
|
+
pxmonth
|
295
|
+
|
296
|
+
else
|
297
|
+
|
298
|
+
pxmonth = make_month(m) do |a, wday|
|
299
|
+
|
300
|
+
# Sunday start
|
301
|
+
# wdays: 1 = Monday, 0 = Sunday
|
302
|
+
|
303
|
+
r = case wday
|
304
|
+
|
305
|
+
# the 1st day of the month is a Sunday, add no placeholders
|
306
|
+
when 0 then a
|
307
|
+
|
308
|
+
# add a few placeholders before the 1st day
|
309
|
+
else Array.new(6 - wday) + a
|
310
|
+
end
|
311
|
+
|
312
|
+
r
|
313
|
+
|
83
314
|
end
|
84
315
|
|
85
|
-
|
316
|
+
pxmonth.xslt = 'month_calendar.xsl'
|
317
|
+
pxmonth.css_layout = 'month_layout.css'
|
318
|
+
pxmonth.css_style = 'month.css'
|
319
|
+
pxmonth
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
def month_day()
|
324
|
+
end
|
325
|
+
|
326
|
+
def months
|
327
|
+
@polyrex.records
|
328
|
+
end
|
329
|
+
|
330
|
+
def parse_events(list)
|
331
|
+
|
332
|
+
polyrex = Polyrex.new('events/dayx[date, title]/entryx[start_time, end_time,' + \
|
333
|
+
' duration, title]')
|
334
|
+
|
335
|
+
polyrex.format_masks[1] = '([!start_time] \([!duration]\) [!title]|' + \
|
336
|
+
'[!start_time]-[!end_time] [!title]|' + \
|
337
|
+
'[!start_time] [!title])'
|
338
|
+
|
339
|
+
polyrex.parse(list)
|
340
|
+
|
341
|
+
self.import_events polyrex
|
342
|
+
# for testing only
|
343
|
+
#polyrex
|
344
|
+
end
|
345
|
+
|
346
|
+
def save(filename='polyrex.xml')
|
347
|
+
@polyrex.save filename
|
348
|
+
end
|
349
|
+
|
350
|
+
def this_week()
|
351
|
+
|
352
|
+
dt = DateTime.now
|
353
|
+
days = @polyrex.records[dt.month-1].day
|
354
|
+
|
355
|
+
r = days.find {|day| day.date.cweek == dt.cweek }
|
356
|
+
pxweek = PolyrexObjects::Week.new
|
357
|
+
pxweek.mon = Date::MONTHNAMES[dt.month]
|
358
|
+
pxweek.no = dt.cweek.to_s
|
359
|
+
pxweek.label = ''
|
360
|
+
days[days.index(r),7].each{|day| pxweek.add day }
|
361
|
+
|
362
|
+
pxweek
|
363
|
+
end
|
364
|
+
|
365
|
+
def this_month()
|
366
|
+
self.month(DateTime.now.month)
|
367
|
+
end
|
368
|
+
|
369
|
+
def import_bankholidays(dynarex)
|
370
|
+
import_dynarex(dynarex, :bankholiday=)
|
371
|
+
end
|
372
|
+
|
373
|
+
def import_recurring_events(dynarex)
|
374
|
+
|
375
|
+
title = dynarex.summary[:event_title]
|
376
|
+
cc = ChronicCron.new dynarex.summary[:description].split(/,/,2).first
|
377
|
+
time_start= "%s:%02d" % cc.to_time.to_a.values_at(2,1)
|
378
|
+
|
379
|
+
dynarex.flat_records.each do |event|
|
380
|
+
|
381
|
+
dt = DateTime.parse(event[:date])
|
382
|
+
m, d = dt.month, dt.day
|
383
|
+
record = {title: title, time_start: time_start}
|
384
|
+
|
385
|
+
@polyrex.records[m-1].day[d-1].create.entry record
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
def import_sunrise_times(dynarex)
|
390
|
+
import_suntimes dynarex, :sunrise=
|
391
|
+
end
|
392
|
+
|
393
|
+
def import_sunset_times(dynarex)
|
394
|
+
import_suntimes dynarex, :sunset=
|
395
|
+
end
|
396
|
+
|
397
|
+
private
|
398
|
+
|
399
|
+
def import_suntimes(dynarex, event_type=:sunrise=)
|
400
|
+
|
401
|
+
dynarex.flat_records.each do |event|
|
402
|
+
|
403
|
+
dt = DateTime.parse(event[:date])
|
404
|
+
m, d = dt.month, dt.day
|
405
|
+
@polyrex.records[m-1].day[d-1].method(event_type).call event[:time]
|
86
406
|
end
|
407
|
+
end
|
408
|
+
|
409
|
+
def import_dynarex(dynarex, daytype=:event=)
|
410
|
+
|
411
|
+
dynarex.flat_records.each do |event|
|
412
|
+
|
413
|
+
dt = DateTime.parse(event[:date])
|
414
|
+
m, d = dt.month, dt.day
|
415
|
+
|
416
|
+
case daytype
|
417
|
+
when :event=
|
418
|
+
if dynarex.fields.include?(:time) then
|
419
|
+
|
420
|
+
match = event[:time].match(/(\S+)\s*(?:to|-)\s*(\S+)/)
|
421
|
+
|
422
|
+
if match then
|
423
|
+
|
424
|
+
start_time, end_time = match.captures
|
425
|
+
# add an event entry
|
426
|
+
title = [event[:title], dynarex.summary[:label],
|
427
|
+
event[:desc]].compact.join(': ')
|
428
|
+
record = {
|
429
|
+
title: title,
|
430
|
+
time_start: Time.parse(start_time).strftime("%H:%M%p"),
|
431
|
+
time_end: Time.parse(end_time).strftime("%H:%M%p")
|
432
|
+
}
|
433
|
+
|
434
|
+
@polyrex.records[m-1].day[d-1].create.entry record
|
435
|
+
else
|
436
|
+
|
437
|
+
dt = DateTime.parse(event[:date] + ' ' + event[:time])
|
438
|
+
# add the event
|
439
|
+
title = [event[:title], dynarex.summary[:label],
|
440
|
+
event[:desc]].compact.join(': ')
|
441
|
+
event_label = "%s at %s" % [title, dt.strftime("%H:%M%p")]
|
442
|
+
|
443
|
+
@polyrex.records[m-1].day[d-1].method(daytype).call event_label
|
444
|
+
end
|
445
|
+
|
446
|
+
else
|
87
447
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
448
|
+
event_label = "%s at %s" % [event[:title], dt.strftime("%H:%M%p")]
|
449
|
+
@polyrex.records[m-1].day[d-1].method(daytype).call event_label
|
450
|
+
end
|
451
|
+
|
452
|
+
else
|
453
|
+
|
454
|
+
event_label = "%s" % event[:title]
|
455
|
+
@polyrex.records[m-1].day[d-1].method(daytype).call event_label
|
92
456
|
end
|
457
|
+
|
93
458
|
end
|
459
|
+
end
|
460
|
+
|
461
|
+
def import_polyrex(polyrex)
|
462
|
+
|
463
|
+
polyrex.records.each do |day|
|
464
|
+
|
465
|
+
dt = day.date
|
94
466
|
|
95
|
-
|
467
|
+
sd = dt.strftime("%Y-%b-%d ")
|
468
|
+
m, i = dt.month, dt.day
|
469
|
+
cal_day = @polyrex.records[m - 1].day[i-1]
|
96
470
|
|
97
|
-
|
98
|
-
year_start = months[0][0][-1]
|
99
|
-
@polyrex.summary.year = @year
|
100
|
-
old_year_week = (year_start - 7).cweek
|
471
|
+
cal_day.event = day.title
|
101
472
|
|
102
|
-
|
473
|
+
if day.records.length > 0 then
|
103
474
|
|
104
|
-
|
475
|
+
raw_entries = day.records
|
105
476
|
|
106
|
-
|
107
|
-
month.each_with_index do |week,j|
|
477
|
+
entries = raw_entries.inject({}) do |r,entry|
|
108
478
|
|
109
|
-
|
110
|
-
create.week rel_no: (j+1).to_s, no: week_s do |create|
|
111
|
-
week.each_with_index do |x,k|
|
479
|
+
start_time = entry.start_time
|
112
480
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
481
|
+
if entry.end_time.length > 0 then
|
482
|
+
|
483
|
+
end_time = entry.end_time
|
484
|
+
duration = ChronicDuration.output(Time.parse(sd + end_time) \
|
485
|
+
- Time.parse(sd + start_time))
|
486
|
+
else
|
487
|
+
|
488
|
+
if entry.duration.length > 0 then
|
489
|
+
duration = entry.duration
|
490
|
+
else
|
491
|
+
duration = '10 mins'
|
124
492
|
end
|
493
|
+
|
494
|
+
end_time = (Time.parse(sd + start_time) + ChronicDuration.parse(duration))\
|
495
|
+
.strftime("%H:%M")
|
125
496
|
end
|
497
|
+
|
498
|
+
r.merge!(start_time => {time_start: start_time, time_end: end_time, \
|
499
|
+
duration: duration, title: entry.title})
|
500
|
+
|
126
501
|
end
|
502
|
+
|
503
|
+
seconds = entries.keys.map{|x| Time.parse(x) - Time.parse('08:00')}
|
504
|
+
|
505
|
+
unless dt.saturday? or dt.sunday? then
|
506
|
+
rows = slotted_sort(seconds).map do |x|
|
507
|
+
(Time.parse('08:00') + x.to_i).strftime("%H:%M") if x
|
508
|
+
end
|
509
|
+
else
|
510
|
+
rows = entries.keys
|
511
|
+
end
|
512
|
+
|
513
|
+
rows.each do |row|
|
514
|
+
create = cal_day.create
|
515
|
+
create.id = @id
|
516
|
+
create.entry entries[row] || {}
|
517
|
+
end
|
518
|
+
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
end
|
523
|
+
|
524
|
+
def make_month(m)
|
525
|
+
|
526
|
+
cal_month = @polyrex.records[m-1]
|
527
|
+
days_in_month = cal_month.records
|
528
|
+
pxmonth = cal_month.clone
|
529
|
+
pxmonth.records.each(&:delete)
|
530
|
+
|
531
|
+
a = days_in_month
|
532
|
+
|
533
|
+
i = a[0].wday
|
534
|
+
|
535
|
+
a2 = yield(a, i)
|
536
|
+
|
537
|
+
a2.each_slice(7) do |days_in_week|
|
538
|
+
|
539
|
+
pxweek = PolyrexObjects::Week.new
|
540
|
+
|
541
|
+
days_in_week.each do |day|
|
542
|
+
|
543
|
+
new_day = day ? day.deep_clone : PolyrexObjects::Day.new
|
544
|
+
pxweek.add new_day
|
127
545
|
end
|
546
|
+
|
547
|
+
pxmonth.add pxweek
|
128
548
|
end
|
129
549
|
|
130
|
-
|
550
|
+
week1 = pxmonth.week[0]
|
131
551
|
|
132
|
-
|
552
|
+
other_days = week1.day.select{|day| day.sdate.empty? }
|
553
|
+
start_date = week1.day[other_days.length].date
|
554
|
+
|
555
|
+
other_days.reverse.each.with_index do |day, i|
|
556
|
+
day.sdate = (start_date - (i+1)).strftime("%Y %b %d")
|
557
|
+
day.xday = day.date.day.to_s
|
558
|
+
end
|
559
|
+
|
560
|
+
last_week = pxmonth.week[-1]
|
561
|
+
|
562
|
+
gap = 7 - last_week.records.length
|
563
|
+
end_date = last_week.day.last.date
|
564
|
+
|
565
|
+
gap.times do |i|
|
566
|
+
|
567
|
+
day = PolyrexObjects::Day.new
|
568
|
+
day.sdate = (end_date + (i+1)).strftime("%Y %b %d")
|
569
|
+
day.xday = day.date.day.to_s
|
570
|
+
last_week.add day
|
571
|
+
end
|
572
|
+
|
573
|
+
pxmonth
|
574
|
+
end
|
133
575
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
576
|
+
def ordinal(val)
|
577
|
+
(10...20).include?(val) ? \
|
578
|
+
'th' : %w{ th st nd rd th th th th th th }[val % 10]
|
579
|
+
end
|
580
|
+
|
581
|
+
def slotted_sort(a)
|
582
|
+
|
583
|
+
upper = 36000 # upper slot value
|
584
|
+
slot_width = 9000 # 2.5 hours
|
585
|
+
max_slots = 3
|
586
|
+
|
587
|
+
b = a.reverse.inject([]) do |r,x|
|
588
|
+
|
589
|
+
upper ||= 10; i ||= 0
|
590
|
+
diff = upper - x
|
139
591
|
|
592
|
+
if diff >= slot_width and (i + a.length) < max_slots then
|
593
|
+
r << nil
|
594
|
+
i += 1
|
595
|
+
upper -= slot_width
|
596
|
+
redo
|
597
|
+
else
|
598
|
+
upper -= slot_width if x <= upper
|
599
|
+
r << x
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
a = b.+([nil] * max_slots).take(max_slots).reverse
|
140
604
|
end
|
141
|
-
|
605
|
+
|
606
|
+
|
607
|
+
end
|
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.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,86 +31,130 @@ cert_chain:
|
|
31
31
|
V2LbfuIuDVCUDR9ON1ozFySFLuTnZSmO6lR4UsFjHKwbtnnbapfQVvEJ1PLW/F13
|
32
32
|
1r3+lzIVNJhpdQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-
|
34
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: polyrex
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
42
|
+
version: '0.9'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.3
|
43
46
|
type: :runtime
|
44
47
|
prerelease: false
|
45
48
|
version_requirements: !ruby/object:Gem::Requirement
|
46
49
|
requirements:
|
47
|
-
- -
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.9'
|
53
|
+
- - ">="
|
48
54
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
55
|
+
version: 0.9.3
|
50
56
|
- !ruby/object:Gem::Dependency
|
51
57
|
name: nokogiri
|
52
58
|
requirement: !ruby/object:Gem::Requirement
|
53
59
|
requirements:
|
54
|
-
- -
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.6'
|
63
|
+
- - ">="
|
55
64
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
65
|
+
version: 1.6.2.1
|
57
66
|
type: :runtime
|
58
67
|
prerelease: false
|
59
68
|
version_requirements: !ruby/object:Gem::Requirement
|
60
69
|
requirements:
|
61
|
-
- -
|
70
|
+
- - "~>"
|
62
71
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
72
|
+
version: '1.6'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.6.2.1
|
64
76
|
- !ruby/object:Gem::Dependency
|
65
77
|
name: chronic_duration
|
66
78
|
requirement: !ruby/object:Gem::Requirement
|
67
79
|
requirements:
|
68
|
-
- -
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- - ">="
|
69
84
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
85
|
+
version: 0.10.4
|
71
86
|
type: :runtime
|
72
87
|
prerelease: false
|
73
88
|
version_requirements: !ruby/object:Gem::Requirement
|
74
89
|
requirements:
|
75
|
-
- -
|
90
|
+
- - "~>"
|
76
91
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
92
|
+
version: '0.10'
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.10.4
|
78
96
|
- !ruby/object:Gem::Dependency
|
79
97
|
name: chronic_cron
|
80
98
|
requirement: !ruby/object:Gem::Requirement
|
81
99
|
requirements:
|
82
|
-
- -
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.2'
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 0.2.33
|
106
|
+
type: :runtime
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0.2'
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 0.2.33
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: rxfhelper
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0.1'
|
123
|
+
- - ">="
|
83
124
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
125
|
+
version: 0.1.12
|
85
126
|
type: :runtime
|
86
127
|
prerelease: false
|
87
128
|
version_requirements: !ruby/object:Gem::Requirement
|
88
129
|
requirements:
|
89
|
-
- -
|
130
|
+
- - "~>"
|
90
131
|
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
132
|
+
version: '0.1'
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 0.1.12
|
92
136
|
description:
|
93
137
|
email: james@r0bertson.co.uk
|
94
138
|
executables: []
|
95
139
|
extensions: []
|
96
140
|
extra_rdoc_files: []
|
97
141
|
files:
|
98
|
-
- lib/kplanner_month.xsl
|
99
142
|
- lib/calendar.xsl
|
100
|
-
- lib/
|
101
|
-
- lib/
|
143
|
+
- lib/calendar.xsl~
|
144
|
+
- lib/kplanner.xsl
|
145
|
+
- lib/kplanner_month.xsl
|
102
146
|
- lib/layout.css
|
103
|
-
- lib/
|
104
|
-
- lib/
|
147
|
+
- lib/month.css
|
148
|
+
- lib/month_calendar.xsl
|
149
|
+
- lib/month_layout.css
|
150
|
+
- lib/monthday.css
|
105
151
|
- lib/monthday_layout.css
|
106
152
|
- lib/polyrex-calendar.rb
|
153
|
+
- lib/polyrex-calendar.rb~
|
154
|
+
- lib/week.css
|
107
155
|
- lib/week_calendar.xsl
|
108
|
-
- lib/
|
109
|
-
- lib/kplanner.xsl
|
110
|
-
- lib/monthday.css
|
156
|
+
- lib/week_layout.css
|
111
157
|
- lib/year.css
|
112
|
-
- lib/month_layout.css
|
113
|
-
- lib/month.css
|
114
158
|
homepage: https://github.com/jrobertson/polyrex-calendar
|
115
159
|
licenses:
|
116
160
|
- MIT
|
@@ -121,18 +165,19 @@ require_paths:
|
|
121
165
|
- lib
|
122
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
167
|
requirements:
|
124
|
-
- -
|
168
|
+
- - ">="
|
125
169
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
170
|
+
version: 2.1.2
|
127
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
172
|
requirements:
|
129
|
-
- -
|
173
|
+
- - ">="
|
130
174
|
- !ruby/object:Gem::Version
|
131
175
|
version: '0'
|
132
176
|
requirements: []
|
133
177
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.2.2
|
135
179
|
signing_key:
|
136
180
|
specification_version: 4
|
137
|
-
summary:
|
181
|
+
summary: Generates an HTML calendar from a Polyrex document
|
138
182
|
test_files: []
|
183
|
+
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|