simple_calendar 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/app/views/simple_calendar/_calendar.html.erb +2 -2
- data/app/views/simple_calendar/_month_calendar.html.erb +2 -2
- data/app/views/simple_calendar/_week_calendar.html.erb +2 -2
- data/lib/simple_calendar/calendar.rb +16 -11
- data/lib/simple_calendar/version.rb +1 -1
- data/spec/calendar_spec.rb +22 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f9a905897bec1f2aa6ca50db79a859af2e1620
|
4
|
+
data.tar.gz: 7f2e0f099aa7bdb9bb2630aaf28a3b8f5c58dcca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5665ddcfa19aca666994ec0dacbe3ad4fba3be565a5ace251fb104b829732e94c933d116d714664992fcb053e76a5edbb55d0389758bc88e677db0405e88675
|
7
|
+
data.tar.gz: 83b695471fc4da275e318c2575c608a7e458935ee991f67a8ad9c153637568455b413eb61fc1d7eb870070a4ca967c3ca372cdef151931dde28da10811b0ab30
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="simple-calendar">
|
2
|
-
<%= link_to "Previous",
|
2
|
+
<%= link_to "Previous", calendar.url_for_previous_view %>
|
3
3
|
<%= I18n.t("date.month_names")[start_date.month] %> <%= start_date.year %>
|
4
|
-
<%= link_to "Next",
|
4
|
+
<%= link_to "Next", calendar.url_for_next_view %>
|
5
5
|
|
6
6
|
<table class="table table-striped">
|
7
7
|
<thead>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="simple-calendar">
|
2
|
-
<%= link_to "Previous",
|
2
|
+
<%= link_to "Previous", calendar.url_for_previous_view %>
|
3
3
|
<%= I18n.t("date.month_names")[start_date.month] %> <%= start_date.year %>
|
4
|
-
<%= link_to "Next",
|
4
|
+
<%= link_to "Next", calendar.url_for_next_view %>
|
5
5
|
|
6
6
|
<table class="table table-striped">
|
7
7
|
<thead>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="simple-calendar">
|
2
|
-
<%= link_to "Previous",
|
2
|
+
<%= link_to "Previous", calendar.url_for_previous_view %>
|
3
3
|
Week <%= start_date.strftime("%U").to_i %>
|
4
|
-
<%= link_to "Next",
|
4
|
+
<%= link_to "Next", calendar.url_for_next_view %>
|
5
5
|
|
6
6
|
<table class="table table-striped">
|
7
7
|
<thead>
|
@@ -2,11 +2,17 @@ require 'rails'
|
|
2
2
|
|
3
3
|
module SimpleCalendar
|
4
4
|
class Calendar
|
5
|
+
PARAM_KEY_BLACKLIST = :authenticity_token, :commit, :utf8, :_method, :script_name
|
6
|
+
|
5
7
|
attr_accessor :view_context, :options
|
6
8
|
|
7
9
|
def initialize(view_context, opts={})
|
8
10
|
@view_context = view_context
|
9
11
|
@options = opts
|
12
|
+
|
13
|
+
@params = @view_context.params
|
14
|
+
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
|
15
|
+
@params = @params.with_indifferent_access.except(*PARAM_KEY_BLACKLIST)
|
10
16
|
end
|
11
17
|
|
12
18
|
def render(&block)
|
@@ -39,6 +45,14 @@ module SimpleCalendar
|
|
39
45
|
td_class
|
40
46
|
end
|
41
47
|
|
48
|
+
def url_for_next_view
|
49
|
+
view_context.url_for(@params.merge(start_date: date_range.last + 1.day))
|
50
|
+
end
|
51
|
+
|
52
|
+
def url_for_previous_view
|
53
|
+
view_context.url_for(@params.merge(start_date: date_range.first - 1.day))
|
54
|
+
end
|
55
|
+
|
42
56
|
private
|
43
57
|
|
44
58
|
def partial_name
|
@@ -51,18 +65,9 @@ module SimpleCalendar
|
|
51
65
|
|
52
66
|
def sorted_events
|
53
67
|
events = options.fetch(:events, []).sort_by(&attribute)
|
54
|
-
sorted = {}
|
55
|
-
|
56
|
-
events.each do |event|
|
57
|
-
start_time = event.send(attribute)
|
58
|
-
if start_time.present?
|
59
|
-
date = start_time.to_date
|
60
|
-
sorted[date] ||= []
|
61
|
-
sorted[date] << event
|
62
|
-
end
|
63
|
-
end
|
64
68
|
|
65
|
-
|
69
|
+
scheduled = events.reject { |e| e.send(attribute).nil? }
|
70
|
+
scheduled.group_by { |e| e.send(attribute).to_date }
|
66
71
|
end
|
67
72
|
|
68
73
|
def start_date
|
data/spec/calendar_spec.rb
CHANGED
@@ -35,7 +35,28 @@ describe SimpleCalendar::Calendar do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "#sorted_events" do
|
38
|
-
it 'converts an array of events to a hash sorted by days'
|
38
|
+
it 'converts an array of events to a hash sorted by days' do
|
39
|
+
today, tomorrow = Date.today, Date.tomorrow
|
40
|
+
|
41
|
+
event1 = double(start_time: today.at_midnight)
|
42
|
+
event2 = double(start_time: today.at_noon)
|
43
|
+
event3 = double(start_time: tomorrow.at_noon)
|
44
|
+
|
45
|
+
events = [event1, event2, event3].shuffle
|
46
|
+
calendar = SimpleCalendar::Calendar.new(nil, events: events)
|
47
|
+
|
48
|
+
sorted_events = calendar.send(:sorted_events)
|
49
|
+
|
50
|
+
expect(sorted_events[today]).to eq([event1, event2])
|
51
|
+
expect(sorted_events[tomorrow]).to eq([event3])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'handles events without a start time' do
|
55
|
+
event = double(start_time: nil)
|
56
|
+
calendar = SimpleCalendar::Calendar.new(nil, events: [event])
|
57
|
+
|
58
|
+
expect{calendar.send(:sorted_events)}.not_to raise_error
|
59
|
+
end
|
39
60
|
end
|
40
61
|
|
41
62
|
describe "#start_date" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project: simple_calendar
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: A simple Rails 3 and Rails 4 calendar
|