jekyll-uj-powertools 1.5.2 → 1.6.1

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.
@@ -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)