simple_calendar 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e11781a625cdf2a8812e5b7972feecb016b82abe0c1ad57b6687e90851f04f86
4
- data.tar.gz: 19f2e34143a16827b1b2a6255988ef53004477f91077e4e69bcfef31837aec31
3
+ metadata.gz: 37a9649373c34dabc95e3549b89903edea28a8b86e3c5e84defd640354390961
4
+ data.tar.gz: 561d150c797c2c350fa00501f8936556412efe0158449aa909fd22b824fbf5e0
5
5
  SHA512:
6
- metadata.gz: 140c319c81da2305230604b0101f6302e14d9952c2895ffab35a7d3c43cf7d4ab5eb4ad2111f0d2bb7246488446d9f09de71bb9b6e0bfe6ddeea11efba8b7bd0
7
- data.tar.gz: 8c2f960eaea8445f1a4f45b62d7ba5fd7864010a91c6ee37f4299443aa95bc4df70c760cea79bdaff35a166d65a0cbaa2b0b0caf1be289668705b337a1dd8c30
6
+ metadata.gz: 22c618117445c21407bfabd37889f83c5676143704a388670bf3f8b00ddd66d4d41fd2ccc5c4bdf9ecd2cde4b5b232407cac2d4265f2228640b51b4a65503e37
7
+ data.tar.gz: c284fe582e697f44e001c22dd0380a74c7ef60827a835f7768c058c56585534c339c4b11541ca938ad44da5a6aedad5ccd60fd5fe3e795a0dc921534dbebf105
data/.gitignore CHANGED
@@ -5,6 +5,6 @@ pkg/*
5
5
  .ruby-version
6
6
  .ruby-gemset
7
7
  test/dummy/db/test.sqlite3
8
- test/dummy/log/test.log
9
- test/dummy/log/development.log
10
8
  test/dummy/db/development.sqlite3
9
+ test/dummy/log
10
+ test/dummy/tmp
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 3.0.1
2
+
3
+ * Refactor to use block from `render_in` call to better support custom calendars
4
+
1
5
  ### 3.0.0
2
6
 
3
7
  * Drop support for Rails 6.0 and earlier
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ gem "standard"
7
7
 
8
8
  gem "puma"
9
9
  gem "sqlite3"
10
+
11
+ gem "web-console", "~> 4.2", group: :development
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- simple_calendar (3.0.0)
13
+ simple_calendar (3.0.1)
14
14
  rails (>= 6.1)
15
15
 
16
16
  GEM
@@ -82,6 +82,7 @@ GEM
82
82
  minitest (>= 5.1)
83
83
  tzinfo (~> 2.0)
84
84
  ast (2.4.2)
85
+ bindex (0.8.1)
85
86
  builder (3.2.4)
86
87
  concurrent-ruby (1.2.2)
87
88
  crass (1.0.6)
@@ -197,6 +198,11 @@ GEM
197
198
  tzinfo (2.0.6)
198
199
  concurrent-ruby (~> 1.0)
199
200
  unicode-display_width (2.4.2)
201
+ web-console (4.2.0)
202
+ actionview (>= 6.0.0)
203
+ activemodel (>= 6.0.0)
204
+ bindex (>= 0.4.0)
205
+ railties (>= 6.0.0)
200
206
  websocket-driver (0.7.5)
201
207
  websocket-extensions (>= 0.1.0)
202
208
  websocket-extensions (0.1.5)
@@ -213,6 +219,7 @@ DEPENDENCIES
213
219
  simple_calendar!
214
220
  sqlite3
215
221
  standard
222
+ web-console (~> 4.2)
216
223
 
217
224
  BUNDLED WITH
218
225
  2.4.16
data/README.md CHANGED
@@ -394,7 +394,7 @@ end
394
394
  To render this in the view, you can do:
395
395
 
396
396
  ```erb
397
- <%= SimpleCalendar::BusinessWeekCalendar.new(self, {}).render do |date| %>
397
+ <%= render SimpleCalendar::BusinessWeekCalendar.new(self, events: meetings) do |date| %>
398
398
  <%= date %>
399
399
  <% end %>
400
400
  ```
@@ -1,18 +1,18 @@
1
1
  module SimpleCalendar
2
- module ViewHelpers
2
+ module CalendarHelper
3
3
  def calendar(options = {}, &block)
4
4
  raise "calendar requires a block" unless block
5
- render SimpleCalendar::Calendar.new(self, options, &block)
5
+ render SimpleCalendar::Calendar.new(self, options), &block
6
6
  end
7
7
 
8
8
  def month_calendar(options = {}, &block)
9
9
  raise "month_calendar requires a block" unless block
10
- render SimpleCalendar::MonthCalendar.new(self, options, &block)
10
+ render SimpleCalendar::MonthCalendar.new(self, options), &block
11
11
  end
12
12
 
13
13
  def week_calendar(options = {}, &block)
14
14
  raise "week_calendar requires a block" unless block
15
- render SimpleCalendar::WeekCalendar.new(self, options, &block)
15
+ render SimpleCalendar::WeekCalendar.new(self, options), &block
16
16
  end
17
17
  end
18
18
  end
@@ -6,6 +6,7 @@ gem "appraisal", github: "thoughtbot/appraisal"
6
6
  gem "standard"
7
7
  gem "puma"
8
8
  gem "sqlite3"
9
+ gem "web-console", "~> 4.2", group: :development
9
10
  gem "rails", "~> 6.1.0"
10
11
 
11
12
  gemspec path: "../"
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: ..
12
12
  specs:
13
- simple_calendar (3.0.0)
13
+ simple_calendar (3.0.1)
14
14
  rails (>= 6.1)
15
15
 
16
16
  GEM
@@ -76,6 +76,7 @@ GEM
76
76
  tzinfo (~> 2.0)
77
77
  zeitwerk (~> 2.3)
78
78
  ast (2.4.2)
79
+ bindex (0.8.1)
79
80
  builder (3.2.4)
80
81
  concurrent-ruby (1.2.2)
81
82
  crass (1.0.6)
@@ -204,6 +205,11 @@ GEM
204
205
  tzinfo (2.0.6)
205
206
  concurrent-ruby (~> 1.0)
206
207
  unicode-display_width (2.4.2)
208
+ web-console (4.2.0)
209
+ actionview (>= 6.0.0)
210
+ activemodel (>= 6.0.0)
211
+ bindex (>= 0.4.0)
212
+ railties (>= 6.0.0)
207
213
  websocket-driver (0.7.5)
208
214
  websocket-extensions (>= 0.1.0)
209
215
  websocket-extensions (0.1.5)
@@ -221,6 +227,7 @@ DEPENDENCIES
221
227
  simple_calendar!
222
228
  sqlite3
223
229
  standard
230
+ web-console (~> 4.2)
224
231
 
225
232
  BUNDLED WITH
226
233
  2.4.16
@@ -6,6 +6,7 @@ gem "appraisal", github: "thoughtbot/appraisal"
6
6
  gem "standard"
7
7
  gem "puma"
8
8
  gem "sqlite3"
9
+ gem "web-console", "~> 4.2", group: :development
9
10
  gem "rails", "~> 7.0.0"
10
11
 
11
12
  gemspec path: "../"
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: ..
12
12
  specs:
13
- simple_calendar (3.0.0)
13
+ simple_calendar (3.0.1)
14
14
  rails (>= 6.1)
15
15
 
16
16
  GEM
@@ -82,6 +82,7 @@ GEM
82
82
  minitest (>= 5.1)
83
83
  tzinfo (~> 2.0)
84
84
  ast (2.4.2)
85
+ bindex (0.8.1)
85
86
  builder (3.2.4)
86
87
  concurrent-ruby (1.2.2)
87
88
  crass (1.0.6)
@@ -200,6 +201,11 @@ GEM
200
201
  tzinfo (2.0.6)
201
202
  concurrent-ruby (~> 1.0)
202
203
  unicode-display_width (2.4.2)
204
+ web-console (4.2.0)
205
+ actionview (>= 6.0.0)
206
+ activemodel (>= 6.0.0)
207
+ bindex (>= 0.4.0)
208
+ railties (>= 6.0.0)
203
209
  websocket-driver (0.7.5)
204
210
  websocket-extensions (>= 0.1.0)
205
211
  websocket-extensions (0.1.5)
@@ -217,6 +223,7 @@ DEPENDENCIES
217
223
  simple_calendar!
218
224
  sqlite3
219
225
  standard
226
+ web-console (~> 4.2)
220
227
 
221
228
  BUNDLED WITH
222
229
  2.4.16
@@ -6,6 +6,7 @@ gem "appraisal", github: "thoughtbot/appraisal"
6
6
  gem "standard"
7
7
  gem "puma"
8
8
  gem "sqlite3"
9
+ gem "web-console", "~> 4.2", group: :development
9
10
  gem "rails", github: "rails/rails"
10
11
 
11
12
  gemspec path: "../"
@@ -106,13 +106,14 @@ GIT
106
106
  PATH
107
107
  remote: ..
108
108
  specs:
109
- simple_calendar (3.0.0)
109
+ simple_calendar (3.0.1)
110
110
  rails (>= 6.1)
111
111
 
112
112
  GEM
113
113
  remote: http://rubygems.org/
114
114
  specs:
115
115
  ast (2.4.2)
116
+ bindex (0.8.1)
116
117
  builder (3.2.4)
117
118
  concurrent-ruby (1.2.2)
118
119
  connection_pool (2.4.1)
@@ -223,6 +224,11 @@ GEM
223
224
  tzinfo (2.0.6)
224
225
  concurrent-ruby (~> 1.0)
225
226
  unicode-display_width (2.4.2)
227
+ web-console (4.2.0)
228
+ actionview (>= 6.0.0)
229
+ activemodel (>= 6.0.0)
230
+ bindex (>= 0.4.0)
231
+ railties (>= 6.0.0)
226
232
  webrick (1.8.1)
227
233
  websocket-driver (0.7.5)
228
234
  websocket-extensions (>= 0.1.0)
@@ -241,6 +247,7 @@ DEPENDENCIES
241
247
  simple_calendar!
242
248
  sqlite3
243
249
  standard
250
+ web-console (~> 4.2)
244
251
 
245
252
  BUNDLED WITH
246
253
  2.4.16
@@ -21,7 +21,8 @@ module SimpleCalendar
21
21
  @params.merge!(@options.fetch(:params, {}))
22
22
  end
23
23
 
24
- def render_in(view_context)
24
+ def render_in(view_context, &block)
25
+ @block = block
25
26
  view_context.render(
26
27
  partial: partial_name,
27
28
  locals: locals
@@ -1,9 +1,4 @@
1
1
  module SimpleCalendar
2
2
  class Engine < Rails::Engine
3
- initializer "simple_calendar.view_helpers" do
4
- ActiveSupport.on_load(:action_view) do
5
- include ViewHelpers
6
- end
7
- end
8
3
  end
9
4
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -1,13 +1,7 @@
1
- require "simple_calendar/engine"
2
- require "simple_calendar/calendar"
3
- require "simple_calendar/month_calendar"
4
- require "simple_calendar/week_calendar"
5
- require "simple_calendar/version"
6
- require "simple_calendar/view_helpers"
7
-
8
1
  module SimpleCalendar
9
- autoload :Calendar, "simple_calendar/calendar"
10
- autoload :MonthCalendar, "simple_calendar/month_calendar"
11
- autoload :WeekCalendar, "simple_calendar/week_calendar"
12
- autoload :ViewHelpers, "simple_calendar/view_helpers"
2
+ require_relative "simple_calendar/calendar"
3
+ require_relative "simple_calendar/engine"
4
+ require_relative "simple_calendar/month_calendar"
5
+ require_relative "simple_calendar/version"
6
+ require_relative "simple_calendar/week_calendar"
13
7
  end
@@ -0,0 +1,9 @@
1
+ class BusinessWeekCalendar < SimpleCalendar::Calendar
2
+ private
3
+
4
+ def date_range
5
+ beginning = start_date.beginning_of_week + 1.day
6
+ ending = start_date.end_of_week - 1.day
7
+ (beginning..ending).to_a
8
+ end
9
+ end
@@ -6,6 +6,10 @@ class MeetingsController < ApplicationController
6
6
  @meetings = Meeting.all
7
7
  end
8
8
 
9
+ def business_week
10
+ @meetings = Meeting.all
11
+ end
12
+
9
13
  # GET /meetings/1
10
14
  def show
11
15
  end
@@ -0,0 +1,33 @@
1
+ <div class="simple-calendar">
2
+ <div class="calendar-heading">
3
+ <span class="calendar-title"><%= t('date.month_names')[start_date.month] %> <%= start_date.year %></span>
4
+
5
+ <nav>
6
+ <%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
7
+ <%= link_to t('simple_calendar.today', default: 'Today'), calendar.url_for_today_view %>
8
+ <%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
9
+ </nav>
10
+ </div>
11
+
12
+ <table class="table table-striped">
13
+ <thead>
14
+ <tr>
15
+ <% date_range.slice(0, 7).each do |day| %>
16
+ <th><%= t('date.abbr_day_names')[day.wday] %></th>
17
+ <% end %>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody>
22
+ <% date_range.each_slice(7) do |week| %>
23
+ <%= content_tag :tr, class: calendar.tr_classes_for(week) do %>
24
+ <% week.each do |day| %>
25
+ <%= content_tag :td, class: calendar.td_classes_for(day) do %>
26
+ <% instance_exec(day, calendar.sorted_events_for(day), &passed_block) %>
27
+ <% end %>
28
+ <% end %>
29
+ <% end %>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+ </div>
@@ -0,0 +1,24 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <h1>Meetings</h1>
4
+ <%= render BusinessWeekCalendar.new(self, events: @meetings) do |date, meetings| %>
5
+ <%= date %>
6
+
7
+ <% meetings.each do |meeting| %>
8
+ <div>
9
+ <%= meeting.name %>
10
+ </div>
11
+ <% end %>
12
+ <% end %>
13
+
14
+ <div id="meetings">
15
+ <% @meetings.each do |meeting| %>
16
+ <%= render meeting %>
17
+ <p>
18
+ <%= link_to "Show this meeting", meeting %>
19
+ </p>
20
+ <% end %>
21
+ </div>
22
+
23
+ <%= link_to "New meeting", new_meeting_path %>
24
+ <%= Time.current.beginning_of_month %>
@@ -1,5 +1,9 @@
1
1
  Rails.application.routes.draw do
2
- resources :meetings
2
+ resources :meetings do
3
+ collection do
4
+ get :business_week
5
+ end
6
+ end
3
7
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
4
8
 
5
9
  # Defines the root path route ("/")
@@ -10,11 +10,11 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2022_09_30_184313) do
13
+ ActiveRecord::Schema[7.0].define(version: 2022_09_30_184313) do
14
14
  create_table "meetings", force: :cascade do |t|
15
15
  t.string "name"
16
- t.datetime "start_time"
17
- t.datetime "end_time"
16
+ t.datetime "start_time", precision: nil
17
+ t.datetime "end_time", precision: nil
18
18
  t.datetime "created_at", null: false
19
19
  t.datetime "updated_at", null: false
20
20
  end
@@ -0,0 +1,31 @@
1
+ require "test_helper"
2
+
3
+ class CustomCalendarIntegrationTest < ActionDispatch::IntegrationTest
4
+ test "renders a custom calendar" do
5
+ get business_week_meetings_path
6
+ assert_select "div.simple-calendar"
7
+ end
8
+
9
+ test "calendar renders events" do
10
+ get business_week_meetings_path
11
+ assert_select "div.simple-calendar" do
12
+ assert_select "div", text: meetings(:one_day_event).name
13
+ end
14
+ end
15
+
16
+ test "calendar render two day events" do
17
+ event = meetings(:two_day_event)
18
+ get business_week_meetings_path, params: {start_date: event.start_time.to_date}
19
+ assert_select "div.simple-calendar" do
20
+ assert_select "div", text: event.name, count: 2
21
+ end
22
+ end
23
+
24
+ test "calendar render three day events" do
25
+ event = meetings(:three_day_event)
26
+ get business_week_meetings_path, params: {start_date: event.start_time.to_date}
27
+ assert_select "div.simple-calendar" do
28
+ assert_select "div", text: event.name, count: 3
29
+ end
30
+ end
31
+ end
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: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-13 00:00:00.000000000 Z
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -43,6 +43,7 @@ files:
43
43
  - README.md
44
44
  - Rakefile
45
45
  - app/assets/stylesheets/simple_calendar.scss
46
+ - app/helpers/simple_calendar/calendar_helper.rb
46
47
  - app/views/simple_calendar/_calendar.html.erb
47
48
  - app/views/simple_calendar/_month_calendar.html.erb
48
49
  - app/views/simple_calendar/_week_calendar.html.erb
@@ -61,7 +62,6 @@ files:
61
62
  - lib/simple_calendar/engine.rb
62
63
  - lib/simple_calendar/month_calendar.rb
63
64
  - lib/simple_calendar/version.rb
64
- - lib/simple_calendar/view_helpers.rb
65
65
  - lib/simple_calendar/week_calendar.rb
66
66
  - simple_calendar.gemspec
67
67
  - test/calendars/calendar_test.rb
@@ -70,6 +70,7 @@ files:
70
70
  - test/dummy/app/assets/config/manifest.js
71
71
  - test/dummy/app/assets/images/.keep
72
72
  - test/dummy/app/assets/stylesheets/application.css
73
+ - test/dummy/app/calendars/business_week_calendar.rb
73
74
  - test/dummy/app/channels/application_cable/channel.rb
74
75
  - test/dummy/app/channels/application_cable/connection.rb
75
76
  - test/dummy/app/controllers/application_controller.rb
@@ -85,8 +86,10 @@ files:
85
86
  - test/dummy/app/views/layouts/application.html.erb
86
87
  - test/dummy/app/views/layouts/mailer.html.erb
87
88
  - test/dummy/app/views/layouts/mailer.text.erb
89
+ - test/dummy/app/views/meetings/_business_week_calendar.html.erb
88
90
  - test/dummy/app/views/meetings/_form.html.erb
89
91
  - test/dummy/app/views/meetings/_meeting.html.erb
92
+ - test/dummy/app/views/meetings/business_week.html.erb
90
93
  - test/dummy/app/views/meetings/edit.html.erb
91
94
  - test/dummy/app/views/meetings/index.html.erb
92
95
  - test/dummy/app/views/meetings/new.html.erb
@@ -122,13 +125,8 @@ files:
122
125
  - test/dummy/public/apple-touch-icon.png
123
126
  - test/dummy/public/favicon.ico
124
127
  - test/dummy/storage/.keep
125
- - test/dummy/tmp/.keep
126
- - test/dummy/tmp/development_secret.txt
127
- - test/dummy/tmp/pids/.keep
128
- - test/dummy/tmp/pids/server.pid
129
- - test/dummy/tmp/restart.txt
130
- - test/dummy/tmp/storage/.keep
131
128
  - test/fixtures/meetings.yml
129
+ - test/integrations/custom_calendar_test.rb
132
130
  - test/integrations/month_calendar_test.rb
133
131
  - test/simple_calendar_test.rb
134
132
  - test/test_helper.rb
@@ -151,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
149
  - !ruby/object:Gem::Version
152
150
  version: '0'
153
151
  requirements: []
154
- rubygems_version: 3.4.16
152
+ rubygems_version: 3.4.17
155
153
  signing_key:
156
154
  specification_version: 4
157
155
  summary: A simple Rails calendar
data/test/dummy/tmp/.keep DELETED
File without changes
@@ -1 +0,0 @@
1
- 385417154446f2326be01378c4937623ff31b03c81fa45edeb89225c92e037918243b1ed9d16713314411fb6ed3cf2962bfaafcc1996a54322180368477bca66
File without changes
@@ -1 +0,0 @@
1
- 10208
File without changes
File without changes