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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63f84288c3d38825104a042c4d8e31943900a2a7fc3646d6da3455141cafef7c
4
- data.tar.gz: b2ee94e280628d5163086a6bd99015f1baa3c0d55e2505e9b273cbff92e13f6e
3
+ metadata.gz: da3ce92d92bcdf7f5ed7ec8063a02884b6aa3112bc4d5df11abf0c0ca401be10
4
+ data.tar.gz: e04d89bc278e37e8b5ae65c9ee8aeba0787376cb9c6a797daf666e498f52dd68
5
5
  SHA512:
6
- metadata.gz: d42ee74a754c5b6e9c629e6acbe1618d968acee11b9422e87099aa9ca3f410be6e05c0f337c80ebebe1dece4613b97587a7b43475ff088c61b30cd8902c73117
7
- data.tar.gz: 917c9d9d5689103a1086addbf171ac9881c5047c2791ddf842474d111155a6daaa88aadc940a46a557dfeea75dff28299b79932f4cecaf203e524ba13c6170a7
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
- * `strip_ads` filter to remove ads from a string
30
- * `json_escape` filter to escape JSON characters
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 `strip_ads` and `json_escape` filters in your Jekyll site:
49
+ Now you can use the `uj_strip_ads` and `uj_json_escape` filters in your Jekyll site:
50
50
 
51
- ### `strip_ads` Filter
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 | strip_ads }}
55
+ {{ post.content | uj_strip_ads }}
56
56
  ```
57
57
 
58
- ### `json_escape` Filter
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 | json_escape }}
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.
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module UJPowertools
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.8"
4
4
  end
5
5
  end
@@ -2,14 +2,32 @@ require "jekyll"
2
2
 
3
3
  module Jekyll
4
4
  module UJPowertools
5
- def strip_ads(input)
6
- # input.gsub(/<ad-unit>[\s\S]*?<\/ad-unit>/m, '')
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
- def json_escape(value)
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
- describe '.strip_ads' do
12
- # it 'removes ads from the string' do
13
- # expect(dummy.strip_ads('{% include /master/modules/adunits/adsense-in-article.html index="0" %} This is content')).to eq(' This is content')
14
- # end
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.remove_ads('No ads here')).to eq('No ads here')
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
- describe '.json_escape' do
30
+ # Test JSON Escape method
31
+ describe '.uj_json_escape' do
29
32
  it 'escapes double quotes in JSON string' do
30
- expect(dummy.json_escape('this is a "quote"')).to eq('this is a \"quote\"')
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.json_escape('this is a nothing')).to eq('this is a nothing')
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.6
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-25 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll