holidays_img 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -9
- data/lib/holidays_img/base.rb +2 -1
- data/lib/holidays_img/image_tag_wrapper.rb +3 -1
- data/lib/holidays_img/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0be67fcb81c827f829c0f1a7022e333477f958d
|
4
|
+
data.tar.gz: c3284d9944346ccbb5e348417fe82b887f7468b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1769d5c8d1cf8f7ed95c95926b1c9a687ab3a3d280dbe5a71788bcf52eeebc73160499ecdfc25c26b1fad11df2dd31a41a4bb4728d35497bcd92183bb2b3e74
|
7
|
+
data.tar.gz: d85ea2729c79419e991d17dda9fddc2d29758ade4ff50b4f1d5058bb028a19c31733b361d0239f00530d934dee14579d89bbe16a712a74421359af14994c8a35
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# holidays_img
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/holidays_img.svg)](https://badge.fury.io/rb/holidays_img)
|
4
|
+
|
3
5
|
This gem is a simple wrapper for Rails's `image_tag` helper. Leveraging the `holidays` gem, it allows you to easily load images based on the holiday occurring on any given date.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
Add
|
9
|
+
Add the gem to your application's Gemfile:
|
8
10
|
|
9
11
|
```ruby
|
10
12
|
gem 'holidays_img'
|
@@ -18,13 +20,19 @@ $ bundle
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
Simply use the `holidays_image_tag` helper as you would a standard Rails `image_tag
|
23
|
+
Simply use the `holidays_image_tag` helper as you would a standard Rails `image_tag`:
|
24
|
+
|
25
|
+
```
|
26
|
+
<%= holidays_image_tag 'image.jpg' %>
|
27
|
+
```
|
28
|
+
|
29
|
+
To ensure proper loading of images, adhere to the following naming convention:
|
22
30
|
|
23
31
|
- 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)
|
24
|
-
- Name your holiday images in the following format: `original_name_holiday_name`
|
32
|
+
- Name your holiday images in the following format: `original_name_holiday_name.ext`
|
25
33
|
- Ensure all holiday images are in the same directory
|
26
34
|
|
27
|
-
Naming
|
35
|
+
Naming Example:
|
28
36
|
|
29
37
|
```
|
30
38
|
image.jpg
|
@@ -34,24 +42,27 @@ image_independence_day.jpg
|
|
34
42
|
...
|
35
43
|
```
|
36
44
|
|
37
|
-
See the
|
45
|
+
See the Holidays gem's [definition files](https://github.com/holidays/definitions) for a list of holidays for any available region.
|
38
46
|
|
39
47
|
## Configuration
|
40
48
|
|
41
49
|
You can configure options using an initializer:
|
42
50
|
|
43
51
|
```ruby
|
44
|
-
#
|
52
|
+
# config/initializers/holidays_img.rb
|
45
53
|
|
46
54
|
HolidaysImg.configure do |config|
|
47
55
|
# Load holidays based on region, defaults to :us
|
48
56
|
config.region = :ca
|
49
|
-
# Only load images for holidays you specify
|
50
|
-
|
51
|
-
|
57
|
+
# Only load images for holidays you specify
|
58
|
+
config.whitelist = ['Christmas Day', 'Mother\'s Day']
|
59
|
+
# Load custom holidays from file, can also pass array of file paths
|
60
|
+
config.custom_holidays = '/path/to/custom_holidays.yml'
|
52
61
|
end
|
53
62
|
```
|
54
63
|
|
64
|
+
For info on how to format custom holiday definitions, see the Holidays gem's [definition syntax documentation](https://github.com/holidays/definitions/blob/master/SYNTAX.md).
|
65
|
+
|
55
66
|
## License
|
56
67
|
|
57
68
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/holidays_img/base.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module HolidaysImg
|
2
2
|
module ImageTagWrapper
|
3
3
|
def holidays_image_tag(source, options={})
|
4
|
+
Holidays.load_custom(HolidaysImg.custom_holidays) if HolidaysImg.custom_holidays
|
5
|
+
|
4
6
|
date = options[:date] || Date.today
|
5
7
|
holiday = Holidays.on(date, HolidaysImg.region).first
|
6
8
|
|
@@ -8,7 +10,7 @@ module HolidaysImg
|
|
8
10
|
original_source = source.dup
|
9
11
|
substring_index = source.rindex('.')
|
10
12
|
|
11
|
-
if HolidaysImg.whitelist.
|
13
|
+
if HolidaysImg.whitelist.blank? || HolidaysImg.whitelist.include?(holiday[:name])
|
12
14
|
source.insert(substring_index, "_#{holiday[:name].parameterize(separator: '_')}")
|
13
15
|
|
14
16
|
unless File.exists?("#{Rails.root}/app/assets/images/#{source}")
|
data/lib/holidays_img/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidays_img
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran Pesic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holidays
|