simple_calendar 2.2.6 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ci.yml +43 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +3 -0
- data/README.md +68 -31
- data/Rakefile +1 -1
- data/app/views/simple_calendar/_calendar.html.erb +5 -5
- data/app/views/simple_calendar/_month_calendar.html.erb +3 -3
- data/app/views/simple_calendar/_week_calendar.html.erb +8 -8
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_6.gemfile.lock +197 -0
- data/gemfiles/rails_6_1.gemfile +9 -0
- data/gemfiles/rails_6_1.gemfile.lock +200 -0
- data/gemfiles/rails_master.gemfile +9 -0
- data/gemfiles/rails_master.gemfile.lock +205 -0
- data/lib/generators/simple_calendar/views_generator.rb +2 -2
- data/lib/simple_calendar/calendar.rb +67 -59
- data/lib/simple_calendar/month_calendar.rb +3 -6
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +6 -6
- data/lib/simple_calendar/week_calendar.rb +6 -8
- data/simple_calendar.gemspec +12 -13
- data/spec/calendar_spec.rb +90 -44
- data/spec/calendars/month_calendar_spec.rb +22 -4
- data/spec/simple_calendar_spec.rb +4 -4
- data/spec/spec_helper.rb +53 -53
- data/spec/support/fake_event.rb +9 -0
- data/spec/support/view_context.rb +20 -0
- data/spec/views_generators_spec.rb +3 -3
- metadata +21 -8
- data/.travis.yml +0 -4
@@ -1,10 +1,7 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
class MonthCalendar < SimpleCalendar::Calendar
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
(start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
|
7
|
-
end
|
3
|
+
def date_range
|
4
|
+
(start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
|
5
|
+
end
|
8
6
|
end
|
9
7
|
end
|
10
|
-
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
module ViewHelpers
|
3
|
-
def calendar(options={}, &block)
|
4
|
-
raise
|
3
|
+
def calendar(options = {}, &block)
|
4
|
+
raise "calendar requires a block" unless block
|
5
5
|
SimpleCalendar::Calendar.new(self, options).render(&block)
|
6
6
|
end
|
7
7
|
|
8
|
-
def month_calendar(options={}, &block)
|
9
|
-
raise
|
8
|
+
def month_calendar(options = {}, &block)
|
9
|
+
raise "month_calendar requires a block" unless block
|
10
10
|
SimpleCalendar::MonthCalendar.new(self, options).render(&block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def week_calendar(options={}, &block)
|
14
|
-
raise
|
13
|
+
def week_calendar(options = {}, &block)
|
14
|
+
raise "week_calendar requires a block" unless block
|
15
15
|
SimpleCalendar::WeekCalendar.new(self, options).render(&block)
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
class WeekCalendar < SimpleCalendar::Calendar
|
3
3
|
def week_number
|
4
|
-
format =
|
4
|
+
format = Date.beginning_of_week == :sunday ? "%U" : "%V"
|
5
5
|
start_date.beginning_of_week.strftime(format).to_i
|
6
6
|
end
|
7
7
|
|
@@ -13,13 +13,11 @@ module SimpleCalendar
|
|
13
13
|
week_number + number_of_weeks - 1
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def date_range
|
17
|
+
starting = start_date.beginning_of_week
|
18
|
+
ending = (starting + (number_of_weeks - 1).weeks).end_of_week
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
ending = (starting + (number_of_weeks - 1).weeks).end_of_week
|
21
|
-
|
22
|
-
(starting..ending).to_a
|
23
|
-
end
|
20
|
+
(starting..ending).to_a
|
21
|
+
end
|
24
22
|
end
|
25
23
|
end
|
data/simple_calendar.gemspec
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "simple_calendar/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
12
|
-
s.description =
|
13
|
-
s.license
|
5
|
+
s.name = "simple_calendar"
|
6
|
+
s.version = SimpleCalendar::VERSION
|
7
|
+
s.authors = ["Chris Oliver"]
|
8
|
+
s.email = ["excid3@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/excid3/simple_calendar"
|
10
|
+
s.summary = "A simple Rails calendar"
|
11
|
+
s.description = "A simple Rails calendar"
|
12
|
+
s.license = "MIT"
|
14
13
|
|
15
14
|
s.rubyforge_project = "simple_calendar"
|
16
15
|
|
17
|
-
s.files
|
18
|
-
s.test_files
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
18
|
s.require_paths = ["lib"]
|
20
19
|
|
21
|
-
s.add_dependency
|
22
|
-
s.add_development_dependency
|
20
|
+
s.add_dependency "rails", ">= 3.0"
|
21
|
+
s.add_development_dependency "rspec"
|
23
22
|
end
|
data/spec/calendar_spec.rb
CHANGED
@@ -1,53 +1,38 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :start_date, :start_date_param
|
7
|
-
|
8
|
-
def initialize(start_date=nil, options={})
|
9
|
-
@start_date = start_date
|
10
|
-
@start_date_param = options.fetch(:start_date_param, :start_date)
|
11
|
-
end
|
12
|
-
|
13
|
-
def params
|
14
|
-
if @start_date.present?
|
15
|
-
ActionController::Parameters.new({start_date_param => @start_date})
|
16
|
-
else
|
17
|
-
ActionController::Parameters.new
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
require "action_controller"
|
3
|
+
require "simple_calendar/calendar"
|
4
|
+
require_relative "support/fake_event"
|
5
|
+
require_relative "support/view_context"
|
21
6
|
|
22
7
|
describe SimpleCalendar::Calendar do
|
23
8
|
let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
|
24
9
|
|
25
|
-
it
|
10
|
+
it "renders a partial with the same name as the class" do
|
26
11
|
expect(calendar.send(:partial_name)).to eq("simple_calendar/calendar")
|
27
12
|
end
|
28
13
|
|
29
|
-
context
|
30
|
-
it
|
14
|
+
context "event sorting attribute" do
|
15
|
+
it "has start_time as the default attribute" do
|
31
16
|
expect(calendar.send(:attribute)).to eq(:start_time)
|
32
17
|
end
|
33
18
|
|
34
|
-
it
|
19
|
+
it "allows you to override the default attribute" do
|
35
20
|
expect(SimpleCalendar::Calendar.new(ViewContext.new, attribute: :starts_at).send(:attribute)).to eq(:starts_at)
|
36
21
|
end
|
37
22
|
|
38
23
|
it "set a default when `partial` option isn't present" do
|
39
|
-
expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq(
|
40
|
-
expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq(
|
41
|
-
expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq(
|
24
|
+
expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/calendar")
|
25
|
+
expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/month_calendar")
|
26
|
+
expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/week_calendar")
|
42
27
|
end
|
43
28
|
|
44
|
-
it
|
45
|
-
expect(SimpleCalendar::Calendar.new(ViewContext.new, partial:
|
29
|
+
it "allows to override the default partial" do
|
30
|
+
expect(SimpleCalendar::Calendar.new(ViewContext.new, partial: "simple_calendar/custom_calendar").send(:partial_name)).to eq("simple_calendar/custom_calendar")
|
46
31
|
end
|
47
32
|
end
|
48
33
|
|
49
34
|
describe "#sorted_events" do
|
50
|
-
it
|
35
|
+
it "converts an array of events to a hash sorted by days" do
|
51
36
|
today, tomorrow = Date.today, Date.tomorrow
|
52
37
|
|
53
38
|
event1 = double(start_time: today.at_midnight)
|
@@ -63,7 +48,7 @@ describe SimpleCalendar::Calendar do
|
|
63
48
|
expect(sorted_events[tomorrow]).to eq([event3])
|
64
49
|
end
|
65
50
|
|
66
|
-
it
|
51
|
+
it "converts an array of multi-day events to a hash sorted by days" do
|
67
52
|
today, tomorrow = Date.today, Date.tomorrow
|
68
53
|
|
69
54
|
event1 = double(start_time: today.at_midnight, end_time: tomorrow.at_midnight)
|
@@ -79,17 +64,17 @@ describe SimpleCalendar::Calendar do
|
|
79
64
|
expect(sorted_events[tomorrow]).to eq([event1, event3])
|
80
65
|
end
|
81
66
|
|
82
|
-
it
|
67
|
+
it "handles events without a start time" do
|
83
68
|
event = double(start_time: nil)
|
84
69
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])
|
85
70
|
|
86
|
-
expect{calendar.send(:sorted_events)}.not_to raise_error
|
71
|
+
expect { calendar.send(:sorted_events) }.not_to raise_error
|
87
72
|
end
|
88
73
|
end
|
89
74
|
|
90
75
|
describe "#start_date" do
|
91
76
|
it "defaults to today's date" do
|
92
|
-
view_context = ViewContext.new
|
77
|
+
view_context = ViewContext.new
|
93
78
|
calendar = SimpleCalendar::Calendar.new(view_context)
|
94
79
|
expect(calendar.send(:start_date)).to eq(Date.today)
|
95
80
|
end
|
@@ -113,18 +98,79 @@ describe SimpleCalendar::Calendar do
|
|
113
98
|
end
|
114
99
|
end
|
115
100
|
|
116
|
-
|
117
|
-
|
118
|
-
|
101
|
+
describe "current week class" do
|
102
|
+
it "should have the current week" do
|
103
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
104
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
105
|
+
expect(calendar.send(:tr_classes_for, week)).to include("current-week")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not have the current week if it does not contain today" do
|
109
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new(6.months.ago))
|
110
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
111
|
+
expect(calendar.send(:tr_classes_for, week)).to_not include("current-week")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "has a param that determines the start date of the calendar" do
|
116
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
117
|
+
|
118
|
+
rendering_variables = calendar.render[:locals]
|
119
|
+
|
120
|
+
expect(rendering_variables[:start_date]).not_to be_nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it "generates a default date if no start date is present" do
|
124
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
125
|
+
|
126
|
+
calendar_start_date = calendar.render[:locals][:start_date]
|
127
|
+
|
128
|
+
expect(calendar_start_date).not_to be_nil
|
129
|
+
expect(calendar_start_date).to be_a(Date)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "has a range of dates" do
|
133
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
134
|
+
|
135
|
+
calendar_date_range = calendar.date_range
|
136
|
+
|
137
|
+
expect(calendar_date_range).to be_an(Array)
|
138
|
+
expect(calendar_date_range).to all(be_an(Date))
|
139
|
+
end
|
140
|
+
|
141
|
+
it "can split the range of dates into weeks"
|
142
|
+
it "has a title"
|
143
|
+
it "has a next view link"
|
144
|
+
it "has a previous view link"
|
145
|
+
|
146
|
+
it "accepts an array of events" do
|
147
|
+
first_event = FakeEvent.new("event1", Date.today)
|
148
|
+
second_event = FakeEvent.new("event2", Date.today + 1.day)
|
149
|
+
events = [first_event, second_event]
|
150
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
119
151
|
|
120
|
-
|
121
|
-
it 'has a title'
|
122
|
-
it 'has a next view link'
|
123
|
-
it 'has a previous view link'
|
152
|
+
calendar_sorted_events = calendar.render[:locals][:sorted_events]
|
124
153
|
|
125
|
-
|
126
|
-
|
127
|
-
|
154
|
+
expect(calendar_sorted_events.length).to eq(2)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sorts the events" do
|
158
|
+
first_event = FakeEvent.new("event1", Date.today + 2.days)
|
159
|
+
second_event = FakeEvent.new("event2", Date.today + 1.day)
|
160
|
+
third_event = FakeEvent.new("event3", Date.today)
|
161
|
+
events = [first_event, third_event, second_event]
|
162
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
163
|
+
|
164
|
+
calendar_sorted_events = calendar.render[:locals][:sorted_events]
|
165
|
+
first_key = calendar_sorted_events.keys[0]
|
166
|
+
second_key = calendar_sorted_events.keys[1]
|
167
|
+
third_key = calendar_sorted_events.keys[2]
|
168
|
+
|
169
|
+
expect(calendar_sorted_events[first_key][0]).to eq(third_event)
|
170
|
+
expect(calendar_sorted_events[second_key][0]).to eq(second_event)
|
171
|
+
expect(calendar_sorted_events[third_key][0]).to eq(first_event)
|
172
|
+
end
|
128
173
|
|
174
|
+
it "yields the events for each day"
|
129
175
|
it "doesn't crash when an event has a nil start_time"
|
130
176
|
end
|
@@ -1,7 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "action_controller"
|
3
|
+
require "simple_calendar/calendar"
|
4
|
+
require "simple_calendar/month_calendar"
|
5
|
+
require "support/view_context"
|
3
6
|
|
4
7
|
describe SimpleCalendar::MonthCalendar do
|
5
|
-
|
6
|
-
|
8
|
+
describe "#date_range" do
|
9
|
+
it "renders a full calendar month" do
|
10
|
+
today = Date.today
|
11
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: Date.today)
|
12
|
+
|
13
|
+
expect(calendar.date_range.min).to be <= today.beginning_of_month
|
14
|
+
expect(calendar.date_range.max).to be >= today.end_of_month
|
15
|
+
end
|
16
|
+
|
17
|
+
it "render the days of next and previous months on the edges of the calendar" do
|
18
|
+
month = Date.new(2018, 8, 1)
|
19
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: month)
|
20
|
+
|
21
|
+
expect(calendar.date_range.first).to eq Date.new(2018, 7, 30)
|
22
|
+
expect(calendar.date_range.last).to eq Date.new(2018, 9, 2)
|
23
|
+
end
|
24
|
+
end
|
7
25
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "rails"
|
3
|
+
require "simple_calendar"
|
4
4
|
|
5
5
|
describe SimpleCalendar do
|
6
|
-
it
|
6
|
+
it "has a version number" do
|
7
7
|
expect(SimpleCalendar::VERSION).not_to be nil
|
8
8
|
end
|
9
9
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
|
1
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
5
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
@@ -40,57 +42,55 @@ RSpec.configure do |config|
|
|
40
42
|
mocks.verify_partial_doubles = true
|
41
43
|
end
|
42
44
|
|
43
|
-
# The settings below are suggested to provide a good initial experience
|
44
|
-
# with RSpec, but feel free to customize to your heart's content.
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
config.
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# - http://
|
61
|
-
# - http://
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
Kernel.srand config.seed
|
95
|
-
=end
|
45
|
+
# The settings below are suggested to provide a good initial experience
|
46
|
+
# with RSpec, but feel free to customize to your heart's content.
|
47
|
+
# # These two settings work together to allow you to limit a spec run
|
48
|
+
# # to individual examples or groups you care about by tagging them with
|
49
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
50
|
+
# # get run.
|
51
|
+
# config.filter_run :focus
|
52
|
+
# config.run_all_when_everything_filtered = true
|
53
|
+
#
|
54
|
+
# # Allows RSpec to persist some state between runs in order to support
|
55
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
56
|
+
# # you configure your source control system to ignore this file.
|
57
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
58
|
+
#
|
59
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
60
|
+
# # recommended. For more details, see:
|
61
|
+
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
63
|
+
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
64
|
+
# config.disable_monkey_patching!
|
65
|
+
#
|
66
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
67
|
+
# # be too noisy due to issues in dependencies.
|
68
|
+
# config.warnings = true
|
69
|
+
#
|
70
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
71
|
+
# # file, and it's useful to allow more verbose output when running an
|
72
|
+
# # individual spec file.
|
73
|
+
# if config.files_to_run.one?
|
74
|
+
# # Use the documentation formatter for detailed output,
|
75
|
+
# # unless a formatter has already been configured
|
76
|
+
# # (e.g. via a command-line flag).
|
77
|
+
# config.default_formatter = 'doc'
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# # Print the 10 slowest examples and example groups at the
|
81
|
+
# # end of the spec run, to help surface which specs are running
|
82
|
+
# # particularly slow.
|
83
|
+
# config.profile_examples = 10
|
84
|
+
#
|
85
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
86
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
87
|
+
# # the seed, which is printed after each run.
|
88
|
+
# # --seed 1234
|
89
|
+
# config.order = :random
|
90
|
+
#
|
91
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
92
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
93
|
+
# # test failures related to randomization by passing the same `--seed` value
|
94
|
+
# # as the one that triggered the failure.
|
95
|
+
# Kernel.srand config.seed
|
96
96
|
end
|