Cyclical for Rails
Integration with ruby and JavaScript versions of Cyclical recurring events library for yourrails application.
About
Cyclical lets you list recurring events with complex recurrence rules like "every 4 years, the first Tuesday after a Monday in November" in a simple way both in the front-end and the back-end of your application.
Install
Add the cyclical-rails
gem in your Gemfile
gem "cyclical-rails"
The cyclical
JavaScript library will be added to the asset pipeline. To use them add the following to app/assets/javascript/application.js
:
//= require cyclical
Usage
Ruby & JavaScript
In your controller you do:
schedule = Cyclical::Schedule.new Time.now, Cyclical::Rule.daily(2).count(3)
schedule.occurrences
in your javascript you do:
var schedule = new Schedule(new Date, Schedule.Rule.daily(2).count(3));
var occ = schedule.occurrences();
and you get the same results.
You can send schedules over the wire as JSON. Serialize in ERB
schedule_json = '<%= @schedule.to_json.html_safe %>';
and load in javascript
var schedule = Schedule.fromJSON(schedule_json);
The same also works the other way round.
For more information about Cyclical and Cyclical.js see the respective repos.
License
Released under the MIT License.