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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe4d886672079338214f95fb037805836bfae5e975c549153ffbabeef2d1cd35
4
- data.tar.gz: 4e88e58ab6351024d738b07a4dc7231837462b09396f55fa7cec6904f32b031d
3
+ metadata.gz: 647e5f1a1f3beb8dd596cb87a5fb848f07e8e87e28ce705f3d1c93d8c9cfe9ac
4
+ data.tar.gz: d2b327f45d36a44069cf6dd9de03310918f56647bc1a40c6eb675837eb1cb653
5
5
  SHA512:
6
- metadata.gz: 386ab00e03abeb9a752d91ca025c21765bce174a375326544170be5ff032e5ed7289b114981871482baccc46024d9d31cacad64db564d45129b1b182938b349a
7
- data.tar.gz: 7557c4583e78b49421ca301982b0ee5f8b0dab478075a6882b8040bace46e6dd5f49e81a401f5e3101f42380898e00ddbac7e5a864ce269710415febf8514ac3
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/PercentLiteralDelimiters:
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
@@ -7,9 +7,7 @@ gemspec
7
7
 
8
8
  gem "rubocop"
9
9
  gem "sus"
10
- gem "zeitwerk"
11
10
  gem "benchmark-ips"
12
- gem "erb"
13
11
 
14
12
  group :test do
15
13
  gem "i18n"
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)
@@ -13,4 +13,10 @@ module ViewHelper
13
13
  Class.new(Phlex::HTML, &block)
14
14
  end
15
15
  end
16
+
17
+ def svg_view(&block)
18
+ let :view do
19
+ Class.new(Phlex::SVG, &block)
20
+ end
21
+ end
16
22
  end
@@ -1,15 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Phlex
4
- module BlackHole
5
- extend self
3
+ module Phlex::BlackHole
4
+ extend self
6
5
 
7
- def <<(anything)
8
- self
9
- end
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
- def length
12
- 0
13
- end
18
+ def clear
19
+ self
14
20
  end
15
21
  end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Phlex
4
- module Callable
5
- def to_proc
6
- method(:call).to_proc
7
- end
3
+ module Phlex::Callable
4
+ def to_proc
5
+ method(:call).to_proc
8
6
  end
9
7
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Phlex
4
- module DeferredRender
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
@@ -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
- module Elements
9
- def register_element(element, tag: element.name.tr("_", "-"))
10
- class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
11
- # frozen_string_literal: true
12
-
13
- def #{element}(**attributes, &block)
14
- if attributes.length > 0
15
- if block_given?
16
- @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << ">"
17
- yield_content(&block)
18
- @_target << "</#{tag}>"
19
- else
20
- @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << "></#{tag}>"
21
- end
22
- else
23
- if block_given?
24
- @_target << "<#{tag}>"
25
- yield_content(&block)
26
- @_target << "</#{tag}>"
27
- else
28
- @_target << "<#{tag}></#{tag}>"
29
- end
30
- end
31
-
32
- nil
33
- end
34
-
35
- alias_method :_#{element}, :#{element}
36
- RUBY
37
-
38
- Phlex::HTML::STANDARD_ELEMENTS[element] = tag
39
- end
40
-
41
- def register_void_element(element, tag: element.name.tr("_", "-"))
42
- class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
43
- # frozen_string_literal: true
44
-
45
- def #{element}(**attributes)
46
- if attributes.length > 0
47
- @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << ">"
48
- else
49
- @_target << "<#{tag}>"
50
- end
51
-
52
- nil
53
- end
54
-
55
- alias_method :_#{element}, :#{element}
56
- RUBY
57
-
58
- Phlex::HTML::VOID_ELEMENTS[element] = tag
59
- end
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]