phlex 1.6.1 β 1.8.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 +32 -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 +175 -64
- 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: 463bbaade702e9495ee8965c20ca4c5aeb926b10a2e190584a0a0dfcc4f43709
|
4
|
+
data.tar.gz: f57de49b85bfc10920f890581656a7aa1c86d6d120ce45017c9fc0c355587514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf30a011b71eb056c093b0e0691e635b7fc60f3b2ed533fec63d65bd8c29ca5ddea794ac054a33c27cb2b79e8caab587299522707646c34c12a822a819aeba05
|
7
|
+
data.tar.gz: c8dc0e52c90c686e0824ee611afb303c8cdb8c9d9ebbb0293e1f0a0905e83a302499cabca54e44f2bddbe859ac43dd71d004f4f05b1feaf3dbd8d7f9696f24b8
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.
|
1
|
+
3.2.2
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--private --hide-api private --markup markdown
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
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.8.0] 2024-04-19
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Support `Integer` and `Float` attribute values, and fall back to calling `to_str` on other objects.
|
10
|
+
|
11
|
+
## [1.7.0] 2024-04-18
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Experimental Smart chunking.
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Improved YARD documentation, which is now available here https://rubydoc.info/gems/phlex
|
20
|
+
- `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.
|
21
|
+
- Raise an error when outputting an unknown object using `SGML#plain`.
|
22
|
+
- Raise an error when using attribute keys that aren't Strings or Symbols.
|
23
|
+
- Support Array and Set values for HTML/SVG attributes.
|
24
|
+
|
25
|
+
### Removed
|
26
|
+
|
27
|
+
- Removed the `menuitem` element as it's a deprecated HTML element.
|
28
|
+
- Removed the `SGML#text` method. This has been replaced with `SGML#plain`.
|
29
|
+
|
30
|
+
***
|
31
|
+
|
32
|
+
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
|