phlex 1.3.2 → 1.5.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/.rubocop.yml +2 -24
- data/Gemfile +0 -2
- data/README.md +12 -0
- data/fixtures/view_helper.rb +6 -0
- data/lib/phlex/black_hole.rb +15 -9
- data/lib/phlex/callable.rb +3 -5
- data/lib/phlex/deferred_render.rb +2 -4
- data/lib/phlex/element_clobbering_guard.rb +13 -0
- data/lib/phlex/elements.rb +64 -54
- data/lib/phlex/helpers.rb +9 -2
- data/lib/phlex/html/standard_elements.rb +0 -14
- data/lib/phlex/html.rb +19 -297
- data/lib/{overrides → phlex/overrides}/symbol/name.rb +1 -1
- data/lib/phlex/sgml.rb +313 -0
- data/lib/phlex/svg/standard_elements.rb +389 -0
- data/lib/phlex/svg.rb +14 -0
- data/lib/phlex/testing/view_helper.rb +10 -12
- data/lib/phlex/unbuffered.rb +34 -36
- data/lib/phlex/version.rb +1 -1
- data/lib/phlex.rb +5 -1
- metadata +21 -4
- data/lib/phlex/buffered.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 647e5f1a1f3beb8dd596cb87a5fb848f07e8e87e28ce705f3d1c93d8c9cfe9ac
|
4
|
+
data.tar.gz: d2b327f45d36a44069cf6dd9de03310918f56647bc1a40c6eb675837eb1cb653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0387ae5e9183fb312619950e5a5a6d75d1383c58e46be6f389e781a5cbdf2b3658efc4cbd298eb7b9d1ad0f9042c857ecc11c3812a2bd1600ee04a79f9fc1d8a'
|
7
|
+
data.tar.gz: 6159fbe6ac1f52baf8924e9309a43ae252a47655f7feaf380787fb4d5a56e83380154dd906e8a964b0754fa0f4827e3e3b028ca9f4a03ded5aace8431edf0452
|
data/.rubocop.yml
CHANGED
@@ -5,27 +5,5 @@ inherit_from:
|
|
5
5
|
AllCops:
|
6
6
|
TargetRubyVersion: 2.7
|
7
7
|
|
8
|
-
Style/
|
9
|
-
Enabled: false
|
10
|
-
|
11
|
-
Layout/CaseIndentation:
|
12
|
-
Enabled: false
|
13
|
-
|
14
|
-
Style/StringConcatenation:
|
15
|
-
Enabled: false
|
16
|
-
|
17
|
-
Style/CaseEquality:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Security/Eval:
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
Style/MethodCallWithoutArgsParentheses:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
Style/MixinUsage:
|
27
|
-
Enabled: false
|
28
|
-
|
29
|
-
Style/AccessModifierDeclarations:
|
30
|
-
Enabled: true
|
31
|
-
EnforcedStyle: inline
|
8
|
+
Style/ExplicitBlockArgument:
|
9
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,17 @@ Documentation can be found at [www.phlex.fun](https://www.phlex.fun).
|
|
10
10
|
|
11
11
|
If you run into any trouble, please [start a discussion](https://github.com/joeldrapper/phlex/discussions/new), or [open an issue](https://github.com/joeldrapper/phlex/issues/new) if you think you’ve found a bug.
|
12
12
|
|
13
|
+
### Ecosystem 🌱
|
14
|
+
- [joeldrapper/phlex-rails](https://github.com/joeldrapper/phlex-rails) — Ruby on Rails integration
|
15
|
+
- [joeldrapper/phlex.fun](https://github.com/joeldrapper/phlex.fun) — Docs Website
|
16
|
+
- [joeldrapper/phlex-markdown](https://github.com/joeldrapper/phlex-markdown) — Markdown to HTML using Phlex
|
17
|
+
- [joeldrapper/phlex-compiler](https://github.com/joeldrapper/phlex-compiler) — A compiler for Phlex
|
18
|
+
- [joeldrapper/phlex-translation](https://github.com/joeldrapper/phlex-translation) — I18n Support for Phlex
|
19
|
+
- [joeldrapper/phlex-testing-nokogiri](https://github.com/joeldrapper/phlex-testing-nokogiri) — Nokogiri support
|
20
|
+
- [joeldrapper/phlex-testing-capybara](https://github.com/joeldrapper/phlex-testing-capybara) — Capybara support
|
21
|
+
- [marcoroth/phlexing](https://github.com/marcoroth/phlexing) — ERB → Phlex converter
|
22
|
+
- [ViewComponent/lookbook](https://github.com/ViewComponent/lookbook) — Document and preview Phlex components in Rails (v2 beta only)
|
23
|
+
|
13
24
|
### Community 🙌
|
14
25
|
|
15
26
|
Everyone interacting in Phlex codebases, issue trackers or chat rooms is expected to follow the [code of conduct](https://github.com/joeldrapper/phlex/blob/main/CODE_OF_CONDUCT.md).
|
@@ -43,3 +54,4 @@ Thanks [Logology](https://www.logology.co) for sponsoring our logo.
|
|
43
54
|
- [hoshi](https://github.com/pete/hoshi)
|
44
55
|
- [hyperstack](https://github.com/hyperstack-org/hyperstack)
|
45
56
|
- [clearwater](https://github.com/clearwater-rb/clearwater)
|
57
|
+
- [paggio](https://github.com/opal/paggio)
|
data/fixtures/view_helper.rb
CHANGED
data/lib/phlex/black_hole.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Phlex
|
4
|
-
|
5
|
-
extend self
|
3
|
+
module Phlex::BlackHole
|
4
|
+
extend self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def <<(anything)
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def length
|
11
|
+
0
|
12
|
+
end
|
13
|
+
|
14
|
+
def dup
|
15
|
+
self
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
18
|
+
def clear
|
19
|
+
self
|
14
20
|
end
|
15
21
|
end
|
data/lib/phlex/callable.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Phlex
|
4
|
-
module
|
5
|
-
# This module doesn't do anything. Phlex::HTML#call checks for its inclusion in the ancestry instead.
|
6
|
-
end
|
3
|
+
module Phlex::DeferredRender
|
4
|
+
# This module doesn't do anything. Phlex::HTML#call checks for its inclusion in the ancestry instead.
|
7
5
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module ElementClobberingGuard
|
5
|
+
def method_added(method_name)
|
6
|
+
if method_name[0] == "_" && private_instance_methods.include?(:"__phlex#{method_name}__")
|
7
|
+
raise NameError, "👋 Redefining the method `#{name}##{method_name}` is not a good idea."
|
8
|
+
end
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/phlex/elements.rb
CHANGED
@@ -1,61 +1,71 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
|
4
|
-
using Overrides::Symbol::Name
|
4
|
+
using Phlex::Overrides::Symbol::Name
|
5
5
|
end
|
6
6
|
|
7
|
-
module Phlex
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
7
|
+
module Phlex::Elements
|
8
|
+
private def slow_registered_elements
|
9
|
+
private_instance_methods
|
10
|
+
.lazy
|
11
|
+
.map(&:to_s)
|
12
|
+
.select { |m| m.start_with?("__phlex_") }
|
13
|
+
.map { |m| m[8...-2].to_sym }
|
14
|
+
end
|
15
|
+
|
16
|
+
def register_element(element, tag: element.name.tr("_", "-"))
|
17
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
def __phlex_#{element}__(**attributes, &block)
|
21
|
+
if attributes.length > 0 # with attributes
|
22
|
+
if block_given? # with content block
|
23
|
+
@_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
|
24
|
+
yield_content(&block)
|
25
|
+
@_target << "</#{tag}>"
|
26
|
+
else # without content block
|
27
|
+
@_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << "></#{tag}>"
|
28
|
+
end
|
29
|
+
else # without attributes
|
30
|
+
if block_given? # with content block
|
31
|
+
@_target << "<#{tag}>"
|
32
|
+
yield_content(&block)
|
33
|
+
@_target << "</#{tag}>"
|
34
|
+
else # without content block
|
35
|
+
@_target << "<#{tag}></#{tag}>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :_#{element}, :__phlex_#{element}__
|
43
|
+
alias_method :#{element}, :__phlex_#{element}__
|
44
|
+
private :__phlex_#{element}__
|
45
|
+
RUBY
|
46
|
+
|
47
|
+
element
|
48
|
+
end
|
49
|
+
|
50
|
+
def register_void_element(element, tag: element.name.tr("_", "-"))
|
51
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
52
|
+
# frozen_string_literal: true
|
53
|
+
|
54
|
+
def __phlex_#{element}__(**attributes)
|
55
|
+
if attributes.length > 0 # with attributes
|
56
|
+
@_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
|
57
|
+
else # without attributes
|
58
|
+
@_target << "<#{tag}>"
|
59
|
+
end
|
60
|
+
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
alias_method :_#{element}, :__phlex_#{element}__
|
65
|
+
alias_method :#{element}, :__phlex_#{element}__
|
66
|
+
private :__phlex_#{element}__
|
67
|
+
RUBY
|
68
|
+
|
69
|
+
element
|
60
70
|
end
|
61
71
|
end
|
data/lib/phlex/helpers.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
|
4
|
-
using Overrides::Symbol::Name
|
4
|
+
using Phlex::Overrides::Symbol::Name
|
5
5
|
end
|
6
6
|
|
7
7
|
module Phlex::Helpers
|
8
|
+
# @return [String]
|
8
9
|
private def tokens(*tokens, **conditional_tokens)
|
9
10
|
conditional_tokens.each do |condition, token|
|
10
11
|
truthy = case condition
|
@@ -25,9 +26,13 @@ module Phlex::Helpers
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
tokens.join(" ")
|
29
|
+
tokens = tokens.select(&:itself).join(" ")
|
30
|
+
tokens.strip!
|
31
|
+
tokens.gsub!(/\s+/, " ")
|
32
|
+
tokens
|
29
33
|
end
|
30
34
|
|
35
|
+
# @api private
|
31
36
|
private def __append_token__(tokens, token)
|
32
37
|
case token
|
33
38
|
when nil then nil
|
@@ -39,6 +44,7 @@ module Phlex::Helpers
|
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
47
|
+
# @return [Hash]
|
42
48
|
private def classes(*tokens, **conditional_tokens)
|
43
49
|
tokens = self.tokens(*tokens, **conditional_tokens)
|
44
50
|
|
@@ -49,6 +55,7 @@ module Phlex::Helpers
|
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
58
|
+
# @return [Hash]
|
52
59
|
private def mix(*args)
|
53
60
|
args.each_with_object({}) do |object, result|
|
54
61
|
result.merge!(object) do |_key, old, new|
|
@@ -189,13 +189,6 @@ module Phlex::HTML::StandardElements
|
|
189
189
|
# @see https://developer.mozilla.org/docs/Web/HTML/Element/form
|
190
190
|
register_element :form, tag: "form"
|
191
191
|
|
192
|
-
# @!method g(**attributes, &content)
|
193
|
-
# Outputs a <code>g</code> tag
|
194
|
-
# @return [nil]
|
195
|
-
# @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g
|
196
|
-
# @todo move this to SVG
|
197
|
-
register_element :g, tag: "g"
|
198
|
-
|
199
192
|
# @!method h1(**attributes, &content)
|
200
193
|
# Outputs an <code>h1</code> tag
|
201
194
|
# @return [nil]
|
@@ -377,13 +370,6 @@ module Phlex::HTML::StandardElements
|
|
377
370
|
# @see https://developer.mozilla.org/docs/Web/HTML/Element/p
|
378
371
|
register_element :p, tag: "p"
|
379
372
|
|
380
|
-
# @!method path(**attributes, &content)
|
381
|
-
# Outputs a <code>path</code> tag
|
382
|
-
# @return [nil]
|
383
|
-
# @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
384
|
-
# @todo move this to SVG
|
385
|
-
register_element :path, tag: "path"
|
386
|
-
|
387
373
|
# @!method picture(**attributes, &content)
|
388
374
|
# Outputs a <code>picture</code> tag
|
389
375
|
# @return [nil]
|