jekyll-uj-powertools 1.0.7 → 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: 9db7ef2a5b59ca20237faf78d7b55ad7efa383dd792420383fe5dac7b6f043e4
4
- data.tar.gz: 66d40c4551b9a0f65b9a95bdf6a193e3383c9ae8c128db0f2a04f41cf659e966
3
+ metadata.gz: da3ce92d92bcdf7f5ed7ec8063a02884b6aa3112bc4d5df11abf0c0ca401be10
4
+ data.tar.gz: e04d89bc278e37e8b5ae65c9ee8aeba0787376cb9c6a797daf666e498f52dd68
5
5
  SHA512:
6
- metadata.gz: 138078fa39a755f3cc5aae6360106dea7ecbe09f202469d7b805ccc0115944f2d953783252695d5593df8a3f528f47a26d4dbc6c3b52c4854b7e5e50be813dd1
7
- data.tar.gz: 71a73c6f9d3281e3d8dfecf458e31f34935e1b337fa3e23c91865f2d4658e5c4a27cd54ff0b86ea7c756f16ec37db0a7e790d06c358b05736ba1bd8eef0dc9e9
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.7"
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,31 +8,54 @@ RSpec.describe Jekyll::UJPowertools do
8
8
 
9
9
  let(:dummy) { DummyClass.new }
10
10
 
11
- describe '.strip_ads' do
11
+ # Test Strip Ads method
12
+ describe '.uj_strip_ads' do
12
13
  it 'removes ads from the string with custom HTML elements' do
13
- expect(dummy.strip_ads('This is <ad-unit>and ad</ad-unit>')).to eq('This is ')
14
+ expect(dummy.uj_strip_ads('This is <ad-unit>and ad</ad-unit>')).to eq('This is')
14
15
  end
15
16
 
16
17
  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
+ expect(dummy.uj_strip_ads('No ads here')).to eq('No ads here')
18
19
  end
19
20
 
20
21
  it 'removes multiple ads from the string' do
21
- expect(dummy.strip_ads('First part<ad-unit>ad content</ad-unit>Second part<ad-unit>more ad content</ad-unit>Third part')).to eq('First partSecond partThird part')
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')
22
23
  end
23
24
 
24
25
  it 'removes surrounding whitespace' do
25
- expect(dummy.strip_ads("Start\n<ad-unit>\n ad content\n</ad-unit>\nEnd")).to eq("Start\nEnd")
26
+ expect(dummy.uj_strip_ads("Start\n<ad-unit>\n ad content\n</ad-unit>\nEnd")).to eq("StartEnd")
26
27
  end
27
28
  end
28
29
 
29
- describe '.json_escape' do
30
+ # Test JSON Escape method
31
+ describe '.uj_json_escape' do
30
32
  it 'escapes double quotes in JSON string' do
31
- 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\"')
32
34
  end
33
35
 
34
36
  it 'escapes backslashes in JSON string' do
35
- 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)
36
59
  end
37
60
  end
38
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.7
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