polyrex-calendar 0.1.3 → 0.1.4

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.
data/lib/calendar.xsl ADDED
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
+ <xsl:output method="xml" indent="yes" />
4
+
5
+ <xsl:template match="calendar">
6
+
7
+ <html lang="en">
8
+
9
+ <head>
10
+ <title><xsl:value-of select="summary/year"/> Calendar | generated by Polrex-Calendar</title>
11
+ <link rel="stylesheet" href="xlayout.css"/>
12
+ </head>
13
+
14
+ <body>
15
+ <div id="wrap">
16
+ <h1><xsl:value-of select="summary/year"/></h1>
17
+ <xsl:apply-templates select="records"/>
18
+ </div>
19
+ </body>
20
+ </html>
21
+
22
+ </xsl:template>
23
+
24
+ <xsl:template match="records/month">
25
+ <div class="table">
26
+ <table border="1">
27
+ <xsl:apply-templates select="summary"/>
28
+ <tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>
29
+ <xsl:apply-templates select="records"/>
30
+ </table>
31
+ </div>
32
+ </xsl:template>
33
+
34
+ <xsl:template match="month/summary">
35
+ <caption><xsl:value-of select="name"/></caption>
36
+ </xsl:template>
37
+
38
+ <xsl:template match="records/week">
39
+ <xsl:apply-templates select="summary"/>
40
+ <xsl:element name="tr">
41
+ <xsl:apply-templates select="records"/>
42
+ </xsl:element>
43
+ </xsl:template>
44
+
45
+ <xsl:template match="week/summary">
46
+
47
+ </xsl:template>
48
+
49
+ <xsl:template match="records/day">
50
+ <xsl:apply-templates select="summary"/>
51
+ <xsl:apply-templates select="records"/>
52
+ </xsl:template>
53
+
54
+ <xsl:template match="day/summary">
55
+ <td><xsl:value-of select="xday"/></td>
56
+ </xsl:template>
57
+
58
+ </xsl:stylesheet>
data/lib/layout.css ADDED
@@ -0,0 +1,30 @@
1
+ body {background-color: transparent }
2
+
3
+ #wrap {
4
+ background-color: transparent;
5
+ border: 1px solid transparent;
6
+ margin: 0 auto;
7
+ margin-bottom: 0.6em;
8
+ overflow: hidden;
9
+ padding-bottom: 4em;
10
+ width: 750px;
11
+ }
12
+
13
+ #wrap h1 {
14
+ background-color: transparent;
15
+ margin: 0.5em;
16
+ padding: 0.2em 0.4em;
17
+ }
18
+
19
+ #wrap .table {
20
+ background-color: transparent;
21
+ float: left;
22
+ height: 13em;
23
+ padding: 1em 0.8em;
24
+ margin: 0.5em;
25
+ }
26
+
27
+ #wrap table {background-color: transparent; }
28
+ #wrap table td {text-align: right}
29
+
30
+
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # file: polyrex-calendar.rb
4
+
5
+ require 'polyrex'
6
+ require 'date'
7
+ require 'nokogiri'
8
+
9
+ class PolyrexCalendar
10
+
11
+ def initialize(year=nil)
12
+ @year = year ? year : Time.now.year
13
+ generate_calendar
14
+ end
15
+
16
+ def to_a()
17
+ @a
18
+ end
19
+
20
+ def to_xml()
21
+ @xml
22
+ end
23
+
24
+ def to_webpage()
25
+
26
+ # transform the xml to html
27
+ lib = File.join(File.dirname(__FILE__), '..', 'lib')
28
+
29
+ doc = Nokogiri::XML(@xml)
30
+ xslt = Nokogiri::XSLT(File.open(lib + '/calendar.xsl','r').read)
31
+ html = xslt.transform(doc).to_xml
32
+ css = File.open(lib + '/layout.css','r').read
33
+
34
+ {'calendar.html' => html, 'layout.css' => css}
35
+ end
36
+
37
+ private
38
+
39
+ def generate_calendar()
40
+
41
+ d = Date.parse(@year.to_s + '-Jan-01')
42
+ a = []
43
+ (a << d; d += 1) while d.year == Time.now.year
44
+
45
+ months = a.group_by(&:month).map do |key, month|
46
+ i = month.index(month.detect{|x| x.wday == 0})
47
+ unless i == 0 then
48
+ weeks = [month.slice!(0,i)] + month.each_slice(7).to_a
49
+ (weeks[0] = ([nil] * 6 + weeks[0]).slice(-7..-1))
50
+ else
51
+ weeks = month.each_slice(7).to_a
52
+ end
53
+
54
+ weeks
55
+ end
56
+
57
+ @a = months
58
+
59
+ calendar = Polyrex.new('calendar[year]/month[no,name]/week[no, rel_no]/day[wday, xday, name, event]')
60
+ year_start = months[0][0][-1]
61
+ calendar.summary.year = year_start.year.to_s
62
+ old_year_week = year_start.prev_day.cweek
63
+
64
+ week_i = 0
65
+
66
+ months.each_with_index do |month,i|
67
+
68
+ calendar.create.month no: (i+1).to_s, name: Date::MONTHNAMES[i+1] do |create|
69
+ month.each_with_index do |week,j|
70
+
71
+ week_s = (week_i == 0 ? old_year_week : week_i).to_s
72
+ create.week rel_no: (j+1).to_s, no: week_s do |create|
73
+ week.each_with_index do |x,k|
74
+
75
+ if x then
76
+ week_i += 1 if x.wday == 6
77
+ h = {wday: x.wday.to_s, xday: x.day.to_s, name: Date::DAYNAMES[k]}
78
+ else
79
+ h = {}
80
+ end
81
+ create.day(h)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ @xml = calendar.to_xml pretty: true
89
+
90
+ end
91
+ 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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -41,6 +41,9 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
+ - lib/polyrex-calendar.rb~
45
+ - lib/calendar.xsl
46
+ - lib/layout.css
44
47
  - lib/polyrex-calendar.rb
45
48
  has_rdoc: true
46
49
  homepage: