jekyll-pluralize 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE.md +21 -0
- data/README.md +97 -0
- data/lib/jekyll-pluralize.rb +49 -0
- data/lib/jekyll/pluralize/version.rb +9 -0
- data/spec/pluralize_spec.rb +54 -0
- data/spec/spec_helper.rb +15 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 247bb30b104cb48e834c55bf9efaffc12fe2ed813cd4c6b41091264c5934112a
|
4
|
+
data.tar.gz: '028fbae3322a0b0ee16af79463fd38318e138b25b9ae665abcfa3721e5c6c0b8'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8efc7f67b1c0cab704c3f5c94e3a98edf765da55977fe88dd5da061e310591d659e60f6aef3ee70241fe93f661b5a3be6d2d6cb71aae64e1ae65548a8a01231
|
7
|
+
data.tar.gz: 819be8128592cd4399cf2b7ce5bc516dfe64151d025915dc6f229116c088df89098e6abb26dc1f10942128054bae915eb07d8a8ce29157729616639cc86bd1d8
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 David Demonchy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# jekyll-pluralize
|
2
|
+
|
3
|
+
[](https://travis-ci.com/fusco/jekyll-pluralize)
|
4
|
+
|
5
|
+
A plugin to make an simple pluralize with Jekyll.
|
6
|
+
|
7
|
+
## installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'jekyll-pluralize'
|
13
|
+
```
|
14
|
+
|
15
|
+
and add this line in your application's `_config.yml` :
|
16
|
+
|
17
|
+
```yml
|
18
|
+
# _config.yml
|
19
|
+
|
20
|
+
plugins:
|
21
|
+
- jekyll-pluralize
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
In you html file, use liquid syntax with :
|
27
|
+
|
28
|
+
```liquid
|
29
|
+
{{ number | pluralize: 'singular', 'plural' }}
|
30
|
+
```
|
31
|
+
### with singular and plural words
|
32
|
+
|
33
|
+
If `page.posts.size = 1` or `page.posts.size = 0`
|
34
|
+
|
35
|
+
```liquid
|
36
|
+
<span>
|
37
|
+
{{ page.post.size }}
|
38
|
+
{{ page.post.size | pluralize: 'post', 'posts' }}
|
39
|
+
</span>
|
40
|
+
```
|
41
|
+
|
42
|
+
render :
|
43
|
+
|
44
|
+
```html
|
45
|
+
<span>
|
46
|
+
1 post or 0 post
|
47
|
+
</span>
|
48
|
+
```
|
49
|
+
|
50
|
+
If `page.posts.size >= 2`
|
51
|
+
|
52
|
+
```liquid
|
53
|
+
<span>
|
54
|
+
{{ page.post.size }}
|
55
|
+
{{ page.post.size | pluralize: 'post', 'posts' }}
|
56
|
+
</span>
|
57
|
+
```
|
58
|
+
|
59
|
+
render :
|
60
|
+
|
61
|
+
```html
|
62
|
+
<span>
|
63
|
+
2 posts
|
64
|
+
</span>
|
65
|
+
```
|
66
|
+
### with singular and without plural words
|
67
|
+
|
68
|
+
If `page.posts.size = 1` or `page.posts.size = 0`
|
69
|
+
|
70
|
+
```liquid
|
71
|
+
<span>
|
72
|
+
{{ page.post.size }}
|
73
|
+
{{ page.post.size | pluralize: 'post' }}
|
74
|
+
</span>
|
75
|
+
```
|
76
|
+
|
77
|
+
```html
|
78
|
+
<span>
|
79
|
+
1 post or 0 post
|
80
|
+
</span>
|
81
|
+
```
|
82
|
+
If `page.posts.size >= 2`
|
83
|
+
|
84
|
+
```liquid
|
85
|
+
<span>
|
86
|
+
{{ page.post.size }}
|
87
|
+
{{ page.post.size | pluralize: 'post' }}
|
88
|
+
</span>
|
89
|
+
```
|
90
|
+
|
91
|
+
render :
|
92
|
+
|
93
|
+
```html
|
94
|
+
<span>
|
95
|
+
2 posts
|
96
|
+
</span>
|
97
|
+
```
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# jekyll module
|
4
|
+
module Jekyll
|
5
|
+
# Pluralize
|
6
|
+
module Pluralize
|
7
|
+
# pluralize method {{ number | pluralize: 'word', words' }}
|
8
|
+
def pluralize(*args)
|
9
|
+
analyzed_words(args[0], args[1], args[2]) if args[0].numeric?
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def analyzed_words(number, singular, plural)
|
15
|
+
if plural.nil?
|
16
|
+
plural_undefined(number, singular)
|
17
|
+
else
|
18
|
+
plural_defined(number, singular, plural)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def plural_defined(number, singular, plural)
|
23
|
+
one_item(number) ? singular : plural
|
24
|
+
end
|
25
|
+
|
26
|
+
def plural_undefined(number, singular)
|
27
|
+
one_item(number) ? singular : singular.concat('s')
|
28
|
+
end
|
29
|
+
|
30
|
+
def one_item(number)
|
31
|
+
return true if number.to_i.equal?(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Override Integer CLass
|
37
|
+
class Integer
|
38
|
+
def numeric?
|
39
|
+
return true if self =~ /\A\d+\Z/
|
40
|
+
|
41
|
+
begin
|
42
|
+
true if Float(self)
|
43
|
+
rescue TypeError
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Liquid::Template.register_filter(Jekyll::Pluralize)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe(Jekyll::Pluralize) do
|
6
|
+
let(:output) do
|
7
|
+
pluralize(number, word, words)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'pluzalize with plural args and 2 items' do
|
11
|
+
let(:word) { 'post' }
|
12
|
+
let(:words) { 'posts' }
|
13
|
+
let(:number) { 2 }
|
14
|
+
let(:content) { "{{ '#{number}' | pluralize: '#{word}', '#{words}' }}" }
|
15
|
+
it 'produces the correct plural string' do
|
16
|
+
expect(output).to eq(words)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'not pluzalize with the plural args and 1 item' do
|
21
|
+
let(:word) { 'post' }
|
22
|
+
let(:words) { 'posts' }
|
23
|
+
let(:number) { 1 }
|
24
|
+
let(:content) { "{{ '#{number}' | pluralize: '#{word}', '#{words}' }}" }
|
25
|
+
it 'produces the correct singular string' do
|
26
|
+
expect(output).to eq(word)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe(Jekyll::Pluralize) do
|
32
|
+
let(:output) do
|
33
|
+
pluralize(number, word)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'pluzalize without plural args and 2 items' do
|
37
|
+
let(:word) { 'post' }
|
38
|
+
let(:words) { 'posts' }
|
39
|
+
let(:number) { 2 }
|
40
|
+
let(:content) { "{{ '#{number}' | pluralize: '#{word}' }}" }
|
41
|
+
it 'produces the correct plural string' do
|
42
|
+
expect(output).to eq(words)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'not pluzalize without plural args and 1 item' do
|
47
|
+
let(:word) { '1 post' }
|
48
|
+
let(:number) { 1 }
|
49
|
+
let(:content) { "{{ '#{number}' | pluralize: '#{word}' }}" }
|
50
|
+
it 'produces the correct singular' do
|
51
|
+
expect(output).to eq(word)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jekyll'
|
4
|
+
require 'liquid'
|
5
|
+
require File.expand_path('../lib/jekyll-pluralize.rb', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
Jekyll.logger.log_level = :error
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
config.order = 'random'
|
13
|
+
|
14
|
+
include Jekyll::Pluralize
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-pluralize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Demonchy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 13.0.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 13.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.71'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.71'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-jekyll
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: pluralize liquid filter for Jekyll
|
84
|
+
email:
|
85
|
+
- david@demonchy.info
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- CHANGELOG.md
|
91
|
+
- LICENSE.md
|
92
|
+
- README.md
|
93
|
+
- lib/jekyll-pluralize.rb
|
94
|
+
- lib/jekyll/pluralize/version.rb
|
95
|
+
- spec/pluralize_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/fusco/jekyll-pluralize
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.1.4
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: liquid filter which converts string with pluralize.
|
120
|
+
test_files:
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/pluralize_spec.rb
|