jekyll-uj-powertools 1.5.2 → 1.6.0

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: 4c546d3b5f77c67bf33fdcdbecfeb0c741760a89fdcf508f05caf7943b19b197
4
- data.tar.gz: 2612f6dae15afb265e3193bccdaf038421eb1ad51e3bdd955c0ce610b324e441
3
+ metadata.gz: bee69fe37cc10927e8f51898ed41337c5f71a2a013f1270f3ff0dea6b9318a42
4
+ data.tar.gz: 6a07ff1145e4d2fc93dd2f269ce38ed51d42606206d435afb9a47c909b8575ff
5
5
  SHA512:
6
- metadata.gz: e95b14dd432df58e934bb9cab3c77eb8bb577cc6e917475692753ec95b9d78ed8759e4310c6560fa6bb5da350519eb3e3fe97fc3278c78c2b345e021a53fc256
7
- data.tar.gz: 54646abcd5832dabb835cdfff9dfb71d80aebe28df1727381497beb7af057ef594a05231cc9327ddf87f74484c1c6035d440a394b5fd97568943e641999f9af8
6
+ metadata.gz: 7b87aa8225fd7cbebb64c20a21711e04f1faefd7221ddfc351a322424f46fb26c3b9459ce1b62938c430842c27b8b4aebf910c49517c846ceacab01fc6664c19
7
+ data.tar.gz: 7b8e91ed9fb513e952163f53519f4eaf065a516832422dbc11ad9f5c39c0e0d535c4bfba312f36d9272f0ff11bb234475121dee9ad5367b04c98fc76e458c887
data/README.md CHANGED
@@ -78,7 +78,7 @@ Use the `site.uj.cache_breaker` variable to append a cache-busting query paramet
78
78
  <link rel="stylesheet" href="{{ "/assets/css/style.css" | prepend: site.baseurl }}?v={{ site.uj.cache_breaker }}">
79
79
  ```
80
80
 
81
- ### Page Variables
81
+ ## Page Variables
82
82
  ### `page.random_id` Variable
83
83
  Generate a random ID for each page, useful for sorting randomly or for unique identifiers.
84
84
 
@@ -126,6 +126,24 @@ Resolves the site, layout, and page data into a single object, which can be usef
126
126
  {{ page.my.variable | default: layout.my.variable | default: site.my.variable }}
127
127
  ```
128
128
 
129
+ ## Tags
130
+ ### `iftruthy` Tag
131
+ A custom Liquid tag that checks if a variable is truthy (not nil, not false, not empty string, not 0) and renders the content inside the tag if it is truthy.
132
+ ```liquid
133
+ {% iftruthy my_variable %}
134
+ <p>This content will only be rendered if my_variable is truthy.</p>
135
+ {% endiftruthy %}
136
+ ```
137
+
138
+ ### `iffalsy` Tag
139
+ A custom Liquid tag that checks if a variable is falsy (nil, false, empty string, or 0) and renders the content inside the tag if it is falsy.
140
+ ```liquid
141
+ {% iffalsy my_variable %}
142
+ <p>This content will only be rendered if my_variable is falsy.</p>
143
+ {% endifalsy %}
144
+ ```
145
+
146
+ ## Final notes
129
147
  These examples show how you can use the features of `jekyll-uj-powertools` in your Jekyll site.
130
148
 
131
149
  ## 🔧 Development
@@ -133,9 +151,6 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
133
151
 
134
152
  To install this gem onto your local machine, run `bundle exec rake install`.
135
153
 
136
-
137
-
138
-
139
154
  ## ⚠️ Testing
140
155
  Run the tests
141
156
  ```shell
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  Gem::Specification.new do |spec|
6
6
  # Gem info
7
7
  spec.name = "jekyll-uj-powertools"
8
- spec.version = "1.5.2"
8
+ spec.version = "1.6.0"
9
9
 
10
10
  # Author info
11
11
  spec.authors = ["ITW Creative Works"]
data/lib/filters/main.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Libraries
2
2
  require "jekyll"
3
3
 
4
- # Module
4
+ # Filters
5
5
  module Jekyll
6
6
  module UJPowertools
7
7
  # Initialize a timestamp that will remain consistent across calls
@@ -1,7 +1,7 @@
1
1
  # Libraries
2
2
  # ...
3
3
 
4
- # Module
4
+ # Generator
5
5
  module Jekyll
6
6
  class InjectData < Generator
7
7
  safe true
@@ -75,16 +75,16 @@ module Jekyll
75
75
  def get_layout_chain(layout_name, site)
76
76
  chain = []
77
77
  current_layout_name = layout_name
78
-
78
+
79
79
  # Traverse up the layout hierarchy
80
80
  while current_layout_name
81
81
  layout = site.layouts[current_layout_name]
82
82
  break unless layout
83
-
83
+
84
84
  chain.unshift(layout) # Add to beginning to maintain parent->child order
85
85
  current_layout_name = layout.data['layout']
86
86
  end
87
-
87
+
88
88
  chain
89
89
  end
90
90
 
@@ -95,13 +95,13 @@ module Jekyll
95
95
  'path', 'relative_path', 'collection', 'type', 'id', 'url',
96
96
  'next', 'previous', 'draft', 'ext', 'excerpt', 'output'
97
97
  ]
98
-
98
+
99
99
  filtered = {}
100
100
  data.each do |key, value|
101
101
  next if jekyll_internals.include?(key)
102
102
  filtered[key] = value
103
103
  end
104
-
104
+
105
105
  filtered
106
106
  end
107
107
 
@@ -12,5 +12,6 @@ module Jekyll
12
12
  require_relative "hooks/inject-properties"
13
13
 
14
14
  # Load Tags
15
- # require_relative "tags/ifistruthy"
15
+ require_relative "tags/iftruthy"
16
+ require_relative "tags/iffalsy"
16
17
  end
@@ -0,0 +1,38 @@
1
+ # Libraries
2
+ # ...
3
+
4
+ # Tag
5
+ module Jekyll
6
+ module UJPowertools
7
+ class IfFalsyTag < Liquid::Block
8
+ def initialize(tag_name, markup, tokens)
9
+ super
10
+ @variable = markup.strip
11
+ end
12
+
13
+ def render(context)
14
+ # Use Liquid's variable lookup to handle nested properties
15
+ value = context.scopes.last[@variable] || context[@variable]
16
+
17
+ # For nested properties like page.my.variable
18
+ if @variable.include?('.')
19
+ parts = @variable.split('.')
20
+ value = context[parts.first]
21
+ parts[1..-1].each do |part|
22
+ value = value.is_a?(Hash) ? value[part] : nil
23
+ break if value.nil?
24
+ end
25
+ end
26
+
27
+ # Check if the value is falsy (nil, false, empty string, or 0)
28
+ if value.nil? || value == false || value == "" || value == 0
29
+ super
30
+ else
31
+ ""
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ Liquid::Template.register_tag('iffalsy', Jekyll::UJPowertools::IfFalsyTag)
@@ -0,0 +1,38 @@
1
+ # Libraries
2
+ # ...
3
+
4
+ # Tag
5
+ module Jekyll
6
+ module UJPowertools
7
+ class IfTruthyTag < Liquid::Block
8
+ def initialize(tag_name, markup, tokens)
9
+ super
10
+ @variable = markup.strip
11
+ end
12
+
13
+ def render(context)
14
+ # Use Liquid's variable lookup to handle nested properties
15
+ value = context.scopes.last[@variable] || context[@variable]
16
+
17
+ # For nested properties like page.my.variable
18
+ if @variable.include?('.')
19
+ parts = @variable.split('.')
20
+ value = context[parts.first]
21
+ parts[1..-1].each do |part|
22
+ value = value.is_a?(Hash) ? value[part] : nil
23
+ break if value.nil?
24
+ end
25
+ end
26
+
27
+ # Check if the value is truthy (not nil, not false, not empty string, not 0)
28
+ if value && value != false && value != "" && value != 0
29
+ super
30
+ else
31
+ ""
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ Liquid::Template.register_tag('iftruthy', Jekyll::UJPowertools::IfTruthyTag)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-uj-powertools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITW Creative Works
@@ -103,7 +103,8 @@ files:
103
103
  - lib/generators/inject-properties.rb
104
104
  - lib/hooks/inject-properties.rb
105
105
  - lib/jekyll-uj-powertools.rb
106
- - lib/tags/ifistruthy.rb
106
+ - lib/tags/iffalsy.rb
107
+ - lib/tags/iftruthy.rb
107
108
  homepage: https://github.com/itw-creative-works/jekyll-uj-powertools
108
109
  licenses:
109
110
  - MIT
@@ -1,161 +0,0 @@
1
- module Jekyll
2
- module UJPowertools
3
- class IfIsTruthyTag < Liquid::Block
4
- Syntax = /(\w+)/
5
-
6
- def initialize(tag_name, markup, tokens)
7
- super
8
-
9
- if markup =~ Syntax
10
- @variable_name = $1
11
- else
12
- raise SyntaxError, "Invalid syntax for ifistruthy tag. Usage: {% ifistruthy variable_name %}"
13
- end
14
- end
15
-
16
- def render(context)
17
- variable = context[@variable_name]
18
- is_truthy = check_truthy(variable)
19
-
20
- # Split content at else tag
21
- else_index = nil
22
- @nodelist.each_with_index do |node, index|
23
- if node.respond_to?(:tag_name) && node.tag_name == 'else'
24
- else_index = index
25
- break
26
- end
27
- end
28
-
29
- if is_truthy
30
- if else_index
31
- render_nodelist(@nodelist[0...else_index], context)
32
- else
33
- super(context)
34
- end
35
- else
36
- if else_index
37
- render_nodelist(@nodelist[(else_index + 1)..-1], context)
38
- else
39
- ''
40
- end
41
- end
42
- end
43
-
44
- def unknown_tag(tag_name, markup, tokens)
45
- if tag_name == 'else'
46
- @nodelist << Liquid::ElseTag.new(tag_name, markup, tokens)
47
- else
48
- super
49
- end
50
- end
51
-
52
- private
53
-
54
- def check_truthy(value)
55
- return false if value.nil?
56
- return false if value.respond_to?(:empty?) && value.empty?
57
- return false if value.to_s.downcase == 'null'
58
- return false if value == false
59
- true
60
- end
61
-
62
- def render_nodelist(nodelist, context)
63
- output = []
64
- nodelist.each do |token|
65
- case token
66
- when String
67
- output << token
68
- else
69
- if token.respond_to?(:render)
70
- output << token.render(context)
71
- else
72
- output << token.to_s
73
- end
74
- end
75
- end
76
- output.join
77
- end
78
- end
79
-
80
- class UnlessIsTruthyTag < Liquid::Block
81
- Syntax = /(\w+)/
82
-
83
- def initialize(tag_name, markup, tokens)
84
- super
85
-
86
- if markup =~ Syntax
87
- @variable_name = $1
88
- else
89
- raise SyntaxError, "Invalid syntax for unlessistruthy tag. Usage: {% unlessistruthy variable_name %}"
90
- end
91
- end
92
-
93
- def render(context)
94
- variable = context[@variable_name]
95
- is_truthy = check_truthy(variable)
96
-
97
- # Split content at else tag
98
- else_index = nil
99
- @nodelist.each_with_index do |node, index|
100
- if node.respond_to?(:tag_name) && node.tag_name == 'else'
101
- else_index = index
102
- break
103
- end
104
- end
105
-
106
- if !is_truthy
107
- if else_index
108
- render_nodelist(@nodelist[0...else_index], context)
109
- else
110
- super(context)
111
- end
112
- else
113
- if else_index
114
- render_nodelist(@nodelist[(else_index + 1)..-1], context)
115
- else
116
- ''
117
- end
118
- end
119
- end
120
-
121
- def unknown_tag(tag_name, markup, tokens)
122
- if tag_name == 'else'
123
- @nodelist << Liquid::ElseTag.new(tag_name, markup, tokens)
124
- else
125
- super
126
- end
127
- end
128
-
129
- private
130
-
131
- def check_truthy(value)
132
- return false if value.nil?
133
- return false if value.respond_to?(:empty?) && value.empty?
134
- return false if value.to_s.downcase == 'null'
135
- return false if value == false
136
- true
137
- end
138
-
139
- def render_nodelist(nodelist, context)
140
- output = []
141
- nodelist.each do |token|
142
- case token
143
- when String
144
- output << token
145
- else
146
- if token.respond_to?(:render)
147
- output << token.render(context)
148
- else
149
- output << token.to_s
150
- end
151
- end
152
- end
153
- output.join
154
- end
155
- end
156
- end
157
- end
158
-
159
- # Register the tags
160
- Liquid::Template.register_tag('ifistruthy', Jekyll::UJPowertools::IfIsTruthyTag)
161
- Liquid::Template.register_tag('unlessistruthy', Jekyll::UJPowertools::UnlessIsTruthyTag)