phlex 1.6.0 → 1.6.1
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/lib/phlex/element_clobbering_guard.rb +3 -3
- data/lib/phlex/elements.rb +23 -22
- data/lib/phlex/sgml.rb +28 -12
- data/lib/phlex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada5b83ea9c2fbd305a249ffa81a43c9e9da26a7c87860dac62e594a43341001
|
4
|
+
data.tar.gz: e728f6c83cae97671bf4092f7bd384c93611d51158f613a75518d1109a669942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8b512d89247318f657482d3eeb1ba9fd0c1de73edcf4f3c5d0b6ff843bbd0bbca6d47d9a957780a1831e70b67ec8c2d1d1beba10a00bc9546a8966f67d545d
|
7
|
+
data.tar.gz: a5a780a277bc36e8fa028af0ccdd3b985189ae6c49241d737b9d86e4f37fa43bbbfc8e4cb1736914735a35821a741c8fcc964f45c8b82b96c5389053c72b2684
|
@@ -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
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|