jekyll-uj-powertools 1.0.7 → 1.0.9

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: 69b1080a5753842ce99a31f4672dcfdb49ba3b1854a73f21a57a3a9e80b64e5d
4
+ data.tar.gz: 3b346f6127275711633ebf4249bf7943856d564c1e624bb4b272f8e584b23ce6
5
5
  SHA512:
6
- metadata.gz: 138078fa39a755f3cc5aae6360106dea7ecbe09f202469d7b805ccc0115944f2d953783252695d5593df8a3f528f47a26d4dbc6c3b52c4854b7e5e50be813dd1
7
- data.tar.gz: 71a73c6f9d3281e3d8dfecf458e31f34935e1b337fa3e23c91865f2d4658e5c4a27cd54ff0b86ea7c756f16ec37db0a7e790d06c358b05736ba1bd8eef0dc9e9
6
+ metadata.gz: 5546fdd6f425b90bfb78984488a4a1251eb92aa24b7566ded1827fb5e6a11e7377220dfdc4440852274a4afcf863d53aa1e3659bb1a96fcfdb37475dc931aed7
7
+ data.tar.gz: 6089023c4c5d8c57feb8f11e45c0588ab80816e7dd2a9d6b578ac1d480a625277537fddcca545513c6023db91b2e87a345d063166635e77e76b346c961c2729b
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.9"
4
4
  end
5
5
  end
@@ -2,13 +2,41 @@ 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)
11
- value.gsub('\\', '\\\\').gsub('"', '\"')
10
+ # Escape a string for use in JSON
11
+ # def uj_json_escape(value)
12
+ # value
13
+ # .gsub('\\', '\\\\') # Escape backslashes
14
+ # .gsub('"', '\"') # Escape double quotes
15
+ # .gsub("\b", '\\b') # Escape backspace
16
+ # .gsub("\f", '\\f') # Escape formfeed
17
+ # .gsub("\n", '\\n') # Escape newline
18
+ # .gsub("\r", '\\r') # Escape carriage return
19
+ # .gsub("\t", '\\t') # Escape tab
20
+ # end
21
+ def uj_json_escape(value)
22
+ value.to_json[1..-2] # Convert to JSON and remove the surrounding quotes
23
+ end
24
+
25
+ # Increment a global counter that can be accessed from any page then return the new value
26
+ # def uj_increment_return(input)
27
+ # @context.registers[:uj_incremental_return] ||= 0
28
+ # @context.registers[:uj_incremental_return]
29
+ # @context.registers[:uj_incremental_return] += input
30
+ # end
31
+ def uj_increment_return(input)
32
+ @context ||= { registers: {} }
33
+ @context[:registers][:uj_incremental_return] ||= 0
34
+ @context[:registers][:uj_incremental_return] += input
35
+ end
36
+
37
+ # Return a random number between 0 and the input
38
+ def uj_random(input)
39
+ rand(input)
12
40
  end
13
41
  end
14
42
  end
@@ -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.9
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-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll