simple_calendar 0.0.8 → 0.1.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.
- data/README.md +41 -24
- data/lib/simple_calendar.rb +0 -1
- data/lib/simple_calendar/railtie.rb +0 -5
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +7 -3
- metadata +8 -3
- data/lib/simple_calendar/model_additions.rb +0 -15
data/README.md
CHANGED
@@ -2,41 +2,61 @@ Simple Calendar
|
|
2
2
|
===============
|
3
3
|
|
4
4
|
This is a small Rails 3.2 gem for creating a quick and clean table calendar.
|
5
|
-
Theming is up to you, but it works nicely with Twitter Bootstrap.
|
5
|
+
Theming is up to you, but it works nicely with Twitter Bootstrap. It's
|
6
|
+
compatible with pure Ruby classes, ActiveRecord, Mongoid, and any other
|
7
|
+
ORM.
|
6
8
|
|
7
|
-
Thanks to Josh Chernoff
|
8
|
-
code.
|
9
|
+
Thanks to Josh Chernoff and all other contributors.
|
9
10
|
|
10
11
|
Installation
|
11
12
|
------------
|
12
13
|
|
13
14
|
Just add this into your Gemfile followed by a bundle install:
|
14
15
|
|
15
|
-
gem "simple_calendar", "~> 0.
|
16
|
+
gem "simple_calendar", "~> 0.1.1"
|
16
17
|
|
17
18
|
Usage
|
18
19
|
-----
|
19
20
|
|
20
|
-
####Model
|
21
|
+
#### Model
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
SimpleCalendar will look for a method on your model called `start_time`.
|
24
|
+
This is used to determine the day and time of the event. This should be
|
25
|
+
a `DateTime` object or at least respond similarly.
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
27
|
+
If you don't have an attribute called `start_time` on your model, you
|
28
|
+
can simply delegate like so:
|
28
29
|
|
29
|
-
|
30
|
+
```ruby
|
31
|
+
class Event < ActiveRecord::Base
|
32
|
+
attr_accessible :name, :event_start_time
|
30
33
|
|
31
|
-
|
34
|
+
def start_time
|
35
|
+
event_start_time
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
32
39
|
|
33
|
-
|
34
|
-
|
40
|
+
As long as `start_time` returns a `DateTime` object, you're good to go.
|
41
|
+
This means SimpleCalendar is now compatible with any class, whether it's
|
42
|
+
ORM backed like ActiveRecord, Mongoid, or it's just a pure Ruby class.
|
43
|
+
(Yay!)
|
35
44
|
|
36
|
-
|
45
|
+
##### Querying
|
37
46
|
|
38
|
-
|
39
|
-
|
47
|
+
SimpleCalendar uses `params[:month]` and `params[:year]` to determine
|
48
|
+
which month of the calendar to render. You can use these to make your
|
49
|
+
database queries more efficient.
|
50
|
+
|
51
|
+
#### Views
|
52
|
+
|
53
|
+
SimpleCalendar just accepts an array of events and a block. The block
|
54
|
+
will be executed for each event so you can provide your own logic for
|
55
|
+
displaying the events.
|
56
|
+
|
57
|
+
Here's an example that uses SimpleCalendar to simply render a link to
|
58
|
+
each event on its own line inside the table. You would simply query for
|
59
|
+
the `@events` as discussed above in the querying section.
|
40
60
|
|
41
61
|
<%= calendar @events do |event| %>
|
42
62
|
<div><%= link_to event.title, event %></div>
|
@@ -58,15 +78,15 @@ Possible options:
|
|
58
78
|
|
59
79
|
:year # current year, default: from params or current year
|
60
80
|
:month # current month, default: from params or current month
|
61
|
-
:prev_text
|
62
|
-
:next_text
|
81
|
+
:prev_text # previous month link text, default: «
|
82
|
+
:next_text # next month link text, default: »
|
63
83
|
|
64
84
|
CSS
|
65
85
|
---
|
66
86
|
|
67
87
|
You will probably want to customize the height of the calendar so that
|
68
|
-
all the rows are the same. You can do this by adding
|
69
|
-
to your css:
|
88
|
+
all the rows are the same heights and widths. You can do this by adding
|
89
|
+
the following line to your css:
|
70
90
|
|
71
91
|
.calendar td { height: 100px; width: 14.28%; }
|
72
92
|
|
@@ -76,7 +96,4 @@ and .calendar classes.
|
|
76
96
|
TODO
|
77
97
|
====
|
78
98
|
|
79
|
-
* Add query helpers to grab events for a current month and the days into
|
80
|
-
the next and previous months for efficiency
|
81
99
|
* Customizable starting day of week
|
82
|
-
* More customization?
|
data/lib/simple_calendar.rb
CHANGED
@@ -3,10 +3,5 @@ module SimpleCalendar
|
|
3
3
|
initializer "simple_calendar.view_helpers" do
|
4
4
|
ActionView::Base.send :include, ViewHelpers
|
5
5
|
end
|
6
|
-
initializer "simple_calendar.model_additions" do
|
7
|
-
ActiveSupport.on_load :active_record do
|
8
|
-
extend ModelAdditions
|
9
|
-
end
|
10
|
-
end
|
11
6
|
end
|
12
7
|
end
|
@@ -2,6 +2,9 @@ module SimpleCalendar
|
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
4
|
def calendar(events, options={}, &block)
|
5
|
+
raise 'SimpleCalendar requires a block to be passed in' unless block_given?
|
6
|
+
|
7
|
+
|
5
8
|
opts = {
|
6
9
|
:year => (params[:year] || Time.zone.now.year).to_i,
|
7
10
|
:month => (params[:month] || Time.zone.now.month).to_i,
|
@@ -9,6 +12,7 @@ module SimpleCalendar
|
|
9
12
|
:next_text => raw("»")
|
10
13
|
}
|
11
14
|
options.reverse_merge! opts
|
15
|
+
events ||= []
|
12
16
|
selected_month = Date.civil(options[:year], options[:month])
|
13
17
|
current_date = Date.today
|
14
18
|
range = build_range selected_month
|
@@ -26,7 +30,7 @@ module SimpleCalendar
|
|
26
30
|
end_date = selected_month.end_of_month
|
27
31
|
end_date = end_date.saturday? ? end_date : end_date.end_of_week(:sunday)
|
28
32
|
|
29
|
-
|
33
|
+
(start_date..end_date).to_a
|
30
34
|
end
|
31
35
|
|
32
36
|
def build_month(date_range)
|
@@ -73,7 +77,7 @@ module SimpleCalendar
|
|
73
77
|
divs = []
|
74
78
|
|
75
79
|
concat content_tag(:div, date.day.to_s, :class=>"day_number")
|
76
|
-
divs << day_events(date, events).collect {|event| block.call(event) }
|
80
|
+
divs << day_events(date, events).collect { |event| block.call(event) }
|
77
81
|
divs.join.html_safe
|
78
82
|
end #content_tag :div
|
79
83
|
end #content_tag :td
|
@@ -90,7 +94,7 @@ module SimpleCalendar
|
|
90
94
|
|
91
95
|
# Returns an array of events for a given day
|
92
96
|
def day_events(date, events)
|
93
|
-
events.select { |e| e.
|
97
|
+
events.select { |e| e.start_time.to_date == date }
|
94
98
|
end
|
95
99
|
|
96
100
|
# Generates the header that includes the month and next and previous months
|
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.
|
4
|
+
version: 0.1.1
|
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-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -39,7 +39,6 @@ files:
|
|
39
39
|
- README.md
|
40
40
|
- Rakefile
|
41
41
|
- lib/simple_calendar.rb
|
42
|
-
- lib/simple_calendar/model_additions.rb
|
43
42
|
- lib/simple_calendar/railtie.rb
|
44
43
|
- lib/simple_calendar/version.rb
|
45
44
|
- lib/simple_calendar/view_helpers.rb
|
@@ -56,12 +55,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
55
|
- - ! '>='
|
57
56
|
- !ruby/object:Gem::Version
|
58
57
|
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 1074299040452234765
|
59
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
62
|
none: false
|
61
63
|
requirements:
|
62
64
|
- - ! '>='
|
63
65
|
- !ruby/object:Gem::Version
|
64
66
|
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 1074299040452234765
|
65
70
|
requirements: []
|
66
71
|
rubyforge_project: simple_calendar
|
67
72
|
rubygems_version: 1.8.24
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SimpleCalendar
|
2
|
-
module ModelAdditions
|
3
|
-
def has_calendar(options={})
|
4
|
-
config = { :start_time => "start_time"}
|
5
|
-
config.update(options) if options.is_a?(Hash)
|
6
|
-
|
7
|
-
class_eval <<-EOV
|
8
|
-
def start_time_column
|
9
|
-
#{config[:start_time]}
|
10
|
-
end
|
11
|
-
EOV
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|