polyrex-calendar 0.3.0 → 0.3.1

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: c5b7f2adb9120d8bb6f30118816a105abb7321d5
4
- data.tar.gz: 7d8db19931ccce31286d9d10962e75bf26f77554
3
+ metadata.gz: 73a4ea12f8ea4b5072eb3bc43b38d53023a57cbf
4
+ data.tar.gz: e6b7d20a0696d322cb5f55a9b7cfd4123b404d2b
5
5
  SHA512:
6
- metadata.gz: f7f017e63343dce72c18ba5d7cc7f82c334f9e0eb6d155a3a037ab944c749fb7010d7fb35540ef99a0836a4a57871488e3802267ee6429f66b88335b2fc29597
7
- data.tar.gz: 971706fa487574ebb81cff54bff62750bf880cc95ebb412b000dfd191cfd3f70254d645682b5817606e84c7a805573afe674f21c353ff9d072e7adb5b92a88f1
6
+ metadata.gz: 59ab20f5c5150fb7fdb381f7a86fe133346c544d93461a0e3b5ddfe1e3486b893eed51672918d75d3184d0fdc290f00e097fd7deaf9b4c3263a1088ef01bf4ff
7
+ data.tar.gz: c6ea19082bb2f13d40946c6c07a569f4d6c0a6883eb76a0d4059f14dbb2555440d304f6f6d8fedb8fd2dc792f623a7e2a457c7b83f596983009ba5a2a7a31b44
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ~������ە���u;���֟����p�u��J�RLM6
2
- Rv�W�f/ƺwU�6��R�E;�|Zc�+��R� ���-K�<f���諐k-�B���9-RR
1
+ ����~�{M5���� "9�u���AYo�-fe��J���;#]���9�l*�0j1/�S��%=!1��;���ĥ'��]T�ù�~��<�`����썕{(�z��>� �<��k���#LbZU���T�/����=���>��R����D@��O�xg꤮���D��ZN?gŅ�OU������z0:W��x�J�AO\�����:C&�����s��L� �.�������`Z�Y^���rSF���\-tٚ
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- F���"�>���I0�6.mő������f��LiX�����'_j.�!���An��B3>5 ;��\Je<�j���k����' ”�#�t�ZWD3�I��o�8K�,��iwB&�=���ȩ"?�� W0hH.��}QK}9J�9��M#�a2&5Q��� S��}񗜧Ѡ:ٌM�I�^Y!��H�w��5�õ-�&�OvrE��(�9���*F��n����� �m�k9q�Tdu���_=m�
1
+ ���g u��:��c5���'����n�I@��*��v>��Ǔbʑ�lc2p�a6�\�K��+�WX�E������_��e��퓙.fu7����۔�Ch�/�i7��\��?7�{v��z_2m�|�,a3��� ĭ�c6p+��f���n}?0jY�;̞�9_b�i���ըW9ru�5eM���K�{���Dj��Mڸ�3h��f�8;�u�ɉO,�5\痢�JV���o�#�zHn�*�E
data/lib/layout.css CHANGED
@@ -1,13 +1,12 @@
1
1
  body {background-color: transparent }
2
2
 
3
3
  #wrap {
4
- background-color: transparent;
5
- border: 1px solid transparent;
6
- margin: 0 auto;
4
+ background-color: #d93;
5
+ margin: 0;
7
6
  margin-bottom: 0.6em;
8
7
  overflow: hidden;
9
- padding-bottom: 4em;
10
- width: 750px;
8
+ padding-bottom: 0.5em;
9
+ width: 690px;
11
10
  }
12
11
 
13
12
  #wrap h1 {
@@ -16,15 +15,45 @@ body {background-color: transparent }
16
15
  padding: 0.2em 0.4em;
17
16
  }
18
17
 
19
- #wrap .table {
20
- background-color: transparent;
18
+ #wrap>div:first-child {
19
+ background-color: #458;
20
+ float:left;
21
+ width:405px;
22
+ }
23
+
24
+ #wrap>div:first-child>div {
25
+ background-color: #894;
21
26
  float: left;
22
- height: 13em;
23
- padding: 1em 0.8em;
24
- margin: 0.5em;
27
+
28
+ padding: 0.4em 0.4em;
29
+ margin: 0.1em;
30
+ }
31
+
32
+ #wrap table {
33
+ background-color: transparent;
34
+
35
+ }
36
+ #wrap table td {text-align: center}
37
+
38
+
39
+ #wrap>div:nth-child(2), #wrap>div:last-child {
40
+ background-color: #444;
41
+ font-size: 0.8em;
42
+ padding: 0.5em;
43
+ margin: 0.3em;
44
+
25
45
  }
46
+ #wrap>div:nth-child(2) {
47
+ background-color: #444;
48
+ float: left;
49
+ page-break-after: always;
26
50
 
27
- #wrap table {background-color: transparent; }
28
- #wrap table td {text-align: right}
51
+ }
29
52
 
53
+ #wrap>div:nth-child(2)>ul {
54
+ background-color: transparent;
55
+ }
30
56
 
57
+ #wrap>div:nth-child(2)>ul>li {
58
+ background-color: transparent;
59
+ }
data/lib/month.css CHANGED
@@ -9,12 +9,14 @@
9
9
  }
10
10
 
11
11
  #wrap table{
12
- background-color: rgba(230, 230, 170, 0.1);
12
+ background-color: rgba(230, 230, 170, 0.6);
13
13
  border: none;
14
+ font-family: Helvetica, Verdana, Serif;
15
+ font-size: 1.2em;
14
16
  }
15
17
 
16
18
  #wrap>table th{
17
- background-color: rgba(180, 180, 150, 0.5);
19
+ background-color: rgba(180, 180, 150, 0.8);
18
20
  color: rgba(80, 80, 50, 0.8);
19
21
  border: 1px solid rgba(80, 80, 50, 0.8);
20
22
  }
@@ -24,17 +26,21 @@
24
26
  }
25
27
 
26
28
  #wrap>table tr>td{
29
+ background-color: rgba(130, 130, 160, 0.3);
30
+ }
31
+
32
+ #wrap>table tr>td>div{
27
33
  background-color: rgba(230, 230, 70, 0.4);
28
- color: rgba(130, 130, 30, 1);
29
- border: 1px solid rgba(80, 80, 50, 0.8);
34
+ color: rgba(80, 80, 30, 1);
35
+ margin: 0.3em;
30
36
  }
31
37
 
32
- #wrap>table tr>td.selected{
38
+ #wrap>table tr>td>div.selected{
33
39
  /*background-color: transparent;*/
34
40
  border: 5px solid rgba(240, 150, 100, 0.9);
35
41
  border-radius: 15px;
36
42
  }
37
43
 
38
- #wrap>table tr>td:nth-child(1), #wrap>table tr>td:nth-child(7){
44
+ #wrap>table tr>td:nth-child(1)>div, #wrap>table tr>td:nth-child(7)>div{
39
45
  background-color: rgba(230, 230, 70, 0.2);
40
46
  }
@@ -42,25 +42,32 @@
42
42
  </xsl:template>
43
43
 
44
44
  <xsl:template match="records/day">
45
+ <td>
46
+ <div>
45
47
  <xsl:apply-templates select="summary"/>
48
+ <xsl:apply-templates select="records"/>
49
+ </div>
50
+ </td>
46
51
  </xsl:template>
47
52
 
48
53
  <xsl:template match="day/summary">
49
- <xsl:element name="td">
54
+
50
55
  <xsl:if test="css_style">
51
56
  <xsl:attribute name="class"><xsl:value-of select="css_style"/></xsl:attribute>
52
57
  </xsl:if>
53
- <div>
54
- <xsl:if test="title!=''">
55
- <xsl:value-of select="xday"/>
56
- </xsl:if>
57
- </div>
58
58
 
59
- <div><xsl:value-of select="bankholiday"/></div>
60
- <div><xsl:value-of select="event"/></div>
59
+ <div><xsl:value-of select="xday"/></div>
60
+ <div><xsl:value-of select="bankholiday"/></div>
61
+ <div><xsl:value-of select="event"/></div>
61
62
 
62
- </xsl:element>
63
63
  </xsl:template>
64
64
 
65
+ <xsl:template match="records/entry">
66
+ <xsl:apply-templates select="summary"/>
67
+ </xsl:template>
68
+
69
+ <xsl:template match="entry/summary">
70
+ <strong><xsl:value-of select="title"/></strong>
71
+ </xsl:template>
65
72
 
66
73
  </xsl:stylesheet>
@@ -8,30 +8,26 @@ require 'nokogiri'
8
8
  require 'chronic_duration'
9
9
  require 'chronic_cron'
10
10
 
11
- MINUTE = 60
12
- HOUR = MINUTE * 60
13
- DAY = HOUR * 24
14
- WEEK = DAY * 7
15
- MONTH = DAY * 30
16
11
 
12
+ MONTH = DAY * 30
17
13
 
18
14
 
19
15
  h = {
20
16
  calendar: 'calendar[year]',
21
17
  month: 'month[n, title]',
22
18
  week: 'week[n]',
23
- day: 'day[n, event, date, bankholiday, title]',
19
+ day: 'day[sdate, xday, event, bankholiday, title]',
24
20
  entry: 'entry[time_start, time_end, duration, title]'
25
21
  }
26
- visual_schema = %i(calendar month week day entry).map{|x| h[x]}.join '/'
22
+ visual_schema = h.values.join '/'
27
23
  PolyrexObjects.new(visual_schema)
28
24
 
29
25
  module LIBRARY
30
26
 
31
27
  def fetch_file(filename)
32
-
28
+
33
29
  lib = File.dirname(__FILE__)
34
- File.read filename
30
+ File.read filename
35
31
  end
36
32
 
37
33
  def generate_webpage(xml, xsl)
@@ -84,14 +80,14 @@ class PolyrexObjects::Month
84
80
  month_layout_css = fetch_file self.css_layout
85
81
  month_css = fetch_file self.css_style
86
82
 
87
- File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
88
- File.open('month.xsl','w'){|f| f.write month_xsl }
83
+ File.write 'self.xml', self.to_xml(pretty: true)
84
+ File.write 'month.xsl', month_xsl
89
85
  #html = Rexslt.new(month_xsl, self.to_xml).to_xml
90
86
 
91
87
  # add a css selector for the current day
92
88
  date = Time.now.strftime("%Y-%b-%d")
93
89
  doc = Rexle.new self.to_xml
94
- e = doc.root.element("records/week/records/day/summary[date='#{date}']")
90
+ e = doc.root.element("records/week/records/day/summary[sdate='#{date}']")
95
91
  e.add Rexle::Element.new('css_style').add_text('selected')
96
92
 
97
93
  html = generate_webpage doc.xml, month_xsl
@@ -117,8 +113,8 @@ class PolyrexObjects::Week
117
113
  week_layout_css = fetch_file 'week_layout.css'
118
114
  week_css = fetch_file 'week.css'
119
115
 
120
- File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
121
- File.open('week.xsl','w'){|f| f.write week_xsl }
116
+ File.write 'self.xml', self.to_xml(pretty: true)
117
+ File.write 'week.xsl', week_xsl
122
118
  #html = Rexslt.new(week_xsl, self.to_xml).to_xml
123
119
  #html = xsltproc 'week_calendar.xsl', self.to_xml
124
120
 
@@ -135,6 +131,21 @@ class PolyrexObjects::Week
135
131
  end
136
132
  end
137
133
 
134
+ class PolyrexObjects::Day
135
+
136
+ def date()
137
+ Date.parse(self.sdate)
138
+ end
139
+
140
+ def wday()
141
+ self.date.wday
142
+ end
143
+
144
+ def day()
145
+ self.date.day
146
+ end
147
+ end
148
+
138
149
  class PolyrexCalendar
139
150
  include LIBRARY
140
151
 
@@ -146,15 +157,14 @@ class PolyrexCalendar
146
157
  opts = {year: Time.now.year.to_s}.merge(options)
147
158
  @year = opts[:year]
148
159
 
149
- @h = {
160
+ h = {
150
161
  calendar: 'calendar[year]',
151
162
  month: 'month[n, title]',
152
163
  week: 'week[n]',
153
- day: 'day[n, event, date, bankholiday]',
164
+ day: 'day[sdate, xday, event, bankholiday]',
154
165
  entry: 'entry[time_start, time_end, duration, title]'
155
166
  }
156
- schema = %i(calendar month day entry).map{|x| @h[x]}.join '/'
157
- #@visual_schema = %i(calendar month week day entry).map{|x| @h[x]}.join '/'
167
+ schema = %i(calendar month day entry).map{|x| h[x]}.join '/'
158
168
 
159
169
 
160
170
  if calendar_file then
@@ -174,13 +184,16 @@ class PolyrexCalendar
174
184
 
175
185
  @polyrex.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create|
176
186
  days.each do |x|
177
- create.day n: x.day, wday: x.wday, date: x.strftime("%Y-%b-%d")
187
+ create.day sdate: x.strftime("%Y-%b-%d"), xday: x.day.to_s
178
188
  end
179
189
  end
180
190
  end
181
191
 
182
192
  end
183
193
 
194
+ visual_schema = h.values.join '/'
195
+ PolyrexObjects.new(visual_schema)
196
+
184
197
  @xsl = fetch_file 'calendar.xsl'
185
198
  @css = fetch_file 'layout.css'
186
199
 
@@ -210,7 +223,7 @@ class PolyrexCalendar
210
223
 
211
224
  px = Polyrex.new(@schema, id_counter: @id)
212
225
  px.summary.year = @year
213
- (1..12).each {|n| px.add self.month(n, strict: true) }
226
+ (1..12).each {|n| px.add self.month(n, moday_week: true) }
214
227
 
215
228
  px.xslt = 'kplanner.xsl'
216
229
  px.css_layout = 'monthday_layout.css'
@@ -236,46 +249,30 @@ class PolyrexCalendar
236
249
 
237
250
  end
238
251
 
239
- def month(m, strict: false)
252
+ def month(m, monday_week: false)
240
253
 
241
- cal_month = @polyrex.records[m-1]
254
+ if monday_week == true
242
255
 
243
- if strict == true then
256
+ pxmonth = make_month(m) do |a, wday|
244
257
 
245
- days_in_month = cal_month.xpath('records/week/records/.')\
246
- .select {|x| Date.parse(x.text('summary/date')).month == m}
258
+ # Monday start
259
+ # wdays: 1 = Monday, 0 = Sunday
247
260
 
248
- doc_month = Rexle.new cal_month.to_xml
249
- records = doc_month.root.element 'records'
250
- records.insert_before Rexle::Element.new('records')
261
+ r = case wday
251
262
 
252
- records.delete
263
+ # the 1st day of the month is a Monday, add no placeholders
264
+ when 1 then a
253
265
 
254
- pxmonth = PolyrexObjects::Month.new doc_month.root
266
+ # the 1st day is a Sunday, add 6 placeholders before that day
267
+ when 0 then Array.new(6) + a
255
268
 
256
- a = days_in_month
257
- i = a[0].text('summary/wday').to_i
258
-
259
- a2 = if i > 1 then
260
- Array.new(i - 1) + a
261
- elsif i < 1 then
262
- Array.new(6) + a
263
- else
264
- a
265
- end
266
-
267
- a2.each_slice(7) do |days_in_week|
268
-
269
- pxweek = PolyrexObjects::Week.new \
270
- Rexle.new('<week><summary/><records/></week>').root
269
+ # add a few placeholders before the 1st day
270
+ else Array.new(wday - 1) + a
271
+ end
271
272
 
272
- days_in_week.each do |day|
273
+ r
273
274
 
274
- day = Rexle.new("<day><summary/><records/></day>") unless day
275
- pxweek.add PolyrexObjects::Day.new(day.root)
276
- end
277
275
 
278
- pxmonth.add pxweek
279
276
  end
280
277
 
281
278
  pxmonth.xslt = 'monthday_calendar.xsl'
@@ -284,11 +281,29 @@ class PolyrexCalendar
284
281
  pxmonth
285
282
 
286
283
  else
287
- cal_month.xslt = 'month_calendar.xsl'
288
- cal_month.css_layout = 'month_layout.css'
289
- cal_month.css_style = 'month.css'
290
284
 
291
- cal_month
285
+ pxmonth = make_month(m) do |a, wday|
286
+
287
+ # Sunday start
288
+ # wdays: 1 = Monday, 0 = Sunday
289
+
290
+ r = case wday
291
+
292
+ # the 1st day of the month is a Sunday, add no placeholders
293
+ when 0 then a
294
+
295
+ # add a few placeholders before the 1st day
296
+ else Array.new(6 - wday) + a
297
+ end
298
+
299
+ r
300
+
301
+ end
302
+
303
+ pxmonth.xslt = 'month_calendar.xsl'
304
+ pxmonth.css_layout = 'month_layout.css'
305
+ pxmonth.css_style = 'month.css'
306
+ pxmonth
292
307
  end
293
308
 
294
309
  end
@@ -321,6 +336,7 @@ class PolyrexCalendar
321
336
 
322
337
  m = DateTime.now.month
323
338
  thisweek = self.month(m).records.find do |week|
339
+
324
340
  now = DateTime.now
325
341
  #week_no = now.cwday < 7 ? now.cweek - 1: now.cweek
326
342
  week_no = now.cweek
@@ -385,8 +401,7 @@ class PolyrexCalendar
385
401
 
386
402
  polyrex.records.each do |day|
387
403
 
388
- d1 = Date.parse(day.date)
389
- sd = d1.strftime("%Y-%b-%d ")
404
+ sd = day.date.strftime("%Y-%b-%d ")
390
405
  m,w,i = @day[d1]
391
406
 
392
407
  cal_day = @polyrex.records[m].week[w].day[i]
@@ -443,6 +458,58 @@ class PolyrexCalendar
443
458
  end
444
459
 
445
460
  end
461
+
462
+ def make_month(m)
463
+
464
+ cal_month = @polyrex.records[m-1]
465
+ days_in_month = cal_month.records
466
+ pxmonth = cal_month.clone
467
+ pxmonth.records.each(&:delete)
468
+
469
+ a = days_in_month
470
+
471
+ i = a[0].wday
472
+
473
+ a2 = yield(a, i)
474
+
475
+ a2.each_slice(7) do |days_in_week|
476
+
477
+ pxweek = PolyrexObjects::Week.new
478
+
479
+ days_in_week.each do |day|
480
+
481
+ new_day = day ? day.deep_clone : PolyrexObjects::Day.new
482
+ pxweek.add new_day
483
+ end
484
+
485
+ pxmonth.add pxweek
486
+ end
487
+
488
+ week1 = pxmonth.week[0]
489
+
490
+ other_days = week1.day.select{|day| day.sdate.empty? }
491
+ start_date = week1.day[other_days.length].date
492
+
493
+ other_days.reverse.each.with_index do |day, i|
494
+ day.sdate = (start_date - (i+1)).strftime("%Y %b %d")
495
+ day.xday = day.date.day.to_s
496
+ end
497
+
498
+ last_week = pxmonth.week[-1]
499
+
500
+ gap = 7 - last_week.records.length
501
+ end_date = last_week.day.last.date
502
+
503
+ gap.times do |i|
504
+
505
+ day = PolyrexObjects::Day.new
506
+ day.sdate = (end_date + (i+1)).strftime("%Y %b %d")
507
+ day.xday = day.date.day.to_s
508
+ last_week.add day
509
+ end
510
+
511
+ pxmonth
512
+ end
446
513
 
447
514
  def ordinal(val)
448
515
  (10...20).include?(val) ? \
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.0
4
+ version: 0.3.1
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-17 00:00:00.000000000 Z
32
+ date: 2014-01-18 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: polyrex
metadata.gz.sig CHANGED
Binary file