jekyll-truthyfalsy 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -19
- data/lib/jekyll-truthyfalsy/version.rb +1 -1
- data/lib/jekyll-truthyfalsy.rb +2 -2
- data/spec/jekyll-truthyfalsy_spec.rb +19 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfea5b16fc9b87be39842ea2b737d73f12704d15f9494af8fb5e9c6369349536
|
4
|
+
data.tar.gz: 675fc5000ab5ac2fb897067fb5ed6d2baf116f67208274947011b7ee80cb819d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44880789333e1af31f786e9b8bac5c298b91371f16d1195ed24f8e34928072f2a117a13b13b1d5db4555907435598dd8708ca9f8cdf51f03fc40249eabbd14d7
|
7
|
+
data.tar.gz: d9cbb6c6c2652a4e924ce4899d8ac709db058b026320fa15855cf05f0fc5094d08959cb62cfaf645f1e05646731e8f989e121efa17cefdc34202a76dc256a220
|
data/README.md
CHANGED
@@ -33,7 +33,6 @@ Yes, this module works in both Node and browser environments, including compatib
|
|
33
33
|
* Exposes a `isfalsy` function
|
34
34
|
|
35
35
|
# Jekyll::truthyfalsy
|
36
|
-
|
37
36
|
Meet `jekyll-truthyfalsy`, the whimsical gem dedicated to turning the grey areas of truthiness and falsiness into black and white.
|
38
37
|
|
39
38
|
It doesn't just settle for mere booleans; oh no, it goes above and beyond, scrutinizing empty strings and null values too! Like a tenacious detective, it leaves no stone unturned, and no value unverified. Banish the verbose 'if' statements and welcome a new era of compact, expressive checks.
|
@@ -41,7 +40,6 @@ It doesn't just settle for mere booleans; oh no, it goes above and beyond, scrut
|
|
41
40
|
Because life is too short for ambiguity, embrace the certainty that comes with `jekyll-truthyfalsy`. Truthiness and falsiness: not just a philosophical quandary, but a .gem installation away!
|
42
41
|
|
43
42
|
## Installation
|
44
|
-
|
45
43
|
Install the gem and add to the application's Gemfile by executing:
|
46
44
|
```shell
|
47
45
|
bundle add jekyll-truthyfalsy
|
@@ -53,38 +51,66 @@ gem install jekyll-truthyfalsy
|
|
53
51
|
```
|
54
52
|
|
55
53
|
## Usage
|
56
|
-
Now you can use the istruthy and isfalsy filters in your Jekyll site's templates:
|
54
|
+
Now you can use the `istruthy` and `isfalsy` filters in your Jekyll site's templates:
|
57
55
|
|
58
56
|
```liquid
|
59
|
-
{
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
{
|
66
|
-
|
67
|
-
{
|
68
|
-
|
69
|
-
{
|
57
|
+
{%- assign test_true = true | istruthy -%}
|
58
|
+
{%- if test_true -%}
|
59
|
+
This will print because `true` is truthy
|
60
|
+
{%- endif -%}
|
61
|
+
|
62
|
+
{%- assign test_false = false | istruthy -%}
|
63
|
+
{%- if test_false -%}
|
64
|
+
This will NOT print because `false` is falsy
|
65
|
+
{%- endif -%}
|
66
|
+
|
67
|
+
{%- assign test_string = 'hi' | istruthy -%}
|
68
|
+
{%- if test_string -%}
|
69
|
+
This will print because `'hi'` is truthy
|
70
|
+
{%- endif -%}
|
71
|
+
|
72
|
+
{%- assign test_empty_string = '' | istruthy -%}
|
73
|
+
{%- if test_empty_string -%}
|
74
|
+
This will NOT print because `''` is falsy
|
75
|
+
{%- endif -%}
|
76
|
+
|
77
|
+
{%- assign test_null = null | istruthy -%}
|
78
|
+
{%- if test_null -%}
|
79
|
+
This will NOT print because `null` is falsy
|
80
|
+
{%- endif -%}
|
81
|
+
|
82
|
+
{%- assign test_zero = 0 | istruthy -%}
|
83
|
+
{%- if test_zero -%}
|
84
|
+
This will NOT print because `0` is falsy
|
85
|
+
{%- endif -%}
|
86
|
+
|
87
|
+
{%- assign test_one = 1 | istruthy -%}
|
88
|
+
{%- if test_one -%}
|
89
|
+
This will print because `1` is truthy
|
90
|
+
{%- endif -%}
|
70
91
|
```
|
71
92
|
|
72
93
|
These examples show how you can use `istruthy` and `isfalsy` to easily check if a variable is "truthy" (not null, not an empty string, and not false) or "falsy" (null, an empty string, or false), respectively.
|
73
94
|
|
74
|
-
No more long, confusing, multi-condition
|
95
|
+
No more long, confusing, multi-condition `if` statements - just simple, readable code!
|
75
96
|
|
76
97
|
## Development
|
77
|
-
|
78
98
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
99
|
|
80
100
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
81
101
|
|
82
102
|
### Building and pushing
|
103
|
+
Run the tests
|
104
|
+
```shell
|
105
|
+
bundle exec rspec
|
106
|
+
```
|
107
|
+
|
108
|
+
Publish the Gem
|
83
109
|
```shell
|
84
110
|
gem build jekyll-truthyfalsy.gemspec
|
85
|
-
|
111
|
+
|
112
|
+
gem push jekyll-truthyfalsy-1.0.0.gem
|
86
113
|
```
|
87
114
|
|
88
115
|
## Contributing
|
89
|
-
|
90
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-truthyfalsy.
|
116
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/itw-creative-works/jekyll-truthyfalsy.
|
data/lib/jekyll-truthyfalsy.rb
CHANGED
@@ -3,11 +3,11 @@ require "jekyll"
|
|
3
3
|
module Jekyll
|
4
4
|
module TruthyFalsy
|
5
5
|
def istruthy(input)
|
6
|
-
!(input.nil? || input == '' || input == false)
|
6
|
+
!(input.nil? || input == '' || input == false || input == 0)
|
7
7
|
end
|
8
8
|
|
9
9
|
def isfalsy(input)
|
10
|
-
input.nil? || input == '' || input == false
|
10
|
+
input.nil? || input == '' || input == false || input == 0
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -8,6 +8,7 @@ RSpec.describe Jekyll::TruthyFalsy do
|
|
8
8
|
|
9
9
|
let(:dummy) { DummyClass.new }
|
10
10
|
|
11
|
+
# Truthy values
|
11
12
|
describe '.istruthy' do
|
12
13
|
it 'returns true for non-empty string' do
|
13
14
|
expect(dummy.istruthy('hello')).to be(true)
|
@@ -28,8 +29,17 @@ RSpec.describe Jekyll::TruthyFalsy do
|
|
28
29
|
it 'returns false for nil' do
|
29
30
|
expect(dummy.istruthy(nil)).to be(false)
|
30
31
|
end
|
31
|
-
end
|
32
32
|
|
33
|
+
it 'returns true for integer 1' do
|
34
|
+
expect(dummy.istruthy(1)).to be(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns false for integer 0' do
|
38
|
+
expect(dummy.istruthy(0)).to be(false)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Falsy values
|
33
43
|
describe '.isfalsy' do
|
34
44
|
it 'returns false for non-empty string' do
|
35
45
|
expect(dummy.isfalsy('hello')).to be(false)
|
@@ -50,5 +60,13 @@ RSpec.describe Jekyll::TruthyFalsy do
|
|
50
60
|
it 'returns true for nil' do
|
51
61
|
expect(dummy.isfalsy(nil)).to be(true)
|
52
62
|
end
|
63
|
+
|
64
|
+
it 'returns false for integer 1' do
|
65
|
+
expect(dummy.isfalsy(1)).to be(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns true for integer 0' do
|
69
|
+
expect(dummy.isfalsy(0)).to be(true)
|
70
|
+
end
|
53
71
|
end
|
54
72
|
end
|