phlex 1.6.3 β 1.7.0
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/.yardopts +1 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +1 -0
- data/README.md +3 -43
- data/lib/phlex/black_hole.rb +1 -0
- data/lib/phlex/callable.rb +1 -0
- data/lib/phlex/context.rb +1 -0
- data/lib/phlex/deferred_render.rb +24 -0
- data/lib/phlex/element_clobbering_guard.rb +7 -8
- data/lib/phlex/elements.rb +38 -11
- data/lib/phlex/helpers.rb +21 -4
- data/lib/phlex/html/standard_elements.rb +193 -103
- data/lib/phlex/html/void_elements.rb +13 -12
- data/lib/phlex/html.rb +4 -6
- data/lib/phlex/overrides/symbol/name.rb +1 -0
- data/lib/phlex/sgml.rb +182 -68
- data/lib/phlex/svg/standard_elements.rb +128 -64
- data/lib/phlex/svg.rb +0 -4
- data/lib/phlex/unbuffered.rb +1 -0
- data/lib/phlex/version.rb +1 -1
- data/lib/phlex.rb +19 -6
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c0002c77419906adab684bd6e3bcb0ad2d5b7084aeb4e62f89c4f15a1da6001
|
4
|
+
data.tar.gz: dea42d460e9cce5f3a4001dbe5d6cbfd155f2bafe725ed0a21f3bfc9bb050a39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d4b19c21a14a60f8ff8cb2418bea2d553768b219cc9d491b44181580af17f4aeb804e0e4e0a875f959c74ab96b556f95fc5958e5ff4423f893cd7f07498a99
|
7
|
+
data.tar.gz: 8512284569af79d553d74e16539292f1e68d10aad9224f0c1ec9698ef6d38c025bf20aa3a6c8b0db3533e21c03978980472d7c016148a9605e6fbf72caa0f0fe
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.2
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--private --no-private --hide-api private --markup markdown
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
4
|
+
|
5
|
+
## 1.7.0
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Experimental Smart chunking.
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Improved YARD documentation, which is now available here https://rubydoc.info/gems/phlex
|
14
|
+
- `SGML#render` can now render lambdas with zero or one arguments. Previously, it could only render lambdas with exactly one argument, although it could always render Procs with any number of arguments. When an argument is accepted, the `self` of the component rendering it is yielded to the Proc.
|
15
|
+
- Raise an error when outputting an unknown object using `SGML#plain`.
|
16
|
+
- Raise an error when using attribute keys that aren't Strings or Symbols.
|
17
|
+
- Support Array and Set values for HTML/SVG attributes.
|
18
|
+
|
19
|
+
### Removed
|
20
|
+
|
21
|
+
- Removed the `menuitem` element as it's a deprecated HTML element.
|
22
|
+
|
23
|
+
***
|
24
|
+
|
25
|
+
Before this changelog was introduced, changes were logged in the [release notes](https://github.com/phlex-ruby/phlex/releases).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,47 +1,6 @@
|
|
1
|
-
<a href="https://www.phlex.fun"><img alt="Phlex logo" src="
|
1
|
+
<a href="https://www.phlex.fun"><img alt="Phlex logo" src="https://www.phlex.fun/assets/logo.png" width="180" /></a>
|
2
2
|
|
3
|
-
Phlex lets you compose web views in pure Ruby. Itβs super-fast, thread-safe and supports TruffleRuby v22.2+, JRuby v9.2+ and MRI v2.7+.
|
4
|
-
|
5
|
-
### Documentation π
|
6
|
-
|
7
|
-
Documentation can be found at [www.phlex.fun](https://www.phlex.fun).
|
8
|
-
|
9
|
-
### Support β
|
10
|
-
|
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
|
-
|
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
|
-
|
24
|
-
### Community π
|
25
|
-
|
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).
|
27
|
-
|
28
|
-
### Who uses Phlex?
|
29
|
-
|
30
|
-
- [Clearscope](https://www.clearscope.io)
|
31
|
-
|
32
|
-
*If youβre using Phlex in production, please open a PR to list it here.*
|
33
|
-
|
34
|
-
### Sponsorship π
|
35
|
-
|
36
|
-
Maintaining a library is a lot of work. If your company benefits from this work or is likely to benefit from it in the future, please consider [sponsorship](https://github.com/sponsors/joeldrapper). Phlex is actively developed and maintained by **[Joel Drapper](https://github.com/sponsors/joeldrapper)**.
|
37
|
-
|
38
|
-
### Security π¨
|
39
|
-
|
40
|
-
If youβve found a potential security issue, please email [security@phlex.fun](mailto:security@phlex.fun).
|
41
|
-
|
42
|
-
### Thanks π
|
43
|
-
|
44
|
-
Thanks [Logology](https://www.logology.co) for sponsoring our logo.
|
3
|
+
Phlex lets you compose web views in pure Ruby β kind of like JSX, but not really anything like JSX. Itβs super-fast, thread-safe and supports TruffleRuby v22.2+, JRuby v9.2+ and MRI v2.7+. Phlex currently supports [HTML](https://rubydoc.info/gems/phlex/Phlex/HTML) and [SVG](https://rubydoc.info/gems/phlex/Phlex/SVG) views, and weβre exploring JSON and XML.
|
45
4
|
|
46
5
|
### Prior Art π¨
|
47
6
|
|
@@ -55,3 +14,4 @@ Thanks [Logology](https://www.logology.co) for sponsoring our logo.
|
|
55
14
|
- [hyperstack](https://github.com/hyperstack-org/hyperstack)
|
56
15
|
- [clearwater](https://github.com/clearwater-rb/clearwater)
|
57
16
|
- [paggio](https://github.com/opal/paggio)
|
17
|
+
- [Inesita](https://github.com/inesita-rb/inesita)
|
data/lib/phlex/black_hole.rb
CHANGED
data/lib/phlex/callable.rb
CHANGED
data/lib/phlex/context.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Include this module into an {HTML} or {SVG} component to make it yield the content block before calling {#template}.
|
4
|
+
# @example
|
5
|
+
# class Tabs < Phlex::HTML
|
6
|
+
# include DeferredRender
|
7
|
+
#
|
8
|
+
# Tab = Data.define(:name, :content)
|
9
|
+
#
|
10
|
+
# def initialize
|
11
|
+
# @tabs = []
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def template
|
15
|
+
# @tabs.each { |t| a { t.name } }
|
16
|
+
# @tabs.each { |t| article(&t.content) }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def tab(name, &content)
|
20
|
+
# @tabs << Tab.new(name, content)
|
21
|
+
# end
|
22
|
+
# end
|
3
23
|
module Phlex::DeferredRender
|
4
24
|
# This module doesn't do anything. Phlex::HTML#call checks for its inclusion in the ancestry instead.
|
25
|
+
|
26
|
+
# @!method template
|
27
|
+
# @abstract Override to define your own template.
|
28
|
+
# @note {DeferredRender} templates do not receive the content block. Instead, it is yielded in advance.
|
5
29
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
3
|
+
# @api private
|
4
|
+
module Phlex::ElementClobberingGuard
|
5
|
+
def method_added(method_name)
|
6
|
+
if method_name[0] == "_" && element_method?(method_name[1..].to_sym)
|
7
|
+
raise Phlex::NameError, "π Redefining the method `#{name}##{method_name}` is not a good idea."
|
8
|
+
else
|
9
|
+
super
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
data/lib/phlex/elements.rb
CHANGED
@@ -4,17 +4,41 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
|
|
4
4
|
using Phlex::Overrides::Symbol::Name
|
5
5
|
end
|
6
6
|
|
7
|
+
# Extending this module provides the {register_element} macro for registering your own custom elements. It's already extended by {HTML} and {SVG}.
|
8
|
+
# @example
|
9
|
+
# module MyCustomElements
|
10
|
+
# extend Phlex::Elements
|
11
|
+
#
|
12
|
+
# register_element :trix_editor
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# class MyComponent < Phlex::HTML
|
16
|
+
# include MyCustomElements
|
17
|
+
#
|
18
|
+
# def template
|
19
|
+
# trix_editor
|
20
|
+
# end
|
21
|
+
# end
|
7
22
|
module Phlex::Elements
|
23
|
+
# @api private
|
8
24
|
def registered_elements
|
9
25
|
@registered_elements ||= Concurrent::Map.new
|
10
26
|
end
|
11
27
|
|
12
|
-
|
28
|
+
# Register a custom element. This macro defines an element method for the current class and descendents only. There is no global element registry.
|
29
|
+
# @param method_name [Symbol]
|
30
|
+
# @param tag [String] the name of the tag, otherwise this will be the method name with underscores replaced with dashes.
|
31
|
+
# @return [Symbol] the name of the method created
|
32
|
+
# @note The methods defined by this macro depend on other methods from {SGML} so they should always be mixed into an {HTML} or {SVG} component.
|
33
|
+
# @example Register the custom element `<trix-editor>`
|
34
|
+
# register_element :trix_editor
|
35
|
+
def register_element(method_name, tag: nil)
|
36
|
+
tag ||= method_name.name.tr("_", "-")
|
37
|
+
|
13
38
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
14
39
|
# frozen_string_literal: true
|
15
40
|
|
16
|
-
|
17
|
-
def #{element}(**attributes, &block)
|
41
|
+
def #{method_name}(**attributes, &block)
|
18
42
|
target = @_context.target
|
19
43
|
|
20
44
|
if attributes.length > 0 # with attributes
|
@@ -35,22 +59,25 @@ module Phlex::Elements
|
|
35
59
|
end
|
36
60
|
end
|
37
61
|
|
62
|
+
#{'flush' if tag == 'head'}
|
63
|
+
|
38
64
|
nil
|
39
65
|
end
|
40
66
|
|
41
|
-
alias_method :_#{
|
67
|
+
alias_method :_#{method_name}, :#{method_name}
|
42
68
|
RUBY
|
43
69
|
|
44
|
-
registered_elements[
|
70
|
+
registered_elements[method_name] = tag
|
45
71
|
|
46
|
-
|
72
|
+
method_name
|
47
73
|
end
|
48
74
|
|
49
|
-
|
75
|
+
# @api private
|
76
|
+
def register_void_element(method_name, tag: method_name.name.tr("_", "-"))
|
50
77
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
51
78
|
# frozen_string_literal: true
|
52
79
|
|
53
|
-
def #{
|
80
|
+
def #{method_name}(**attributes)
|
54
81
|
target = @_context.target
|
55
82
|
|
56
83
|
if attributes.length > 0 # with attributes
|
@@ -62,11 +89,11 @@ module Phlex::Elements
|
|
62
89
|
nil
|
63
90
|
end
|
64
91
|
|
65
|
-
alias_method :_#{
|
92
|
+
alias_method :_#{method_name}, :#{method_name}
|
66
93
|
RUBY
|
67
94
|
|
68
|
-
registered_elements[
|
95
|
+
registered_elements[method_name] = tag
|
69
96
|
|
70
|
-
|
97
|
+
method_name
|
71
98
|
end
|
72
99
|
end
|
data/lib/phlex/helpers.rb
CHANGED
@@ -5,8 +5,24 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module Phlex::Helpers
|
8
|
+
private
|
9
|
+
|
10
|
+
# Tokens
|
8
11
|
# @return [String]
|
9
|
-
|
12
|
+
# @example With Proc conditions
|
13
|
+
# tokens(
|
14
|
+
# -> { true } => "a",
|
15
|
+
# -> { false } => "b"
|
16
|
+
# )
|
17
|
+
# @example With method conditions
|
18
|
+
# tokens(
|
19
|
+
# active?: "active"
|
20
|
+
# )
|
21
|
+
# @example With else condition
|
22
|
+
# tokens(
|
23
|
+
# active?: { then: "active", else: "inactive" }
|
24
|
+
# )
|
25
|
+
def tokens(*tokens, **conditional_tokens)
|
10
26
|
conditional_tokens.each do |condition, token|
|
11
27
|
truthy = case condition
|
12
28
|
when Symbol then send(condition)
|
@@ -33,7 +49,7 @@ module Phlex::Helpers
|
|
33
49
|
end
|
34
50
|
|
35
51
|
# @api private
|
36
|
-
|
52
|
+
def __append_token__(tokens, token)
|
37
53
|
case token
|
38
54
|
when nil then nil
|
39
55
|
when String then tokens << token
|
@@ -44,8 +60,9 @@ module Phlex::Helpers
|
|
44
60
|
end
|
45
61
|
end
|
46
62
|
|
63
|
+
# Like {#tokens} but returns a {Hash} where the tokens are the value for `:class`.
|
47
64
|
# @return [Hash]
|
48
|
-
|
65
|
+
def classes(*tokens, **conditional_tokens)
|
49
66
|
tokens = self.tokens(*tokens, **conditional_tokens)
|
50
67
|
|
51
68
|
if tokens.empty?
|
@@ -56,7 +73,7 @@ module Phlex::Helpers
|
|
56
73
|
end
|
57
74
|
|
58
75
|
# @return [Hash]
|
59
|
-
|
76
|
+
def mix(*args)
|
60
77
|
args.each_with_object({}) do |object, result|
|
61
78
|
result.merge!(object) do |_key, old, new|
|
62
79
|
case new
|