polyrex-calendar 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,18 @@ class PolyrexCalendar
18
18
  @css = File.open(lib + '/layout.css','r').read
19
19
  @month_xsl = File.open(lib + '/month_calendar.xsl','r').read
20
20
  @month_css = File.open(lib + '/month_layout.css','r').read
21
+
22
+ PolyrexObjects::Month.class_eval {
23
+ def to_webpage()
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
31
+ }
32
+
21
33
  end
22
34
 
23
35
  def to_a()
@@ -42,16 +54,11 @@ class PolyrexCalendar
42
54
  end
43
55
 
44
56
  def month(m)
45
- monthx = @polyrex.records[m-1]
46
- def monthx.to_webpage()
47
- lib = File.dirname(__FILE__)
48
- month_xsl = File.open(lib + '/month_calendar.xsl','r').read
49
- month_css = File.open(lib + '/month_layout.css','r').read
50
- doc = Nokogiri::XML(self.to_xml); xslt = Nokogiri::XSLT(month_xsl)
51
- html = xslt.transform(doc).to_xml
52
- {self.name.downcase[0..2] + '_calendar.html' => html, 'month_layout.css' => month_css}
53
- end
54
- monthx
57
+ @polyrex.records[m-1]
58
+ end
59
+
60
+ def months
61
+ @polyrex.records
55
62
  end
56
63
 
57
64
  private
@@ -83,7 +90,7 @@ class PolyrexCalendar
83
90
 
84
91
  @a = months
85
92
 
86
- @polyrex = Polyrex.new('calendar[year]/month[no,name,year]/week[no, rel_no]/day[wday, xday, name, event]')
93
+ @polyrex = Polyrex.new('calendar[year]/month[no,name,year]/week[no, rel_no]/day[wday, xday, name, event, date]')
87
94
  year_start = months[0][0][-1]
88
95
  @polyrex.summary.year = @year
89
96
  old_year_week = (year_start - 7).cweek
@@ -101,8 +108,11 @@ class PolyrexCalendar
101
108
 
102
109
  if x then
103
110
  week_i += 1 if x.wday == 6
104
- h = {wday: x.wday.to_s, xday: x.day.to_s, name: Date::DAYNAMES[k]}
111
+ h = {wday: x.wday.to_s, xday: x.day.to_s, name: Date::DAYNAMES[k], \
112
+ date: x.strftime("%Y-%b-%d")}
105
113
  else
114
+ #if blank find the nearest date in the week and calculate this date
115
+ # check right and if nothing then it'sat the end of the month
106
116
  h = {}
107
117
  end
108
118
  create.day(h)
@@ -8,11 +8,16 @@ require 'nokogiri'
8
8
 
9
9
  class PolyrexCalendar
10
10
 
11
- attr_accessor :xsl
11
+ attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
12
12
 
13
13
  def initialize(year=nil)
14
14
  @year = year ? year : Time.now.year
15
15
  generate_calendar
16
+ lib = File.dirname(__FILE__)
17
+ @xsl = File.open(lib + '/calendar.xsl','r').read
18
+ @css = File.open(lib + '/layout.css','r').read
19
+ @month_xsl = File.open(lib + '/month_calendar.xsl','r').read
20
+ @month_css = File.open(lib + '/month_layout.css','r').read
16
21
  end
17
22
 
18
23
  def to_a()
@@ -20,22 +25,35 @@ class PolyrexCalendar
20
25
  end
21
26
 
22
27
  def to_xml()
23
- @xml
28
+ @polyrex.to_xml pretty: true
24
29
  end
25
30
 
26
- def to_webpage()
27
-
28
- # transform the xml to html
29
- lib = File.dirname(__FILE__)
30
-
31
- doc = Nokogiri::XML(@xml)
32
- xslt = Nokogiri::XSLT(File.open(lib + '/calendar.xsl','r').read)
33
- html = xslt.transform(doc).to_xml
34
- css = File.open(lib + '/layout.css','r').read
35
-
36
- {'calendar.html' => html, 'layout.css' => css}
31
+ def to_webpage()
32
+ html = generate_webpage(@polyrex.to_xml, @xsl)
33
+ {'calendar.html' => html, 'layout.css' => @css}
37
34
  end
38
35
 
36
+ def import_events(dynarex)
37
+ dynarex.flat_records.each do |event|
38
+ m,w,i = @day[Date.parse(event[:date])]
39
+ @polyrex.records[m].week[w].day[i].event = event[:title]
40
+ end
41
+ self
42
+ end
43
+
44
+ def month(m)
45
+ monthx = @polyrex.records[m-1]
46
+ def monthx.to_webpage()
47
+ lib = File.dirname(__FILE__)
48
+ month_xsl = File.open(lib + '/month_calendar.xsl','r').read
49
+ month_css = File.open(lib + '/month_layout.css','r').read
50
+ doc = Nokogiri::XML(self.to_xml); xslt = Nokogiri::XSLT(month_xsl)
51
+ html = xslt.transform(doc).to_xml
52
+ {self.name.downcase[0..2] + '_calendar.html' => html, 'month_layout.css' => month_css}
53
+ end
54
+ monthx
55
+ end
56
+
39
57
  private
40
58
 
41
59
  def generate_calendar()
@@ -56,18 +74,25 @@ class PolyrexCalendar
56
74
  weeks
57
75
  end
58
76
 
77
+ @day = {}
78
+ months.each_with_index do |month,m|
79
+ month.each_with_index do |weeks,w|
80
+ weeks.each_with_index{|d,i| @day[d] = [m,w,i]}
81
+ end
82
+ end
83
+
59
84
  @a = months
60
85
 
61
- calendar = Polyrex.new('calendar[year]/month[no,name]/week[no, rel_no]/day[wday, xday, name, event]')
86
+ @polyrex = Polyrex.new('calendar[year]/month[no,name,year]/week[no, rel_no]/day[wday, xday, name, event]')
62
87
  year_start = months[0][0][-1]
63
- calendar.summary.year = year_start.year.to_s
64
- old_year_week = year_start.prev_day.cweek
88
+ @polyrex.summary.year = @year
89
+ old_year_week = (year_start - 7).cweek
65
90
 
66
91
  week_i = 0
67
92
 
68
93
  months.each_with_index do |month,i|
69
94
 
70
- calendar.create.month no: (i+1).to_s, name: Date::MONTHNAMES[i+1] do |create|
95
+ @polyrex.create.month no: (i+1).to_s, name: Date::MONTHNAMES[i+1], year: @year do |create|
71
96
  month.each_with_index do |week,j|
72
97
 
73
98
  week_s = (week_i == 0 ? old_year_week : week_i).to_s
@@ -87,7 +112,15 @@ class PolyrexCalendar
87
112
  end
88
113
  end
89
114
 
90
- @xml = calendar.to_xml pretty: true
115
+ end
116
+
117
+ def generate_webpage(xml, xsl)
118
+
119
+ # transform the xml to html
120
+ doc = Nokogiri::XML(xml)
121
+ xslt = Nokogiri::XSLT(xsl)
122
+ html = xslt.transform(doc).to_xml
123
+ html
91
124
 
92
125
  end
93
126
  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.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors: []
7
7