Sha256: 89f4b7e294d7e25a3596b25f5d7df1f2b514198abe81dd67bdcaf4315f92870e

Contents?: true

Size: 677 Bytes

Versions: 1

Compression:

Stored size: 677 Bytes

Contents

module HolidaysImg
  module ImageTagWrapper
    def holidays_image_tag(source, options={})
      date = options[:date] || Date.today
      holiday = Holidays.on(date, HolidaysImg.region).first

      if holiday
        original_source = source.dup
        substring_index = source.rindex('.')

        if HolidaysImg.whitelist.empty? || HolidaysImg.whitelist.include?(holiday[:name])
          source.insert(substring_index, "_#{holiday[:name].parameterize(separator: '_')}")

          unless File.exists?("#{Rails.root}/app/assets/images/#{source}")
            source = original_source
          end
        end
      end

      image_tag(source, options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
holidays_img-1.0.0 lib/holidays_img/image_tag_wrapper.rb