simple_calendar 0.0.5 → 0.0.6
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/README.md +27 -6
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +21 -14
- metadata +3 -3
data/README.md
CHANGED
@@ -4,16 +4,21 @@ Simple Calendar
|
|
4
4
|
This is a small Rails 3.x gem for creating a quick and clean table calendar.
|
5
5
|
Theming is up to you, but it works nicely with Twitter Bootstrap.
|
6
6
|
|
7
|
+
Thanks to Josh Chernoff for an early rewrite of the calendar generation
|
8
|
+
code.
|
9
|
+
|
7
10
|
Installation
|
8
11
|
------------
|
9
12
|
|
10
13
|
Just add this into your Gemfile followed by a bundle install:
|
11
14
|
|
12
|
-
gem "simple_calendar", "~> 0.0.
|
15
|
+
gem "simple_calendar", "~> 0.0.5"
|
13
16
|
|
14
17
|
Usage
|
15
18
|
-----
|
16
19
|
|
20
|
+
####Model
|
21
|
+
|
17
22
|
Here we have a model called Event with the start_time attribute that we
|
18
23
|
will be using with simple_calendar.
|
19
24
|
|
@@ -21,6 +26,15 @@ will be using with simple_calendar.
|
|
21
26
|
has_calendar
|
22
27
|
end
|
23
28
|
|
29
|
+
has_calendar has options that can be passed to it for configuration:
|
30
|
+
|
31
|
+
has_calendar :start_time => :my_start_column
|
32
|
+
|
33
|
+
The `start_time` option is the field for the start time of the event. This will use
|
34
|
+
`my_start_column` to determine which day to render the event on.
|
35
|
+
|
36
|
+
####Views
|
37
|
+
|
24
38
|
We query the events we want to display as usual, and then render the
|
25
39
|
calendar in the view like so:
|
26
40
|
|
@@ -32,13 +46,20 @@ When the calendar is rendering, it yields to the block to allow you to
|
|
32
46
|
render whatever you like for the item. In this example, I use the title
|
33
47
|
attribute on the event with a link to the event.
|
34
48
|
|
35
|
-
|
49
|
+
You may even pass options to calendar renderer to customize it's behavior
|
36
50
|
|
37
|
-
|
51
|
+
<%= calendar @events, {:prev_text=>"prev", :next_text=>"next"} do |event| %>
|
52
|
+
<div><%= link_to event.title, event %></div>
|
53
|
+
<% end %>
|
54
|
+
|
55
|
+
This time calendar will use prev and next as labels for previous and next month links (which are normally set to &laquo; («) and &raquo; (»)
|
38
56
|
|
39
|
-
|
40
|
-
my_start_column to determine which day to render the event on.
|
57
|
+
Possible options:
|
41
58
|
|
59
|
+
:year # current year, default: from params or current year
|
60
|
+
:month # current month, default: from params or current month
|
61
|
+
:prev_text # previous month link text, default: «
|
62
|
+
:next_text # next month link text, default: »
|
42
63
|
|
43
64
|
CSS
|
44
65
|
---
|
@@ -47,7 +68,7 @@ You will probably want to customize the height of the calendar so that
|
|
47
68
|
all the rows are the same. You can do this by adding the following line
|
48
69
|
to your css:
|
49
70
|
|
50
|
-
|
71
|
+
.calendar td { height: 100px; width: 14.28%; }
|
51
72
|
|
52
73
|
By default simple_calendar will set the calendar to use .bordered-table
|
53
74
|
and .calendar classes.
|
@@ -1,23 +1,30 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
|
-
def calendar(events, &block)
|
5
|
-
|
4
|
+
def calendar(events, options={}, &block)
|
5
|
+
opts = {
|
6
|
+
:year => (params[:year] || Time.zone.now.year).to_i,
|
7
|
+
:month => (params[:month] || Time.zone.now.month).to_i,
|
8
|
+
:prev_text => raw("«"),
|
9
|
+
:next_text => raw("»")
|
10
|
+
}
|
11
|
+
options.reverse_merge! opts
|
12
|
+
selected_month = Date.civil(options[:year], options[:month])
|
6
13
|
current_date = Date.today
|
7
14
|
range = build_range selected_month
|
8
15
|
month_array = build_month range
|
9
16
|
|
10
|
-
draw_calendar(selected_month, month_array, current_date, events, block)
|
17
|
+
draw_calendar(selected_month, month_array, current_date, events, options, block)
|
11
18
|
end
|
12
19
|
|
13
20
|
private
|
14
21
|
|
15
22
|
def build_range(selected_month)
|
16
23
|
start_date = selected_month.beginning_of_month
|
17
|
-
start_date = start_date.sunday? ? start_date : start_date.beginning_of_week
|
24
|
+
start_date = start_date.sunday? ? start_date : start_date.beginning_of_week(:sunday)
|
18
25
|
|
19
26
|
end_date = selected_month.end_of_month
|
20
|
-
end_date = end_date.
|
27
|
+
end_date = end_date.saturday? ? end_date : end_date.end_of_week(:sunday)
|
21
28
|
|
22
29
|
date_range = (start_date..end_date).to_a
|
23
30
|
end
|
@@ -42,13 +49,13 @@ module SimpleCalendar
|
|
42
49
|
end
|
43
50
|
|
44
51
|
# Renders the calendar table
|
45
|
-
def draw_calendar(selected_month, month, current_date, events, block)
|
52
|
+
def draw_calendar(selected_month, month, current_date, events, options, block)
|
46
53
|
tags = []
|
47
54
|
|
48
55
|
content_tag(:table, :class => "table table-bordered table-striped calendar") do
|
49
|
-
tags << month_header(selected_month)
|
56
|
+
tags << month_header(selected_month, options)
|
50
57
|
tags << content_tag(:thead, content_tag(:tr, I18n.t("date.abbr_day_names").collect { |name| content_tag :th, name, :class => (selected_month.month == Date.today.month && Date.today.strftime("%a") == name ? "current-day" : nil)}.join.html_safe))
|
51
|
-
tags << content_tag(:tbody) do
|
58
|
+
tags << content_tag(:tbody, :'data-month'=>selected_month.month, :'data-year'=>selected_month.year) do
|
52
59
|
|
53
60
|
month.collect do |week|
|
54
61
|
content_tag(:tr, :class => (week.include?(Date.today) ? "current-week week" : "week")) do
|
@@ -58,11 +65,11 @@ module SimpleCalendar
|
|
58
65
|
tb_class << not_current_month = (date.month == selected_month.month ? "" : "not-currnet-month")
|
59
66
|
tb_class << (Date.today == date ? "today day" : "day")
|
60
67
|
|
61
|
-
content_tag(:td, :class => tb_class.join(" ")) do
|
68
|
+
content_tag(:td, :class => tb_class.join(" "), :'data-date-iso'=>date.to_s, 'data-date'=>date.to_s.gsub('-', '/')) do
|
62
69
|
content_tag(:div) do
|
63
70
|
divs = []
|
64
71
|
|
65
|
-
concat content_tag(:div, date.day.to_s)
|
72
|
+
concat content_tag(:div, date.day.to_s, :class=>"day_number")
|
66
73
|
divs << day_events(date, events).collect {|event| block.call(event) }
|
67
74
|
divs.join.html_safe
|
68
75
|
end #content_tag :div
|
@@ -84,15 +91,15 @@ module SimpleCalendar
|
|
84
91
|
end
|
85
92
|
|
86
93
|
# Generates the header that includes the month and next and previous months
|
87
|
-
def month_header(selected_month)
|
94
|
+
def month_header(selected_month, options)
|
88
95
|
content_tag :h2 do
|
89
96
|
previous_month = selected_month.advance :months => -1
|
90
97
|
next_month = selected_month.advance :months => 1
|
91
98
|
tags = []
|
92
99
|
|
93
|
-
tags << month_link(
|
94
|
-
tags <<
|
95
|
-
tags << month_link(
|
100
|
+
tags << month_link(options[:prev_text], previous_month, {:class => "previous-month"})
|
101
|
+
tags << I18n.t("date.month_names")[selected_month.month]
|
102
|
+
tags << month_link(options[:next_text], next_month, {:class => "next-month"})
|
96
103
|
|
97
104
|
tags.join.html_safe
|
98
105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project: simple_calendar
|
67
|
-
rubygems_version: 1.8.
|
67
|
+
rubygems_version: 1.8.24
|
68
68
|
signing_key:
|
69
69
|
specification_version: 3
|
70
70
|
summary: A simple Rails 3 calendar
|