README.md in simple_calendar-2.4.1 vs README.md in simple_calendar-2.4.2

- old
+ new

@@ -1,29 +1,30 @@ -![travis ci](https://travis-ci.org/excid3/simple_calendar.svg?branch=master) +# Simple Calendar -Simple Calendar -=============== +### 📆 A calendar for your Ruby on Rails app. -Simple Calendar is designed to do one thing really really well: render a -calendar. It lets you render a calendar of any size. Maybe you want a +[![Build Status](https://github.com/excid3/simple_calendar/workflows/Tests/badge.svg)](https://github.com/excid3/simple_calendar/actions) [![Gem Version](https://badge.fury.io/rb/simple_calendar.svg)](https://badge.fury.io/rb/simple_calendar) + +Simple Calendar is designed to do one thing really really well: render a calendar. + +It lets you render a calendar of any size. Maybe you want a day view, a 4 day agenda, a week view, a month view, or a 6 week calendar. You can do all of that with the new gem, just give it a range of dates to render. -It doesn't depend on any ORM so you're free to use it with ActiveRecord, -Mongoid, any other ORM, or pure Ruby objects. +It doesn't depend on any ORM so you're free to use it with ActiveRecord, Mongoid, any other ORM, or pure Ruby objects. Thanks to all contributors for your wonderful help! ![calendar](https://s3.amazonaws.com/f.cl.ly/items/1T0t1s0W212d28282V2M/Screen%20Shot%202013-03-28%20at%209.44.49%20AM.png) Installation ------------ Just add this into your Gemfile followed by a bundle install: ```ruby -gem "simple_calendar", "~> 2.0" +gem "simple_calendar", "~> 2.4" ``` If you're using Bootstrap, the calendar should already have a border and nice spacing for days. @@ -32,10 +33,17 @@ ```scss *= require simple_calendar ``` +or in your SCSS `app/assets/stylesheets/application.scss` file: + +```scss +@import "simple_calendar"; +``` + + Usage ----- Generating calendars is extremely simple with simple_calendar. @@ -60,11 +68,11 @@ ### Week Calendar You can generate a week calendar with the `week_calendar` method. ```erb -<%= week_calendar number_of_weeks: 2 do |date| %> +<%= week_calendar(number_of_weeks: 2) do |date| %> <%= date %> <% end %> ``` Setting `number_of_weeks` is optional and defaults to 1. @@ -72,11 +80,11 @@ ### Custom Length Calendar You can generate calendars of any length by passing in the number of days you want to render. ```erb -<%= calendar number_of_days: 4 do |date| %> +<%= calendar(number_of_days: 4) do |date| %> <%= date %> <% end %> ``` Setting `number_of_days` is optional and defaults to 4. @@ -85,25 +93,52 @@ You can pass in `start_date_param` to change the name of the parameter in the URL for the current calendar view. ```erb -<%= calendar start_date_param: :my_date do |date| %> +<%= calendar(start_date_param: :my_date) do |date| %> <%= date %> <% end %> ``` ### Custom Partial You can set a different partial name for calendars by passing the partial path. ```erb -<%= calendar partial: 'products/calendar' do |date| %> +<%= calendar(partial: 'products/calendar') do |date| %> <%= date %> <% end %> ``` +### Internationalization (I18n) + +The default views are prepared to do translation lookups for month names and weekdays. + +To profit from that, you can take advantage of the [`rails-i18n`](https://github.com/svenfuchs/rails-i18n/) gem which comes with translations for many languages already. + +In a Rails 6 app, the configuration could look like the following: + + * Add `gem 'rails-i18n'` to your `Gemfile` and run `bundle`. + * Define the available and default locale e.g. in `config/application.rb`: +```ruby +# config/application.rb +config.i18n.available_locales = [:en, :de, :fr] +config.i18n.default_locale = :en +``` + * Define the following translation keys: +```yaml +# e.g. config/locales/de.yml +de: + simple_calendar: + previous: "<<" + next: ">>" + week: Woche +``` + +See the [Rails I18n Guide](https://guides.rubyonrails.org/i18n.html) for further information. + ## Rendering Events What's a calendar without events in it? There are two simple steps for creating calendars with events. @@ -118,11 +153,11 @@ # 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. **If you'd like to use another attribute other than start_time, just pass it in as the `attribute`** ```erb <%= month_calendar(attribute: :starts_at) do |date| %> @@ -158,19 +193,21 @@ We'll just load up all the meetings for this example. ```ruby def index - @meetings = Meeting.all + # Scope your query to the dates being shown: + start_date = params.fetch(:start_date, Date.today).to_date + @meetings = Meeting.where(starts_at: start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week) end ``` Then in your view, you can pass in the `events` option to render. The meetings will automatically be filtered out by day for you. ```erb -<%= month_calendar events: @meetings do |date, meetings| %> +<%= month_calendar(events: @meetings) do |date, meetings| %> <%= date %> <% meetings.each do |meeting| %> <div> <%= meeting.name %> @@ -380,9 +417,13 @@ Chris Oliver <chris@gorails.com> [https://gorails.com](https://gorails.com) [@excid3](https://twitter.com/excid3) + +## License + +Simple Calendar is licensed under the [MIT License](LICENSE.txt). ## Support Need help