0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
A holiday-aware image_tag wrapper.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0

Runtime

~> 5.0
 Project Readme

holidays_img

Gem Version

A simple wrapper for Rails's image_tag helper. Leveraging the holidays gem, it allows you to load images based on the holiday occurring on a given date.

Installation

Add the gem to your application's Gemfile:

gem 'holidays_img'

And then execute:

$ bundle

Usage

Simply use the holidays_image_tag helper as you would a standard Rails image_tag:

<%= holidays_image_tag 'image.jpg' %>

To ensure proper loading of images, adhere to the following naming convention:

  • Have a default image, used for when a day does not fall on a holiday (also acts as a fallback for when a holiday image cannot be found)
  • Name your holiday images in the following format: original_name_holiday_name.ext
  • Ensure all holiday images are in the same directory

Naming Example:

image.jpg
image_christmas_day.jpg
image_new_year_s_day.jpg
image_independence_day.jpg
...

See the Holidays gem's definition files for a list of holidays for any available region.

Configuration

You can configure options using an initializer:

# config/initializers/holidays_img.rb

HolidaysImg.configure do |config|
  # Load holidays based on region, defaults to :us
  config.region    = :ca
  # Only load images for holidays you specify
  config.whitelist = ['Christmas Day', 'Mother\'s Day']
  # Load custom holidays from file, can also pass array of file paths
  config.custom_holidays = '/path/to/custom_holidays.yml'
end

For info on how to format custom holiday definitions, see the Holidays gem's definition syntax documentation.

License

The gem is available as open source under the terms of the MIT License.