README.md in simple_calendar-2.1.5 vs README.md in simple_calendar-2.2.0
- old
+ new
@@ -18,13 +18,14 @@
Installation
------------
Just add this into your Gemfile followed by a bundle install:
+```ruby
+gem "simple_calendar", "~> 2.0"
+```
- gem "simple_calendar", "~> 2.0"
-
Usage
-----
Generating calendars is extremely simple with simple_calendar.
@@ -66,10 +67,22 @@
<% end %>
```
Setting `number_of_days` is optional and defaults to 4.
+### Custom Partial
+
+You can set a different partial name for calendars by passing the partial path.
+
+```erb
+<%= calendar partial: 'products/calendar' do |date| %>
+ <%= date %>
+<% end %>
+```
+
+Setting `number_of_days` is optional and defaults to 4.
+
## Rendering Events
What's a calendar without events in it? There are two simple steps for creating
calendars with events.
@@ -77,28 +90,33 @@
model called Meeting, but you can add this to any model or Ruby object.
Here's an example model:
```bash
-rails g scaffold Meeting name start_time:datetime
+# single day events
+$ rails g scaffold Meeting name start_time:datetime
+
+# multi-day events
+$ rails g scaffold Meeting name start_time:datetime end_time:datetime
```
-By default it uses `start_time` as the attribute name.
+By default it uses `start_time` as the attribute name. Optionally the `end_time`
+attribute can be used which enables multi-day event rendering.
-**If you'd like to use another attribute other than start_time, just
-pass it in as the `attribute` option**
+**If you'd like to use another attribute other than start_time or end_time, just
+pass it in as the `attribute` or `end_attribute` options respectively**
```erb
<%= month_calendar(attribute: :starts_at) do |date| %>
<%= date %>
<% end %>
```
**If you already have a model with a start time attribute called something other than `start_time` or accesses it through a relationship, you can alias the attribute by defining a `start_time` method in the my_model.rb file and not have to specify it separately as in the above example**
```ruby
class MyModel
## Other code related to your model lives here
-
+
def start_time
self.my_related_model.start ##Where 'start' is a attribute of type 'Date' accessible through MyModel's relationship
end
end
```
@@ -144,11 +162,11 @@
You can customize the layouts for each of the calendars by running the
generators for simple_calendar:
```bash
-rails g simple_calendar:views
+$ rails g simple_calendar:views
```
This will generate a folder in app/views called simple_calendar that you
edit to your heart's desire.
@@ -208,13 +226,10 @@
### Custom CSS Classes
Setting classes on the table and elements are pretty easy.
-You can simply run the following command to install the calendar views
-and then add your own helpers to the table, rows, headers, and days.
-
simple_calendar comes with a handful of useful classes for each day in
the calendar that you can use:
```scss
.simple-calendar {
@@ -290,18 +305,18 @@
The main method you'll need to implement is the `date_range` so that
your calendar can have a custom length.
-```
+```ruby
class SimpleCalendar::BusinessWeekCalendar
private
def date_range
beginning = start_date.beginning_of_week + 1.day
ending = start_date.end_of_week - 1.day
- (beginning..ending)
+ (beginning..ending).to_a
end
end
```
To render this in the view, you can do:
@@ -336,10 +351,9 @@
With modifications as appropriate.
## TODO
-- Multi-day events
- Rspec tests for Calendar
- Rspec tests for MonthCalendar
- Rspec tests for WeekCalendar
## Author