calendar_view 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,16 +1,16 @@
1
1
  ## Introduction
2
- _Calendar view_ is a rails plugin which extends application of calendar view.
2
+ _Calendar view_ is a rails plugin which extends application of calendar views.
3
3
 
4
4
  ## Requirements
5
5
 
6
- Plagin was built as Rails 3 Engine plugin.
6
+ Plugin was built as Rails 3 Engine plugin.
7
7
 
8
8
  ## Usage
9
9
 
10
10
  Add to Gemfile of application:
11
11
 
12
12
  ```ruby
13
- gem "calendar_view"
13
+ gem "calendar_view", "~> 0.0.3"
14
14
  ```
15
15
 
16
16
  than
@@ -19,9 +19,33 @@ than
19
19
  bundle install
20
20
  ```
21
21
 
22
+ to install gem.
23
+
22
24
  In views of Your application add:
23
25
 
24
26
  ```ruby
25
- <%= calendar_cube %>
27
+ <% 1.upto(6) do |i| %>
28
+ <%= calendar_square(:month=>i,:highlight_between => Date.new(2011,9,19)..Date.new(2011,9,25)) %>
29
+ <% end %>
30
+ <%= calendar_square %>
31
+ <%= calendar_square(:month_delta=>-12,:year_delta=>-1) %>
32
+ <%= calendar_square(:month_delta=>12) %>
33
+ <%= calendar_square(:month=>12,:highlight_date => Date.new(2011,12,2)) %>
34
+ <%= calendar_square(:month=>1,:first_wday=>0) %>
35
+ <%= calendar_square(
36
+ :month => 1, # month
37
+ :year => 2011, # year
38
+ :month_delta => -1, # relative to month
39
+ :year_delta => -2, # relative to year
40
+ :first_wday => 0, # start of week 0 - Sunday, 1 - Monday
41
+ :highlight_date => Date.new(2011,12,2), # highlight specific day
42
+ :highlight_day => 2, # highlight specific day
43
+ :highlight_month => 12, # highlight specific day
44
+ :highlight_year => 2011, # highlight specific day
45
+ :highlight_between => Date.new(2011,12,1)..Date.new(2011,12,10) # highlight range of days
46
+ ) %>
26
47
  ```
27
48
 
49
+ Customize _public/stylesheets_ and copy to Your public directory.
50
+
51
+
@@ -1,56 +1,102 @@
1
1
  module CalendarViewHelper
2
- def calendar_cube(options={})
2
+
3
+ def color_follow_day(today,follow_day,highlight)
4
+ day = follow_day.day
5
+ c = ""
6
+ c << "this " if (highlight.class.eql?(Range) && highlight.include?(follow_day)) || follow_day == highlight
7
+ c << "today " if follow_day == today
8
+ c << "weekend " if [0,6].include?(follow_day.wday)
9
+ "<td class=\"#{c}\">#{day}</td>"
10
+ end
11
+
12
+ def wdays_names(first_wday)
13
+ html = ""
14
+ first_wday.upto(first_wday+6) do |i|
15
+ html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[i == 7 ? 0 : i]}</td>"
16
+ end
17
+ html
18
+ end
19
+
20
+ def calendar_square(options={})
21
+
3
22
  now = DateTime.now
4
- first = Date.new(now.year,now.month,1)
5
- last = Date.new(now.year,now.month,-1)
6
- curr_week = first.cweek
7
- html = "<h3>"
8
- html << t(:month_names,:scope=>:date)[now.month]
9
- html << "</h3><div class=\"content\">"
10
- html << "<table class=\"side_calendar width100\">"
11
-
12
- html << "<tr><td></td>"
13
- 1.upto(6) do |i|
14
- html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[i]}</td>"
23
+ month = options[:month] ? options[:month] : now.month
24
+ year = options[:year] ? options[:year] : now.year
25
+
26
+ month_delta = options[:month_delta] ? options[:month_delta] : 0
27
+ year_delta = options[:year_delta] ? options[:year_delta] : 0
28
+
29
+ highlight = options[:highlight_date] ? options[:highlight_date] : nil
30
+ if options[:highlight_day] && options[:highlight_month] && options[:highlight_year]
31
+ highlight = Date.new(options[:highlight_year],options[:highlight_month],options[:highlight_day])
15
32
  end
16
- html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[0]}</td>"
17
- html << "</tr>"
33
+ highlight = options[:highlight_between] if options[:highlight_between]
34
+
35
+ month = month + month_delta
36
+ year = year + year_delta
37
+ delta = month.divmod(12)
38
+
39
+ if delta[1].zero?
40
+ year = year + delta[0] -1
41
+ month = 12
42
+ else
43
+ year = year + delta[0]
44
+ month = delta[1]
45
+ end
46
+
47
+ first_wday = options[:first_wday] == 0 ? 0 : 1
48
+ last_wday = first_wday == 0 ? 6 : 0
49
+ first = Date.new(year,month,1)
50
+ last = Date.new(year,month,-1)
51
+ today = Date.new(now.year,now.month,now.day)
18
52
 
53
+ html = ""
54
+ html << "<div class=\"calendar square\">"
55
+ html << "<h3>"
56
+ html << t(:month_names,:scope=>:date)[month]
57
+ html << " #{year}" if year != now.year
58
+ html << "</h3>"
59
+ html << "<div class=\"content\">"
60
+ html << "<table>"
19
61
 
20
- html << "<tr>"
21
- html << "<td class=\"week\">#{first.cweek}</td>"
62
+ html << "<tr><td class=\"outside\">&nbsp;</td>"
63
+ html << wdays_names(first_wday)
64
+ html << "</tr>"
22
65
 
23
- (first.wday-1).downto(1) do |i|
24
- prev = first - i
25
- html << "<td class=\"off\">#{prev.day}</td>"
66
+ if first.wday != first_wday
67
+ (first_wday == 0 ? (first.wday == 0 ? 7 : first.wday) : (first.wday == 0 ? 7 : first.wday) - 1).downto(1) do |i|
68
+ prev = first - i
69
+ logger.custom(i,prev.to_s)
70
+ if prev.wday == first_wday
71
+ html << "<tr>"
72
+ html << "<td class=\"weeknum\">#{prev.cweek}</td>"
73
+ end
74
+ html << "<td class=\"outside\">#{prev.day}</td>"
75
+ end
26
76
  end
27
77
 
28
78
  (first.day).upto(last.day) do |i|
29
- curr = Date.new(now.year,now.month,i)
30
- if curr.wday == 1
31
- html << "</tr>"
79
+ follow_day = Date.new(year,month,i)
80
+ if follow_day.wday == first_wday
32
81
  html << "<tr>"
33
- curr_week += 1
34
- html << "<td class=\"week\">#{curr_week}</td>"
82
+ html << "<td class=\"weeknum\">#{follow_day.cweek}</td>"
35
83
  end
36
- if now.day == i
37
- html << "<td class=\"today\">#{i}</td>"
38
- else
39
- if curr.wday == 0 || curr.wday == 6
40
- html << "<td class=\"weekend\">#{i}</td>"
41
- else
42
- html << "<td>#{i}</td>"
43
- end
84
+ html << color_follow_day(today,follow_day,highlight)
85
+ if follow_day.wday == last_wday
86
+ html << "</tr>"
44
87
  end
45
88
  end
46
89
 
47
- 1.upto(7-last.wday) do |i|
48
- post = last + i
49
- html << "<td class=\"off\">#{post.day}</td>"
90
+ if last_wday != last.wday
91
+ 1.upto(7-(first_wday == 0 ? last.wday+1 : last.wday)) do |i|
92
+ post = last + i
93
+ html << "<td class=\"outside\">#{post.day}</td>"
94
+ end
50
95
  end
51
-
52
96
  html << "</tr>"
53
- html << "</table></div>"
54
- html
97
+
98
+ html << "</table></div></div>"
99
+ html.html_safe
55
100
  end
101
+
56
102
  end
@@ -1,3 +1,3 @@
1
1
  module CalendarView
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,57 @@
1
+ div.calendar {
2
+ margin-bottom: 10px;
3
+ background: none repeat scroll 0 0 #FFFFFF;
4
+ border-bottom-left-radius: 4px;
5
+ border-bottom-right-radius: 4px;
6
+ border-top-left-radius: 4px;
7
+ border-top-right-radius: 4px;
8
+ }
9
+
10
+ div.calendar h3 {
11
+ background: none repeat scroll 0 0 #5E634E;
12
+ border-bottom: 6px solid #DACF77;
13
+ color: #FFFFFF;
14
+ }
15
+
16
+ div.calendar div.content {
17
+ padding: 4px;
18
+ }
19
+
20
+ div.calendar table {
21
+ width: 100%;
22
+ }
23
+
24
+ div.calendar td {
25
+ text-align: right;
26
+ background-color: #EFF3E4;
27
+ padding: 2px;
28
+ }
29
+
30
+ div.calendar td.wday, div.calendar td.weeknum {
31
+ color: white;
32
+ background-color: #DACF77;
33
+ font-weight: bold;
34
+ text-align: center;
35
+ }
36
+
37
+ div.calendar td.weekend {
38
+ color: white;
39
+ background-color: #5E634E;
40
+ }
41
+
42
+ div.calendar td.outside {
43
+ background-color: white;
44
+ }
45
+
46
+ div.calendar td.this {
47
+ font-weight: bold;
48
+ font-size: 13px;
49
+ text-decoration: underline;
50
+ }
51
+
52
+ div.calendar td.today {
53
+ font-weight: bold;
54
+ color: red;
55
+ font-size: 13px;
56
+ text-decoration: underline;
57
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calendar_view
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Wojciech Todryk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-20 00:00:00 Z
18
+ date: 2011-09-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails
@@ -51,6 +51,7 @@ files:
51
51
  - calendar_view.gemspec
52
52
  - lib/calendar_view.rb
53
53
  - lib/calendar_view/version.rb
54
+ - public/stylesheets/calendar_olive.css
54
55
  homepage: https://github.com/musashimm/calendar_view
55
56
  licenses: []
56
57