jekyll-uj-powertools 1.0.6 → 1.0.8
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 +4 -4
- data/README.md +7 -7
- data/lib/jekyll-uj-powertools/version.rb +1 -1
- data/lib/jekyll-uj-powertools.rb +21 -3
- data/spec/jekyll-uj-powertools_spec.rb +38 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da3ce92d92bcdf7f5ed7ec8063a02884b6aa3112bc4d5df11abf0c0ca401be10
|
4
|
+
data.tar.gz: e04d89bc278e37e8b5ae65c9ee8aeba0787376cb9c6a797daf666e498f52dd68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f85fe31a2ad07dbf2f40674810095f419f36f58055abb8866c784c6e91cbb24dd3a10b34cb0df614b31b442dac6c8289ac8dfebf8840faa773a88a9a19a70651
|
7
|
+
data.tar.gz: a699ccfc61bbfca668f897ec48cf89ff787abf928ec103d9cfbc48d514b47a8fa059157c0c4952e766215ac7e03b7fb46ef1764ceff89ab415fa67139c3b8387
|
data/README.md
CHANGED
@@ -26,8 +26,8 @@
|
|
26
26
|
|
27
27
|
## Features
|
28
28
|
* Powerful utility for Jekyll sites
|
29
|
-
* `
|
30
|
-
* `
|
29
|
+
* `uj_strip_ads` filter to remove ads from a string
|
30
|
+
* `uj_json_escape` filter to escape JSON characters
|
31
31
|
|
32
32
|
# Jekyll::uj-powertools
|
33
33
|
Meet `jekyll-uj-powertools`, the powerful set of utilities for Jekyll users.
|
@@ -46,20 +46,20 @@ gem install jekyll-uj-powertools
|
|
46
46
|
```
|
47
47
|
|
48
48
|
## Usage
|
49
|
-
Now you can use the `
|
49
|
+
Now you can use the `uj_strip_ads` and `uj_json_escape` filters in your Jekyll site:
|
50
50
|
|
51
|
-
### `
|
51
|
+
### `uj_strip_ads` Filter
|
52
52
|
Remove ads from a string, such as a blog post or article.
|
53
53
|
|
54
54
|
```liquid
|
55
|
-
{{ post.content |
|
55
|
+
{{ post.content | uj_strip_ads }}
|
56
56
|
```
|
57
57
|
|
58
|
-
### `
|
58
|
+
### `uj_json_escape` Filter
|
59
59
|
Escape JSON characters in a string making it safe to use in a JSON object.
|
60
60
|
|
61
61
|
```liquid
|
62
|
-
{{ post.content |
|
62
|
+
{{ post.content | uj_json_escape }}
|
63
63
|
```
|
64
64
|
|
65
65
|
These examples show how you can use the features of `jekyll-uj-powertools` in your Jekyll site.
|
data/lib/jekyll-uj-powertools.rb
CHANGED
@@ -2,14 +2,32 @@ require "jekyll"
|
|
2
2
|
|
3
3
|
module Jekyll
|
4
4
|
module UJPowertools
|
5
|
-
|
6
|
-
|
5
|
+
# Strip ads from the input
|
6
|
+
def uj_strip_ads(input)
|
7
7
|
input.gsub(/\s*<ad-unit>[\s\S]*?<\/ad-unit>\s*/m, '')
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
# Escape a string for use in JSON
|
11
|
+
def uj_json_escape(value)
|
11
12
|
value.gsub('\\', '\\\\').gsub('"', '\"')
|
12
13
|
end
|
14
|
+
|
15
|
+
# Increment a global counter that can be accessed from any page then return the new value
|
16
|
+
# def uj_increment_return(input)
|
17
|
+
# @context.registers[:uj_incremental_return] ||= 0
|
18
|
+
# @context.registers[:uj_incremental_return]
|
19
|
+
# @context.registers[:uj_incremental_return] += input
|
20
|
+
# end
|
21
|
+
def uj_increment_return(input)
|
22
|
+
@context ||= { registers: {} }
|
23
|
+
@context[:registers][:uj_incremental_return] ||= 0
|
24
|
+
@context[:registers][:uj_incremental_return] += input
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return a random number between 0 and the input
|
28
|
+
def uj_random(input)
|
29
|
+
rand(input)
|
30
|
+
end
|
13
31
|
end
|
14
32
|
end
|
15
33
|
|
@@ -8,30 +8,54 @@ RSpec.describe Jekyll::UJPowertools do
|
|
8
8
|
|
9
9
|
let(:dummy) { DummyClass.new }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# it 'returns the original string if no ads are present' do
|
17
|
-
# expect(dummy.strip_ads('No ads here')).to eq('No ads here')
|
18
|
-
# end
|
19
|
-
it 'removes ads from the string' do
|
20
|
-
expect(dummy.remove_ads('This is <!-- ADUNIT_TRIGGER_START -->and ad<!-- ADUNIT_TRIGGER_END -->')).to eq('This is ')
|
11
|
+
# Test Strip Ads method
|
12
|
+
describe '.uj_strip_ads' do
|
13
|
+
it 'removes ads from the string with custom HTML elements' do
|
14
|
+
expect(dummy.uj_strip_ads('This is <ad-unit>and ad</ad-unit>')).to eq('This is')
|
21
15
|
end
|
22
16
|
|
23
17
|
it 'returns the original string if no ads are present' do
|
24
|
-
expect(dummy.
|
18
|
+
expect(dummy.uj_strip_ads('No ads here')).to eq('No ads here')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'removes multiple ads from the string' do
|
22
|
+
expect(dummy.uj_strip_ads("First part\n<ad-unit>ad content</ad-unit>\nSecond part\n<ad-unit>more ad content</ad-unit>\nThird part")).to eq('First partSecond partThird part')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'removes surrounding whitespace' do
|
26
|
+
expect(dummy.uj_strip_ads("Start\n<ad-unit>\n ad content\n</ad-unit>\nEnd")).to eq("StartEnd")
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
|
30
|
+
# Test JSON Escape method
|
31
|
+
describe '.uj_json_escape' do
|
29
32
|
it 'escapes double quotes in JSON string' do
|
30
|
-
expect(dummy.
|
33
|
+
expect(dummy.uj_json_escape('this is a "quote"')).to eq('this is a \"quote\"')
|
31
34
|
end
|
32
35
|
|
33
36
|
it 'escapes backslashes in JSON string' do
|
34
|
-
expect(dummy.
|
37
|
+
expect(dummy.uj_json_escape('this is a nothing')).to eq('this is a nothing')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Test Increment Return method
|
42
|
+
describe '.uj_increment_return' do
|
43
|
+
it 'increments a global counter' do
|
44
|
+
expect(dummy.uj_increment_return(1)).to eq(1)
|
45
|
+
expect(dummy.uj_increment_return(1)).to eq(2)
|
46
|
+
expect(dummy.uj_increment_return(1)).to eq(3)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Test Random method
|
51
|
+
describe '.uj_random' do
|
52
|
+
it 'returns a random number between 0 and the input' do
|
53
|
+
srand(1)
|
54
|
+
expect(dummy.uj_random(10)).to eq(5)
|
55
|
+
srand(2)
|
56
|
+
expect(dummy.uj_random(10)).to eq(8)
|
57
|
+
srand(3)
|
58
|
+
expect(dummy.uj_random(10)).to eq(8)
|
35
59
|
end
|
36
60
|
end
|
37
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-uj-powertools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITW Creative Works
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|