date_book 0.0.6 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -1
- data/.rubocop_todo.yml +2 -1
- data/.travis.yml +3 -0
- data/Gemfile +16 -4
- data/Gemfile.lock +14 -2
- data/VERSION +1 -1
- data/app/assets/javascripts/date_book/calendar_events.js +3 -3
- data/app/assets/stylesheets/date_book.css.scss +31 -2
- data/app/controllers/date_book/calendars_controller.rb +30 -19
- data/app/controllers/date_book/date_book_controller.rb +1 -1
- data/app/controllers/date_book/events_controller.rb +60 -62
- data/app/controllers/date_book/graphql_controller.rb +10 -11
- data/app/graphql/date_book_schema.rb +4 -4
- data/app/graphql/types/calendar_type.rb +4 -2
- data/app/graphql/types/date_time_type.rb +9 -5
- data/app/graphql/types/event_occurrence_type.rb +4 -2
- data/app/graphql/types/event_type.rb +4 -2
- data/app/graphql/types/mutation_type.rb +3 -1
- data/app/graphql/types/query_type.rb +12 -26
- data/app/helpers/date_book/application_helper.rb +4 -7
- data/app/helpers/date_book/events_helper.rb +43 -23
- data/app/views/date_book/application/_date_range.html.haml +3 -3
- data/app/views/date_book/calendars/index.html.haml +19 -3
- data/app/views/date_book/calendars/show.html.haml +29 -4
- data/app/views/date_book/events/_event.json.jbuilder +3 -1
- data/app/views/date_book/events/_form.html.haml +4 -4
- data/app/views/date_book/events/_occurrence_dates.html.haml +3 -3
- data/app/views/date_book/events/fields/_date.html.haml +1 -1
- data/app/views/date_book/events/fields/_day.html.haml +1 -1
- data/app/views/date_book/events/fields/_day_of_week.html.haml +3 -3
- data/app/views/date_book/events/fields/_duration.html.haml +3 -3
- data/app/views/date_book/events/fields/_interval.html.haml +1 -1
- data/app/views/date_book/events/fields/_time.html.haml +1 -1
- data/app/views/date_book/events/index.html.haml +1 -1
- data/app/views/date_book/events/rules/_daily.html.haml +3 -3
- data/app/views/date_book/events/rules/_monthly.html.haml +4 -4
- data/app/views/date_book/events/rules/_singular.html.haml +3 -3
- data/app/views/date_book/events/rules/_weekly.html.haml +4 -4
- data/app/views/date_book/events/show.html.haml +1 -1
- data/app/views/layouts/_date_book_scripts.html.haml +2 -4
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +1 -1
- data/date_book.gemspec +25 -22
- data/db/migrate/20170807133845_create_calendars.rb +3 -0
- data/db/migrate/20170807133846_create_events.rb +3 -0
- data/db/migrate/20170807133847_create_schedules.rb +9 -6
- data/db/migrate/20170807133848_add_fields_to_schedule.rb +3 -0
- data/db/migrate/20170807133849_create_event_occurrences.rb +4 -3
- data/db/migrate/20170807133850_add_fields_to_event_occurrences.rb +3 -0
- data/lib/date_book.rb +11 -2
- data/lib/date_book/concerns/ability.rb +9 -12
- data/lib/date_book/concerns/acts_as_calendar.rb +5 -6
- data/lib/date_book/concerns/acts_as_event.rb +30 -9
- data/lib/date_book/concerns/acts_as_event_occurrence.rb +21 -9
- data/lib/date_book/concerns/acts_as_ownable.rb +9 -3
- data/lib/date_book/concerns/acts_as_owner.rb +5 -6
- data/lib/date_book/concerns/acts_as_schedule.rb +14 -7
- data/lib/date_book/configuration.rb +14 -11
- data/lib/date_book/engine.rb +7 -5
- data/lib/date_book/version.rb +2 -0
- data/lib/generators/date_book/install/install_generator.rb +27 -29
- data/lib/generators/date_book/install/templates/app/models/calendar.rb +4 -1
- data/lib/generators/date_book/install/templates/app/models/event.rb +4 -1
- data/lib/generators/date_book/install/templates/app/models/event_occurrence.rb +4 -1
- data/lib/generators/date_book/install/templates/app/models/schedule.rb +4 -1
- data/spec/abilities/event_spec.rb +1 -1
- data/spec/controllers/date_book/calendars_controller_spec.rb +48 -20
- data/spec/controllers/date_book/events_controller_spec.rb +145 -39
- data/spec/dummy/app/models/calendar.rb +3 -1
- data/spec/dummy/app/models/event.rb +3 -1
- data/spec/dummy/app/models/event_occurrence.rb +3 -1
- data/spec/dummy/app/models/role.rb +7 -5
- data/spec/dummy/app/models/schedule.rb +3 -1
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/config/initializers/devise.rb +61 -40
- data/spec/dummy/config/initializers/high_voltage.rb +2 -0
- data/spec/dummy/config/initializers/rolify.rb +5 -2
- data/spec/dummy/config/routes.rb +6 -9
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20170728171103_create_users_table.rb +2 -0
- data/spec/dummy/db/migrate/20170807134122_add_devise_to_users.rb +4 -3
- data/spec/dummy/db/migrate/20170807134128_rolify_create_roles.rb +6 -4
- data/spec/dummy/db/migrate/{20170808150915_create_calendars.date_book.rb → 20170808200808_create_calendars.date_book.rb} +3 -0
- data/spec/dummy/db/migrate/{20170808150916_create_events.date_book.rb → 20170808200809_create_events.date_book.rb} +3 -0
- data/spec/dummy/db/migrate/{20170808150917_create_schedules.date_book.rb → 20170808200810_create_schedules.date_book.rb} +9 -6
- data/spec/dummy/db/migrate/{20170808150918_add_fields_to_schedule.date_book.rb → 20170808200811_add_fields_to_schedule.date_book.rb} +3 -0
- data/spec/dummy/db/migrate/{20170808150919_create_event_occurrences.date_book.rb → 20170808200812_create_event_occurrences.date_book.rb} +4 -3
- data/spec/dummy/db/migrate/{20170808150920_add_fields_to_event_occurrences.date_book.rb → 20170808200813_add_fields_to_event_occurrences.date_book.rb} +3 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/db/seeds/calendars.seeds.rb +2 -1
- data/spec/dummy/db/seeds/events.seeds.rb +5 -5
- data/spec/dummy/db/seeds/users.seeds.rb +3 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/basic_benchmark.rb +2 -0
- data/spec/factories/calendars.rb +2 -0
- data/spec/factories/events.rb +2 -0
- data/spec/factories/roles.rb +2 -1
- data/spec/factories/users.rb +2 -0
- data/spec/features/calendars_spec.rb +47 -5
- data/spec/features/events_spec.rb +35 -9
- data/spec/helpers/date_book/application_helper_spec.rb +32 -0
- data/spec/helpers/date_book/events_helper_spec.rb +181 -13
- data/spec/models/calendar_spec.rb +3 -1
- data/spec/models/event_spec.rb +3 -1
- data/spec/models/role_spec.rb +1 -0
- data/spec/rails_helper.rb +6 -1
- data/spec/requests/date_book/api_spec.rb +76 -0
- data/spec/routing/date_book/calendars_routing_spec.rb +4 -2
- data/spec/routing/date_book/events_routing_spec.rb +48 -11
- data/spec/support/controller_behaviors.rb +2 -0
- data/spec/support/controller_macros.rb +3 -1
- data/spec/support/factory_girl.rb +2 -0
- data/spec/support/feature_behaviors.rb +9 -9
- data/spec/support/loaded_site.rb +2 -0
- data/spec/support/loaded_site/calendars.rb +2 -0
- data/spec/support/loaded_site/events.rb +3 -1
- data/spec/support/loaded_site/users.rb +2 -0
- data/spec/support/request_behaviors.rb +12 -63
- data/spec/support/shared_connection.rb +2 -0
- data/spec/support/utilities.rb +6 -5
- metadata +79 -42
- data/app/graphql/types/profile_type.rb +0 -7
- data/app/helpers/date_book/calendar_helper.rb +0 -4
- data/app/views/date_book/application/_all_day_checkbox.html.haml +0 -1
- data/bin/rails +0 -15
- data/spec/helpers/date_book/calendar_helper_spec.rb +0 -17
- data/spec/requests/date_book/events_spec.rb +0 -56
@@ -7,21 +7,18 @@ module DateBook
|
|
7
7
|
|
8
8
|
def initialize_date_book(user)
|
9
9
|
alias_action :index, :show, :popover, to: :read
|
10
|
-
if user.has_role? :admin
|
11
|
-
can :manage, :all
|
12
|
-
elsif user.new_record?
|
13
|
-
can :read, Calendar
|
14
|
-
can :read, Event
|
15
|
-
else
|
16
|
-
can :read, Calendar
|
17
|
-
can :create, Calendar
|
18
|
-
can :manage, Calendar, id: Calendar.with_role(:owner, user).ids
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
can :read, [Calendar, Event]
|
12
|
+
|
13
|
+
unless user.new_record?
|
14
|
+
my_calendar_ids = Calendar.with_role(:owner, user).ids
|
15
|
+
can :create, Calendar
|
16
|
+
can :manage, Calendar, id: my_calendar_ids
|
17
|
+
can :manage, Event, calendar_id: my_calendar_ids
|
23
18
|
can :manage, Event, id: Event.with_role(:owner, user).ids
|
24
19
|
end
|
20
|
+
|
21
|
+
can :manage, :all if user.has_role? :admin
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_calendar behavior in Calendar model
|
2
5
|
module ActsAsCalendar
|
3
|
-
def acts_as_calendar(
|
6
|
+
def acts_as_calendar(_options = {})
|
4
7
|
acts_as_ownable
|
5
8
|
|
6
9
|
validates_presence_of :name, :slug
|
@@ -13,17 +16,13 @@ module DateBook
|
|
13
16
|
has_many :events, dependent: :destroy
|
14
17
|
|
15
18
|
include InstanceMethods
|
16
|
-
extend ClassMethods
|
17
19
|
end
|
18
20
|
|
21
|
+
# Instance Methods
|
19
22
|
module InstanceMethods
|
20
23
|
def event_occurrences
|
21
24
|
events.as_occurrences.ascending
|
22
25
|
end
|
23
26
|
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
end
|
27
|
-
|
28
27
|
end
|
29
28
|
end
|
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_event behavior in Event model
|
2
5
|
module ActsAsEvent
|
3
|
-
|
6
|
+
# rubocop:disable Metrics/AbcSize
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
8
|
+
def acts_as_event(_options = {})
|
4
9
|
acts_as_ownable
|
5
10
|
|
6
11
|
delegate :all_day, :duration, to: :schedule
|
@@ -21,20 +26,26 @@ module DateBook
|
|
21
26
|
accepts_nested_attributes_for :schedule
|
22
27
|
|
23
28
|
# Scopes
|
24
|
-
scope :ending_after,
|
29
|
+
scope :ending_after, (lambda do |start_date|
|
25
30
|
where id: ::EventOccurrence.ending_after(start_date).event_ids
|
26
|
-
|
27
|
-
scope :starting_before,
|
31
|
+
end)
|
32
|
+
scope :starting_before, (lambda do |end_date|
|
28
33
|
where id: ::EventOccurrence.starting_before(end_date).event_ids
|
29
|
-
|
34
|
+
end)
|
30
35
|
|
31
36
|
include InstanceMethods
|
32
37
|
extend ClassMethods
|
33
38
|
end
|
39
|
+
# rubocop:enable Metrics/AbcSize
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
34
41
|
|
42
|
+
# Instance Methods
|
35
43
|
module InstanceMethods
|
36
44
|
def schedule
|
37
|
-
super || build_schedule(
|
45
|
+
super || build_schedule(
|
46
|
+
date: Time.now.to_date,
|
47
|
+
time: Time.now.to_s(:time)
|
48
|
+
)
|
38
49
|
end
|
39
50
|
|
40
51
|
def previous_occurrence(occurrence = nil)
|
@@ -48,19 +59,29 @@ module DateBook
|
|
48
59
|
end
|
49
60
|
|
50
61
|
def url(occurrence = nil)
|
51
|
-
DateBook::Engine
|
62
|
+
DateBook::Engine
|
63
|
+
.routes
|
64
|
+
.url_helpers
|
65
|
+
.calendar_event_path(calendar, slug, occurrence_id: occurrence&.id)
|
52
66
|
end
|
53
67
|
|
54
68
|
def popover_url(occurrence = nil)
|
55
|
-
DateBook::Engine
|
69
|
+
DateBook::Engine
|
70
|
+
.routes
|
71
|
+
.url_helpers
|
72
|
+
.popover_calendar_event_path(
|
73
|
+
calendar,
|
74
|
+
slug,
|
75
|
+
occurrence_id: occurrence&.id
|
76
|
+
)
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
80
|
+
# Class Methods
|
59
81
|
module ClassMethods
|
60
82
|
def as_occurrences
|
61
83
|
::EventOccurrence.for_schedulables('Event', ids)
|
62
84
|
end
|
63
85
|
end
|
64
|
-
|
65
86
|
end
|
66
87
|
end
|
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_event_occurrence behavior in EventOccurrence model
|
2
5
|
module ActsAsEventOccurrence
|
3
|
-
|
6
|
+
# rubocop:disable Metrics/AbcSize
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
8
|
+
def acts_as_event_occurrence(_options = {})
|
4
9
|
before_save :set_end_date
|
5
10
|
|
6
11
|
alias_attribute :start_date, :date
|
@@ -10,19 +15,26 @@ module DateBook
|
|
10
15
|
delegate :schedule, to: :schedulable
|
11
16
|
|
12
17
|
# Scopes
|
13
|
-
scope :remaining, -> { where('date >= ?',Time.now) }
|
14
|
-
scope :previous, -> { where('date < ?',Time.now) }
|
15
|
-
scope :ending_after,
|
16
|
-
|
18
|
+
scope :remaining, -> { where('date >= ?', Time.now) }
|
19
|
+
scope :previous, -> { where('date < ?', Time.now) }
|
20
|
+
scope :ending_after, (lambda do |start_date|
|
21
|
+
(where 'end_date >= ?', start_date)
|
22
|
+
end)
|
23
|
+
scope :starting_before, ->(end_date) { where 'date < ?', end_date }
|
17
24
|
scope :for_events, -> { where(schedulable_type: 'Event') }
|
18
|
-
scope :for_schedulables,
|
25
|
+
scope :for_schedulables, (lambda do |model_name, ids|
|
26
|
+
where(schedulable_type: model_name).where('schedulable_id IN (?)', ids)
|
27
|
+
end)
|
19
28
|
scope :ascending, -> { order date: :asc }
|
20
29
|
scope :descending, -> { order date: :desc }
|
21
30
|
|
22
31
|
include InstanceMethods
|
23
32
|
extend ClassMethods
|
24
33
|
end
|
34
|
+
# rubocop:enable Metrics/AbcSize
|
35
|
+
# rubocop:enable Metrics/MethodLength
|
25
36
|
|
37
|
+
# Instance Methods
|
26
38
|
module InstanceMethods
|
27
39
|
def url
|
28
40
|
event.url(self)
|
@@ -39,7 +51,7 @@ module DateBook
|
|
39
51
|
I18n.localize date, format: :moment_datetime
|
40
52
|
end
|
41
53
|
end
|
42
|
-
|
54
|
+
alias start start_moment
|
43
55
|
|
44
56
|
def end_moment
|
45
57
|
if schedule.all_day
|
@@ -48,7 +60,7 @@ module DateBook
|
|
48
60
|
I18n.localize end_date, format: :moment_datetime
|
49
61
|
end
|
50
62
|
end
|
51
|
-
|
63
|
+
alias end end_moment
|
52
64
|
|
53
65
|
private
|
54
66
|
|
@@ -57,11 +69,11 @@ module DateBook
|
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
72
|
+
# Class Methods
|
60
73
|
module ClassMethods
|
61
74
|
def event_ids
|
62
75
|
for_events.pluck(:schedulable_id).uniq
|
63
76
|
end
|
64
77
|
end
|
65
|
-
|
66
78
|
end
|
67
79
|
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_ownable behavior in Calendar and Event models
|
2
5
|
module ActsAsOwnable
|
3
|
-
def acts_as_ownable(
|
6
|
+
def acts_as_ownable(_options = {})
|
4
7
|
# Rolify Gem
|
5
8
|
resourcify
|
6
9
|
|
@@ -9,6 +12,7 @@ module DateBook
|
|
9
12
|
include InstanceMethods
|
10
13
|
end
|
11
14
|
|
15
|
+
# Instance Methods
|
12
16
|
module InstanceMethods
|
13
17
|
def owners
|
14
18
|
User.with_role(:owner, self)
|
@@ -17,11 +21,13 @@ module DateBook
|
|
17
21
|
def owners=(revised_owners)
|
18
22
|
# Remove owners not listed in new value
|
19
23
|
owners.each do |owner|
|
20
|
-
|
24
|
+
next if revised_owners.include? owner
|
25
|
+
owner.remove_role(:owner, self)
|
21
26
|
end
|
22
27
|
# Add owners not previously held
|
23
28
|
revised_owners.each do |revised_owner|
|
24
|
-
|
29
|
+
next if owners.include? revised_owner
|
30
|
+
revised_owner.add_role :owner, self
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -1,18 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_owner behavior in User model
|
2
5
|
module ActsAsOwner
|
3
|
-
def acts_as_owner(
|
6
|
+
def acts_as_owner(_options = {})
|
4
7
|
include InstanceMethods
|
5
|
-
extend ClassMethods
|
6
8
|
end
|
7
9
|
|
10
|
+
# Instance Methods
|
8
11
|
module InstanceMethods
|
9
12
|
def calendars
|
10
13
|
Calendar.with_role(:owner, self)
|
11
14
|
end
|
12
15
|
end
|
13
|
-
|
14
|
-
module ClassMethods
|
15
|
-
end
|
16
|
-
|
17
16
|
end
|
18
17
|
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DateBook
|
4
|
+
# Mixin to allow acts_as_schedule behavior in Schedule model
|
2
5
|
module ActsAsSchedule
|
3
|
-
def acts_as_schedule(
|
6
|
+
def acts_as_schedule(_options = {})
|
4
7
|
include InstanceMethods
|
5
8
|
end
|
6
9
|
|
10
|
+
# Instance Methods
|
7
11
|
module InstanceMethods
|
8
12
|
def duration_attributes
|
9
13
|
OpenStruct.new count: duration_count, unit: duration_unit
|
@@ -21,8 +25,12 @@ module DateBook
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def duration_unit
|
24
|
-
return 'seconds' if duration
|
25
|
-
DateBook
|
28
|
+
return 'seconds' if duration.zero?
|
29
|
+
DateBook
|
30
|
+
.configuration
|
31
|
+
.duration_units
|
32
|
+
.select { |x| unit_matches? x }
|
33
|
+
.first || 'seconds'
|
26
34
|
end
|
27
35
|
|
28
36
|
def human_date
|
@@ -35,10 +43,9 @@ module DateBook
|
|
35
43
|
|
36
44
|
private
|
37
45
|
|
38
|
-
def
|
39
|
-
duration % 1.send(unit.singularize.to_sym).to_i
|
46
|
+
def unit_matches?(unit)
|
47
|
+
(duration % 1.send(unit.singularize.to_sym).to_i).zero?
|
40
48
|
end
|
41
49
|
end
|
42
|
-
|
43
50
|
end
|
44
|
-
end
|
51
|
+
end
|
@@ -12,18 +12,21 @@ module DateBook
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.weekdays
|
15
|
-
@weekdays
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
return @weekdays if @weekdays
|
16
|
+
|
17
|
+
initial_days = Date::DAYNAMES.map.with_index do |x, i|
|
18
|
+
OpenStruct.new(id: i, name: x, slug: x.downcase)
|
19
|
+
end
|
20
|
+
|
21
|
+
@weekdays = initial_days.sort_by do |value|
|
22
|
+
(value.id - week_start_index) % 7
|
23
|
+
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.week_start_index
|
26
|
-
@week_start_index ||= Date::DAYNAMES.find_index(
|
27
|
+
@week_start_index ||= Date::DAYNAMES.find_index(
|
28
|
+
configuration.week_starts_on
|
29
|
+
)
|
27
30
|
end
|
28
31
|
|
29
32
|
# DateBook Configuration
|
@@ -36,8 +39,8 @@ module DateBook
|
|
36
39
|
|
37
40
|
def initialize
|
38
41
|
self.week_starts_on = 'Sunday'
|
39
|
-
self.rules = %w
|
40
|
-
self.duration_units = %w
|
42
|
+
self.rules = %w[singular daily weekly monthly]
|
43
|
+
self.duration_units = %w[years months weeks days hours minutes seconds]
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
data/lib/date_book/engine.rb
CHANGED
@@ -19,19 +19,21 @@ module DateBook
|
|
19
19
|
end
|
20
20
|
|
21
21
|
initializer 'date_book.assets.precompile' do |app|
|
22
|
-
app.config.assets.precompile += %w
|
22
|
+
app.config.assets.precompile += %w[
|
23
23
|
date_book.js date_book.css bootstrap-wysiwyg/bootstrap-wysiwyg.css
|
24
24
|
bootstrap-wysiwyg.js jquery_nested_form.js jquery_nested_form.js
|
25
25
|
bootstrap-datetimepicker.js bootstrap-datetimepicker.css all-day-bg.png
|
26
|
-
part-day-bg.png
|
27
|
-
|
26
|
+
part-day-bg.png moment.js glyphicons-halflings-regular.eot
|
27
|
+
glyphicons-halflings-regular.svg glyphicons-halflings-regular.ttf
|
28
|
+
glyphicons-halflings-regular.woff glyphicons-halflings-regular.woff2
|
29
|
+
]
|
28
30
|
end
|
29
31
|
|
30
|
-
initializer
|
32
|
+
initializer 'date_book.add_middleware' do |app|
|
31
33
|
app.config.middleware.insert_before 0, Rack::Cors do
|
32
34
|
allow do
|
33
35
|
origins %r{\Ahttp://localhost:3000\z}
|
34
|
-
resource '*', :
|
36
|
+
resource '*', headers: :any, methods: %i[get post options]
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
data/lib/date_book/version.rb
CHANGED
@@ -4,8 +4,8 @@ module DateBook
|
|
4
4
|
# DateBook Install Generator
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
argument :user_model_name, type: :string, default: 'User'
|
7
|
-
source_root
|
8
|
-
require
|
7
|
+
source_root DateBook::Engine.root.join('lib/generators/date_book/install/templates')
|
8
|
+
require DateBook::Engine.root.join('lib/generators/date_book/utils')
|
9
9
|
include Generators::Utils
|
10
10
|
include Rails::Generators::Migration
|
11
11
|
|
@@ -21,7 +21,7 @@ module DateBook
|
|
21
21
|
"install it separately, I'll do that now.", :magenta
|
22
22
|
)
|
23
23
|
generate('devise:install')
|
24
|
-
generate(
|
24
|
+
generate("devise #{user_model_name}")
|
25
25
|
end
|
26
26
|
|
27
27
|
def install_cancan
|
@@ -39,7 +39,23 @@ module DateBook
|
|
39
39
|
'up now.',
|
40
40
|
:magenta
|
41
41
|
)
|
42
|
-
generate('rolify',
|
42
|
+
generate('rolify', "Role #{user_model_name}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_to_user
|
46
|
+
output(
|
47
|
+
"Adding DateBook to your #{user_model_name.downcase} model",
|
48
|
+
:magenta
|
49
|
+
)
|
50
|
+
gsub_file "app/models/#{user_model_name.downcase}.rb", /acts_as_owner/, ''
|
51
|
+
inject_into_file(
|
52
|
+
"app/models/#{user_model_name.downcase}.rb",
|
53
|
+
after: "rolify\n"
|
54
|
+
) do
|
55
|
+
<<-'RUBY'
|
56
|
+
acts_as_owner
|
57
|
+
RUBY
|
58
|
+
end
|
43
59
|
end
|
44
60
|
|
45
61
|
def install_bootstrap_leather
|
@@ -55,7 +71,10 @@ module DateBook
|
|
55
71
|
"Next, you'll need an initializer for Date Book.",
|
56
72
|
:magenta
|
57
73
|
)
|
58
|
-
template
|
74
|
+
template(
|
75
|
+
'config/initializers/date_book.rb',
|
76
|
+
'config/initializers/date_book.rb'
|
77
|
+
)
|
59
78
|
end
|
60
79
|
|
61
80
|
def add_models
|
@@ -65,22 +84,10 @@ module DateBook
|
|
65
84
|
)
|
66
85
|
template 'app/models/calendar.rb', 'app/models/calendar.rb'
|
67
86
|
template 'app/models/event.rb', 'app/models/event.rb'
|
68
|
-
template
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def add_to_user
|
73
|
-
output 'Adding DateBook to your User model', :magenta
|
74
|
-
gsub_file(
|
75
|
-
'app/models/user.rb',
|
76
|
-
%r{acts_as_owner},
|
77
|
-
''
|
87
|
+
template(
|
88
|
+
'app/models/event_occurrence.rb', 'app/models/event_occurrence.rb'
|
78
89
|
)
|
79
|
-
|
80
|
-
<<-'RUBY'
|
81
|
-
acts_as_owner
|
82
|
-
RUBY
|
83
|
-
end
|
90
|
+
template 'app/models/schedule.rb', 'app/models/schedule.rb'
|
84
91
|
end
|
85
92
|
|
86
93
|
def add_migrations
|
@@ -88,15 +95,6 @@ RUBY
|
|
88
95
|
rake 'date_book:install:migrations'
|
89
96
|
end
|
90
97
|
|
91
|
-
# def add_to_model
|
92
|
-
# output 'Adding DateBook to your User model', :magenta
|
93
|
-
# gsub_file 'app/models/user.rb', /^\n subscriber$/, ''
|
94
|
-
# inject_into_file(
|
95
|
-
# 'app/models/user.rb', "\n subscriber",
|
96
|
-
# after: 'class User < ActiveRecord::Base'
|
97
|
-
# )
|
98
|
-
# end
|
99
|
-
|
100
98
|
def add_route
|
101
99
|
output 'Adding DateBook to your routes.rb file', :magenta
|
102
100
|
gsub_file(
|