simple_calendar 2.2.4 → 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/views/simple_calendar/_week_calendar.html.erb +6 -2
- data/lib/simple_calendar/calendar.rb +7 -3
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/week_calendar.rb +8 -4
- data/spec/calendar_spec.rb +10 -3
- 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: b59a6e0877e1ff3b71901bc01ba95dc961d03313
|
4
|
+
data.tar.gz: c2e415e9f1a24e92f970d50cc6119e8becd37615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1baea65b91560b3d247c717dccc9daac1d789a214b7df9db56adb94d9d68877dfaf66e3e8f2023c7db92b93b443c594f0b7be7cdc6cf378f2276b983989a33e6
|
7
|
+
data.tar.gz: 410701770d8ff9cc6f66132037f37a79e34dc61afc420049fc333f448cfe2ec37a06c3ba71994f893da14d3e3ea589bd300edd6386f6081a30f03e765b8f1857
|
data/README.md
CHANGED
@@ -69,6 +69,17 @@ You can generate calendars of any length by passing in the number of days you wa
|
|
69
69
|
|
70
70
|
Setting `number_of_days` is optional and defaults to 4.
|
71
71
|
|
72
|
+
### Custom Parameter Name
|
73
|
+
|
74
|
+
You can pass in `start_date_param` to change the name of the parameter
|
75
|
+
in the URL for the current calendar view.
|
76
|
+
|
77
|
+
```erb
|
78
|
+
<%= calendar start_date_param: :my_date do |date| %>
|
79
|
+
<%= date %>
|
80
|
+
<% end %>
|
81
|
+
```
|
82
|
+
|
72
83
|
### Custom Partial
|
73
84
|
|
74
85
|
You can set a different partial name for calendars by passing the partial path.
|
@@ -1,8 +1,12 @@
|
|
1
1
|
<div class="simple-calendar">
|
2
2
|
<div class="calendar-heading">
|
3
3
|
<%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
|
4
|
-
|
5
|
-
|
4
|
+
<% if calendar.number_of_weeks == 1 %>
|
5
|
+
<span class="calendar-title">Week <%= calendar.week_number %></span>
|
6
|
+
<%else%>
|
7
|
+
<span class="calendar-title">Week <%= calendar.week_number %> - <%= calendar.end_week %></span>
|
8
|
+
<%end%>
|
9
|
+
<%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
|
6
10
|
</div>
|
7
11
|
|
8
12
|
<table class="table table-striped">
|
@@ -46,11 +46,11 @@ module SimpleCalendar
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def url_for_next_view
|
49
|
-
view_context.url_for(@params.merge(
|
49
|
+
view_context.url_for(@params.merge(start_date_param => date_range.last + 1.day))
|
50
50
|
end
|
51
51
|
|
52
52
|
def url_for_previous_view
|
53
|
-
view_context.url_for(@params.merge(
|
53
|
+
view_context.url_for(@params.merge(start_date_param => date_range.first - 1.day))
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
@@ -67,6 +67,10 @@ module SimpleCalendar
|
|
67
67
|
options.fetch(:end_attribute, :end_time).to_sym
|
68
68
|
end
|
69
69
|
|
70
|
+
def start_date_param
|
71
|
+
options.fetch(:start_date_param, :start_date).to_sym
|
72
|
+
end
|
73
|
+
|
70
74
|
def sorted_events
|
71
75
|
@sorted_events ||= begin
|
72
76
|
events = options.fetch(:events, []).reject { |e| e.send(attribute).nil? }.sort_by(&attribute)
|
@@ -92,7 +96,7 @@ module SimpleCalendar
|
|
92
96
|
if options.has_key?(:start_date)
|
93
97
|
options.fetch(:start_date).to_date
|
94
98
|
else
|
95
|
-
view_context.params.fetch(
|
99
|
+
view_context.params.fetch(start_date_param, Date.current).to_date
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
@@ -5,6 +5,14 @@ module SimpleCalendar
|
|
5
5
|
start_date.beginning_of_week.strftime(format).to_i
|
6
6
|
end
|
7
7
|
|
8
|
+
def number_of_weeks
|
9
|
+
options.fetch(:number_of_weeks, 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
def end_week
|
13
|
+
week_number + number_of_weeks - 1
|
14
|
+
end
|
15
|
+
|
8
16
|
private
|
9
17
|
|
10
18
|
def date_range
|
@@ -13,9 +21,5 @@ module SimpleCalendar
|
|
13
21
|
|
14
22
|
(starting..ending).to_a
|
15
23
|
end
|
16
|
-
|
17
|
-
def number_of_weeks
|
18
|
-
options.fetch(:number_of_weeks, 1)
|
19
|
-
end
|
20
24
|
end
|
21
25
|
end
|
data/spec/calendar_spec.rb
CHANGED
@@ -3,15 +3,16 @@ require 'action_controller'
|
|
3
3
|
require 'simple_calendar/calendar'
|
4
4
|
|
5
5
|
class ViewContext
|
6
|
-
attr_accessor :start_date
|
6
|
+
attr_accessor :start_date, :start_date_param
|
7
7
|
|
8
|
-
def initialize(start_date=nil)
|
8
|
+
def initialize(start_date=nil, options={})
|
9
9
|
@start_date = start_date
|
10
|
+
@start_date_param = options.fetch(:start_date_param, :start_date)
|
10
11
|
end
|
11
12
|
|
12
13
|
def params
|
13
14
|
if @start_date.present?
|
14
|
-
ActionController::Parameters.new({
|
15
|
+
ActionController::Parameters.new({start_date_param => @start_date})
|
15
16
|
else
|
16
17
|
ActionController::Parameters.new
|
17
18
|
end
|
@@ -104,6 +105,12 @@ describe SimpleCalendar::Calendar do
|
|
104
105
|
calendar = SimpleCalendar::Calendar.new(view_context, start_date: Date.tomorrow)
|
105
106
|
expect(calendar.send(:start_date)).to eq(Date.tomorrow)
|
106
107
|
end
|
108
|
+
|
109
|
+
it "takes an option to override the start_date parameter" do
|
110
|
+
view_context = ViewContext.new(Date.yesterday, start_date_param: :date)
|
111
|
+
calendar = SimpleCalendar::Calendar.new(view_context, start_date_param: :date)
|
112
|
+
expect(calendar.send(:start_date)).to eq(Date.yesterday)
|
113
|
+
end
|
107
114
|
end
|
108
115
|
|
109
116
|
it 'has a param that determines the start date of the calendar'
|
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.2.
|
4
|
+
version: 2.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project: simple_calendar
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A simple Rails calendar
|