schedulable 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTFlNjE4MmQ1ZGVhZjdlMWEyZGJlMGYzZjhmZDUzZGQ4ZTVhOTU3ZQ==
5
- data.tar.gz: !binary |-
6
- OTA4MjU5YjI3NzBjZWQ1N2QwMzRiMGUwOTlhN2RkMzdhODAyNTJlYg==
2
+ SHA1:
3
+ metadata.gz: 2f7a4518050fa937ff52f0e063aaaadba2947c90
4
+ data.tar.gz: c3b07ace00ddf8dca91141e3c9042f2389acf033
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGFlY2QyMjBjOTViOWY2YjAyOGYzYTJkN2Q4Y2U2Zjg1NTJlNTNhM2RiZmM4
10
- MTUzYzAyNTZlNGYzZDA1ZGQ0NWVjZmNhOTlkZDg2ZjI1NDExMTUyMWNmMGNi
11
- NDEzNGJkMzc2MjE3NGVjODJjZDk3ODdmZDk5ZmY5ODNmODNjZTE=
12
- data.tar.gz: !binary |-
13
- NzMyYzQ1NTdjZGU4NjJkNTEyMjFlZTQ2NjcxNDg0YTAyMDY4ZjcxY2JmM2Fi
14
- ZjFjMWRkMjQwYWEyY2JkZjhiYTYxN2I2MDc0YWUyMDk1NmMwOGE0MjJlODc1
15
- MTRlYWZhMjcxMzNhZWFlNGYyZTY2MjcyZWMyNTFhMGUzMDAxMzA=
6
+ metadata.gz: 5be2519e0114ea58aa2180ecf6373b62aab37f730baa32e0afa01e5ddfc747f7733dd447e862ad448efccb6d5b6d9aacfe1d60e6b2f881cc416cedc1a4a73b13
7
+ data.tar.gz: 16a5641da65cb17518bb19e9f8219a9300e0a6afa9b813928c58345d02876bdd52ab14bc01971b2ac76474256b3fceaba61843e665c917932cec24a9c195a2eb
data/README.md CHANGED
@@ -3,21 +3,23 @@ schedulable
3
3
 
4
4
  Handling recurring events in rails.
5
5
 
6
+ ### Install
6
7
 
7
- The schedulable plugin depends on the ice_cube scheduling-library:
8
- ```
8
+ Put the following into your Gemfile and run `bundle install`
9
+ ```cli
9
10
  gem 'ice_cube'
11
+ gem 'schedulable'
10
12
  ```
11
13
 
12
14
  Install schedule migration and model
13
- ```
15
+ ```cli
14
16
  rails g schedulable:install
15
17
  ```
16
18
 
17
19
  ### Basic Usage
18
20
 
19
- Create your event model
20
- ```
21
+ Create an event model
22
+ ```cli
21
23
  rails g scaffold Event name:string
22
24
  ```
23
25
 
@@ -28,7 +30,7 @@ class Event < ActiveRecord::Base
28
30
  acts_as_schedulable
29
31
  end
30
32
  ```
31
- This will add an association named 'schedule' that holds the schedule information.
33
+ This will add an association to the model named 'schedule' which holds the schedule information.
32
34
 
33
35
  Now you're ready to setup form fields for the schedule association using the fields_for-form_helper.
34
36
 
@@ -65,19 +67,36 @@ The schedule object respects the following attributes:
65
67
  </table>
66
68
 
67
69
  #### SimpleForm
68
- A custom input for simple_form is provided with the plugin
69
- ```
70
+ A custom input for simple_form is provided with the plugin. Make sure, you installed [SimpleForm](https://github.com/plataformatec/simple_form) and executed `rails generate simple_form:install`.
71
+
72
+ ```cli
70
73
  rails g schedulable:simple_form
71
74
  ```
72
75
 
73
- ```
74
- -# app/views/events/_form.html.haml
75
- .form-inputs
76
- = f.input :name
77
- = f.input :schedule, as: :schedule
76
+ ```ruby
77
+ <%# app/views/events/_form.html.erb %>
78
+ <%= simple_form_for(@event) do |f| %>
79
+
80
+ <div class="field">
81
+ <%= f.label :name %><br>
82
+ <%= f.text_field :name %>
83
+ </div>
84
+
85
+ <div class="field">
86
+ <%= f.label :schedule %><br>
87
+ <%= f.input :schedule, as: :schedule %>
88
+ </div>
89
+
90
+ <div class="actions">
91
+ <%= f.submit %>
92
+ </div>
93
+
94
+ <% end %>
95
+
78
96
  ```
79
97
 
80
98
  #### Strong parameters
99
+
81
100
  ```
82
101
  # app/controllers/event_controller.rb
83
102
  def event_params
@@ -88,24 +107,54 @@ end
88
107
  ### IceCube
89
108
  The schedulable plugin uses ice_cube for calculating occurrences.
90
109
  You can access ice_cube-methods via the schedule association:
110
+
111
+ ```ruby
112
+ <%# app/views/events/show.html.erb %>
113
+ <p>
114
+ <strong>Schedule:</strong>
115
+ <%# prints out a human-friendly description of the schedule, such as %>
116
+ <%= @event.schedule %>
117
+ </p>
118
+ ```
119
+
91
120
  ```
92
121
  # prints all occurrences of the event until one year from now
93
122
  puts @event.schedule.occurrences(Time.now + 1.year)
94
123
  # export to ical
95
124
  puts @event.schedule.to_ical
96
125
  ```
97
- See https://github.com/seejohnrun/ice_cube for more information.
126
+ See [IceCube](https://github.com/seejohnrun/ice_cube) for more information.
127
+
128
+ ### Internationalization
129
+
130
+ At first you need to make sure you included all neccessary datetime translations.
131
+ A basic setup can be found [here](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale).
132
+
133
+ #### Localize Schedulable
134
+ Use the locale-generator to create a .yml-file containing schedulable messages in english:
135
+ ```cli
136
+ rails g schedulable:locale en
137
+ ```
98
138
 
99
- ### Event occurrences
139
+ Schedulable has also bundled messages in german. Use `de` as identifier.
140
+
141
+ #### Localize Ice-Cube
142
+ Internationalization of ice-cube itself can be integrated by using [this fork](https://github.com/joelmeyerhamme/ice_cube):
143
+ ```ruby
144
+ gem 'ice_cube', git: 'git://github.com/joelmeyerhamme/ice_cube.git', branch: 'international'
145
+ ```
146
+
147
+
148
+ ### Persist event occurrences
100
149
  We need to have the occurrences persisted because we want to query the database for all occurrences of all instances of an event model or need to add additional attributes and functionality, such as allowing users to attend to a specific occurrence of an event.
101
150
  The schedulable gem handles this for you.
102
151
  Your occurrence model must include an attribute of type 'datetime' with name 'date' as well as a reference to your event model to setup up the association properly:
103
152
 
104
- ```
153
+ ```ruby
105
154
  rails g model EventOccurrence event_id:integer date:datetime
106
155
  ```
107
156
 
108
- ```
157
+ ```ruby
109
158
  # app/models/event_occurrence.rb
110
159
  class EventOccurrence < ActiveRecord::Base
111
160
  belongs_to :event
@@ -135,20 +184,30 @@ See notes on configuration.
135
184
  #### Automate build of occurrences
136
185
  Since we cannot build all occurrences at once, we will need a task that adds occurrences as time goes by.
137
186
  Schedulable comes with a rake-task that performs an update on all scheduled occurrences.
138
- ```
187
+
188
+ ```cli
139
189
  rake schedulable:build_occurrences
140
190
  ```
141
- You may add the task to crontab.
191
+
192
+ You may add this task to crontab.
193
+
194
+ ##### Using 'whenever' to schedule build of occurrences
195
+
142
196
  With the 'whenever' gem this can be easily achieved.
197
+
143
198
  ```
144
199
  gem 'whenever', :require => false
145
200
  ```
146
- Create the 'whenever'-configuration file:
147
- ```
201
+
202
+ Generate the 'whenever'-configuration file:
203
+
204
+ ```cli
148
205
  wheneverize .
149
206
  ```
207
+
150
208
  Open up the file 'config/schedule.rb' and add the job:
151
- ```
209
+
210
+ ```ruby
152
211
  set :environment, "development"
153
212
  set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
154
213
 
@@ -156,18 +215,23 @@ every 1.day do
156
215
  rake "schedulable:build_occurrences"
157
216
  end
158
217
  ```
159
- Write to the crontab:
160
- ```
218
+
219
+ Write to crontab:
220
+
221
+ ```cli
161
222
  whenever -w
162
223
  ```
163
224
 
164
225
  ### Configuration
165
226
  Generate the configuration file
166
- ```
227
+
228
+ ```cli
167
229
  rails g schedulable:config
168
230
  ```
231
+
169
232
  Open 'config/initializers/schedulable.rb' and edit options as you need:
170
- ```
233
+
234
+ ```ruby
171
235
  Schedulable.configure do |config|
172
236
  config.max_build_count = 0
173
237
  config.max_build_period = 1.year
@@ -2,7 +2,11 @@ class ScheduleInput < SimpleForm::Inputs::Base
2
2
 
3
3
 
4
4
  def input
5
-
5
+ weekdays = Date::DAYNAMES.map(&:downcase)
6
+ daynames = I18n.t('date.day_names')
7
+ daylabels = Hash[weekdays.zip(daynames)]
8
+ weekdays = weekdays.slice(1..7) << weekdays.slice(0)
9
+
6
10
  input_html_options[:type] ||= input_type if html5?
7
11
 
8
12
  # options
@@ -10,7 +14,6 @@ class ScheduleInput < SimpleForm::Inputs::Base
10
14
  input_options[:until] = !input_options[:until].nil? ? input_options[:until] : true
11
15
  input_options[:count] = !input_options[:count].nil? ? input_options[:count] : true
12
16
 
13
-
14
17
  @builder.simple_fields_for(:schedule, @builder.object.schedule || @builder.object.build_schedule) do |b|
15
18
 
16
19
  b.template.content_tag("div", {id: b.object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")}) do
@@ -22,34 +25,33 @@ class ScheduleInput < SimpleForm::Inputs::Base
22
25
  end <<
23
26
 
24
27
  template.content_tag("div", {data: {group: 'weekly'}}) do
25
- b.input :days, collection: Time::DAYS_INTO_WEEK.invert.values, label_method: lambda { |v| I18n.t("date.day_names")[Time::DAYS_INTO_WEEK[v]] || v.capitalize }, as: :check_boxes
28
+ b.input :days, collection: weekdays, label_method: lambda { |v| ("&nbsp;" + daylabels[v]).html_safe}, as: :check_boxes
26
29
  end <<
27
30
 
28
31
  template.content_tag("div", {data: {group: 'monthly'}}) do
32
+
29
33
  b.simple_fields_for :day_of_week, OpenStruct.new(b.object.day_of_week || {}) do |db|
30
-
31
- template.content_tag("div", class: 'form-group') do
32
-
33
- db.label(I18n.t("activerecord.attributes.schedule.day_of_week"), required: false) <<
34
-
34
+ template.content_tag("div", class: 'form-group' + (b.object.errors[:day_of_week].any? ? " has-error" : "")) do
35
+ b.label(:day_of_week, error: true) <<
35
36
  template.content_tag("table", style: 'min-width: 280px') do
36
37
  template.content_tag("tr") do
37
38
  template.content_tag("td") <<
38
39
  ['1st', '2nd', '3rd', '4th', 'last'].reduce(''.html_safe) { | x, item |
39
40
  x << template.content_tag("td") do
40
41
  db.label(I18n.t("schedulable.monthly_week_names.#{item}") || item, required: false)
41
- end
42
+ end
42
43
  }
43
44
  end <<
44
- Time::DAYS_INTO_WEEK.invert.values.reduce(''.html_safe) { | x, weekday |
45
+ weekdays.reduce(''.html_safe) do | x, weekday |
45
46
  x << template.content_tag("tr") do
46
47
  template.content_tag("td") do
47
- db.label I18n.t("date.day_names")[Time::DAYS_INTO_WEEK[weekday]] || weekday, required: false
48
+ db.label daylabels[weekday] || weekday, required: false
48
49
  end <<
49
50
  db.collection_check_boxes(weekday.to_sym, [1, 2, 3, 4, -1], lambda { |i| i} , lambda { |i| "&nbsp;".html_safe}, item_wrapper_tag: :td, checked: db.object.send(weekday))
50
51
  end
51
- }
52
- end
52
+ end
53
+ end <<
54
+ b.error(:day_of_week)
53
55
  end
54
56
  end
55
57
  end <<
@@ -75,7 +77,7 @@ class ScheduleInput < SimpleForm::Inputs::Base
75
77
  end <<
76
78
 
77
79
  template.javascript_tag(
78
- "(function() {" <<
80
+ "$(function() {" <<
79
81
  " var container = $(\"*[id='#{b.object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")}']\");" <<
80
82
  " var select = container.find(\"select[name*='rule']\");" <<
81
83
  " function update() {" <<
@@ -91,7 +93,7 @@ class ScheduleInput < SimpleForm::Inputs::Base
91
93
  " }" <<
92
94
  " select.on('change', update);" <<
93
95
  " update.call(select[0]);" <<
94
- "})()"
96
+ "})"
95
97
  )
96
98
 
97
99
 
@@ -26,7 +26,4 @@ de:
26
26
  singular: Einmalig
27
27
  monthly: Monatlich
28
28
  weekly: Wöchentlich
29
- daily: Täglich
30
-
31
-
32
-
29
+ daily: Täglich
@@ -26,7 +26,4 @@ en:
26
26
  singular: Singular
27
27
  monthly: Monthly
28
28
  weekly: Weekly
29
- daily: Daily
30
-
31
-
32
-
29
+ daily: Daily
@@ -1,3 +1,3 @@
1
1
  module Schedulable
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schedulable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Nowrotek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-20 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ice_cube
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Handling recurring events in rails.
@@ -45,6 +45,9 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
48
51
  - lib/generators/schedulable/config_generator.rb
49
52
  - lib/generators/schedulable/install_generator.rb
50
53
  - lib/generators/schedulable/locale_generator.rb
@@ -58,15 +61,12 @@ files:
58
61
  - lib/generators/schedulable/templates/migrations/create_schedules.rb
59
62
  - lib/generators/schedulable/templates/models/occurrence.erb
60
63
  - lib/generators/schedulable/templates/models/schedule.rb
64
+ - lib/schedulable.rb
61
65
  - lib/schedulable/acts_as_schedulable.rb
62
66
  - lib/schedulable/railtie.rb
63
67
  - lib/schedulable/schedule_support.rb
64
68
  - lib/schedulable/version.rb
65
- - lib/schedulable.rb
66
69
  - lib/tasks/schedulable_tasks.rake
67
- - MIT-LICENSE
68
- - Rakefile
69
- - README.md
70
70
  homepage: http://github.com/benignware
71
71
  licenses: []
72
72
  metadata: {}
@@ -76,17 +76,17 @@ require_paths:
76
76
  - lib
77
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ! '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ! '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.1.11
89
+ rubygems_version: 2.2.2
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Handling recurring events in rails.