phlex 1.6.0 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of phlex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/phlex/element_clobbering_guard.rb +3 -3
- data/lib/phlex/elements.rb +23 -22
- data/lib/phlex/sgml.rb +32 -21
- data/lib/phlex/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85f8d8d06e49280c1fd480bf596fd6f13e76d9872fe363349e9e481d8c32fe44
|
4
|
+
data.tar.gz: 55b77a7f744a657406a84f98cc049d38b3a4631dd60d29b45a0d33022efb7695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1628997a70876299299b3825bfb9da74be95703d7402898f57e550945eb1b35da61382237914729ab1f90faeca671d377b10c28ae3c22589afb8f23b5a4d0f4
|
7
|
+
data.tar.gz: 0e62cb5507038341d2f4ef8104fbf6cc79723032cb5b88510c5d44376ba4668b44571a047819b0f03b900abdd6d0c8f8585c369d0f1923db9482962e95d91393
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
@@ -3,11 +3,11 @@
|
|
3
3
|
module Phlex
|
4
4
|
module ElementClobberingGuard
|
5
5
|
def method_added(method_name)
|
6
|
-
if method_name[0] == "_" &&
|
6
|
+
if method_name[0] == "_" && element_method?(method_name[1..].to_sym)
|
7
7
|
raise NameError, "👋 Redefining the method `#{name}##{method_name}` is not a good idea."
|
8
|
+
else
|
9
|
+
super
|
8
10
|
end
|
9
|
-
|
10
|
-
super
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/phlex/elements.rb
CHANGED
@@ -5,45 +5,44 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module Phlex::Elements
|
8
|
-
|
9
|
-
|
10
|
-
.lazy
|
11
|
-
.map(&:to_s)
|
12
|
-
.select { |m| m.start_with?("__phlex_") }
|
13
|
-
.map { |m| m[8...-2].to_sym }
|
8
|
+
def registered_elements
|
9
|
+
@registered_elements ||= Concurrent::Map.new
|
14
10
|
end
|
15
11
|
|
16
12
|
def register_element(element, tag: element.name.tr("_", "-"))
|
17
13
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
18
14
|
# frozen_string_literal: true
|
19
15
|
|
20
|
-
|
16
|
+
|
17
|
+
def #{element}(**attributes, &block)
|
18
|
+
target = @_context.target
|
19
|
+
|
21
20
|
if attributes.length > 0 # with attributes
|
22
21
|
if block_given? # with content block
|
23
|
-
|
22
|
+
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
|
24
23
|
yield_content(&block)
|
25
|
-
|
24
|
+
target << "</#{tag}>"
|
26
25
|
else # without content block
|
27
|
-
|
26
|
+
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << "></#{tag}>"
|
28
27
|
end
|
29
28
|
else # without attributes
|
30
29
|
if block_given? # with content block
|
31
|
-
|
30
|
+
target << "<#{tag}>"
|
32
31
|
yield_content(&block)
|
33
|
-
|
32
|
+
target << "</#{tag}>"
|
34
33
|
else # without content block
|
35
|
-
|
34
|
+
target << "<#{tag}></#{tag}>"
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
nil
|
40
39
|
end
|
41
40
|
|
42
|
-
alias_method :_#{element},
|
43
|
-
alias_method :#{element}, :__phlex_#{element}__
|
44
|
-
private :__phlex_#{element}__
|
41
|
+
alias_method :_#{element}, :#{element}
|
45
42
|
RUBY
|
46
43
|
|
44
|
+
registered_elements[element] = tag
|
45
|
+
|
47
46
|
element
|
48
47
|
end
|
49
48
|
|
@@ -51,21 +50,23 @@ module Phlex::Elements
|
|
51
50
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
52
51
|
# frozen_string_literal: true
|
53
52
|
|
54
|
-
def
|
53
|
+
def #{element}(**attributes)
|
54
|
+
target = @_context.target
|
55
|
+
|
55
56
|
if attributes.length > 0 # with attributes
|
56
|
-
|
57
|
+
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
|
57
58
|
else # without attributes
|
58
|
-
|
59
|
+
target << "<#{tag}>"
|
59
60
|
end
|
60
61
|
|
61
62
|
nil
|
62
63
|
end
|
63
64
|
|
64
|
-
alias_method :_#{element},
|
65
|
-
alias_method :#{element}, :__phlex_#{element}__
|
66
|
-
private :__phlex_#{element}__
|
65
|
+
alias_method :_#{element}, :#{element}
|
67
66
|
RUBY
|
68
67
|
|
68
|
+
registered_elements[element] = tag
|
69
|
+
|
69
70
|
element
|
70
71
|
end
|
71
72
|
end
|
data/lib/phlex/sgml.rb
CHANGED
@@ -12,8 +12,6 @@ module Phlex
|
|
12
12
|
new(...).call
|
13
13
|
end
|
14
14
|
|
15
|
-
alias_method :render, :call
|
16
|
-
|
17
15
|
# Create a new instance of the component.
|
18
16
|
# @note The block will not be delegated to the initializer. Instead, it will be provided to `template` when rendering.
|
19
17
|
def new(*args, **kwargs, &block)
|
@@ -31,6 +29,17 @@ module Phlex
|
|
31
29
|
alias_method :__attributes__, :__final_attributes__
|
32
30
|
alias_method :call, :__final_call__
|
33
31
|
end
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
def element_method?(method_name)
|
35
|
+
return false unless instance_methods.include?(method_name)
|
36
|
+
|
37
|
+
owner = instance_method(method_name).owner
|
38
|
+
|
39
|
+
return true if owner.is_a?(Phlex::Elements) && owner.registered_elements[method_name]
|
40
|
+
|
41
|
+
false
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
# Renders the view and returns the buffer. The default buffer is a mutable String.
|
@@ -52,7 +61,7 @@ module Phlex
|
|
52
61
|
|
53
62
|
around_template do
|
54
63
|
if block
|
55
|
-
if DeferredRender
|
64
|
+
if is_a?(DeferredRender)
|
56
65
|
__vanish__(self, &block)
|
57
66
|
template
|
58
67
|
else
|
@@ -118,11 +127,13 @@ module Phlex
|
|
118
127
|
# Output a whitespace character. This is useful for getting inline elements to wrap. If you pass a block, a whitespace will be output before and after yielding the block.
|
119
128
|
# @return [nil]
|
120
129
|
def whitespace
|
121
|
-
@_context.target
|
130
|
+
target = @_context.target
|
131
|
+
|
132
|
+
target << " "
|
122
133
|
|
123
134
|
if block_given?
|
124
135
|
yield
|
125
|
-
|
136
|
+
target << " "
|
126
137
|
end
|
127
138
|
|
128
139
|
nil
|
@@ -131,9 +142,11 @@ module Phlex
|
|
131
142
|
# Output an HTML comment.
|
132
143
|
# @return [nil]
|
133
144
|
def comment(&block)
|
134
|
-
@_context.target
|
145
|
+
target = @_context.target
|
146
|
+
|
147
|
+
target << "<!-- "
|
135
148
|
yield_content(&block)
|
136
|
-
|
149
|
+
target << " -->"
|
137
150
|
|
138
151
|
nil
|
139
152
|
end
|
@@ -210,10 +223,11 @@ module Phlex
|
|
210
223
|
private def yield_content
|
211
224
|
return unless block_given?
|
212
225
|
|
213
|
-
|
214
|
-
content = yield(self)
|
226
|
+
target = @_context.target
|
215
227
|
|
216
|
-
|
228
|
+
original_length = target.length
|
229
|
+
content = yield(self)
|
230
|
+
plain(content) if original_length == target.length
|
217
231
|
|
218
232
|
nil
|
219
233
|
end
|
@@ -223,9 +237,11 @@ module Phlex
|
|
223
237
|
private def yield_content_with_args(*args)
|
224
238
|
return unless block_given?
|
225
239
|
|
226
|
-
|
240
|
+
target = @_context.target
|
241
|
+
|
242
|
+
original_length = target.length
|
227
243
|
content = yield(*args)
|
228
|
-
plain(content) if original_length ==
|
244
|
+
plain(content) if original_length == target.length
|
229
245
|
|
230
246
|
nil
|
231
247
|
end
|
@@ -243,14 +259,6 @@ module Phlex
|
|
243
259
|
attributes = process_attributes(**attributes)
|
244
260
|
end
|
245
261
|
|
246
|
-
if attributes[:href]&.start_with?(/\s*javascript:/)
|
247
|
-
attributes.delete(:href)
|
248
|
-
end
|
249
|
-
|
250
|
-
if attributes["href"]&.start_with?(/\s*javascript:/)
|
251
|
-
attributes.delete("href")
|
252
|
-
end
|
253
|
-
|
254
262
|
buffer = +""
|
255
263
|
__build_attributes__(attributes, buffer: buffer)
|
256
264
|
|
@@ -268,8 +276,11 @@ module Phlex
|
|
268
276
|
else k.to_s
|
269
277
|
end
|
270
278
|
|
279
|
+
lower_name = name.downcase
|
280
|
+
next if lower_name == "href" && v.start_with?(/\s*javascript:/i)
|
281
|
+
|
271
282
|
# Detect unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters.
|
272
|
-
if HTML::EVENT_ATTRIBUTES[
|
283
|
+
if HTML::EVENT_ATTRIBUTES[lower_name] || name.match?(/[<>&"']/)
|
273
284
|
raise ArgumentError, "Unsafe attribute name detected: #{k}."
|
274
285
|
end
|
275
286
|
|
data/lib/phlex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.5.6
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: A framework for building views in Ruby.
|