phlex 2.0.0.beta2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/lib/phlex/context.rb +3 -2
- data/lib/phlex/csv.rb +4 -11
- data/lib/phlex/error.rb +1 -0
- data/lib/phlex/fifo.rb +1 -0
- data/lib/phlex/helpers.rb +1 -1
- data/lib/phlex/html/standard_elements.rb +1033 -722
- data/lib/phlex/html/void_elements.rb +94 -56
- data/lib/phlex/html.rb +1 -7
- data/lib/phlex/kit.rb +23 -11
- data/lib/phlex/{elements.rb → sgml/elements.rb} +10 -36
- data/lib/phlex/sgml.rb +221 -263
- data/lib/phlex/svg/standard_elements.rb +480 -449
- data/lib/phlex/svg.rb +0 -3
- data/lib/phlex/{black_hole.rb → vanish.rb} +1 -1
- data/lib/phlex/version.rb +1 -1
- data/lib/phlex.rb +2 -5
- metadata +5 -7
- data/lib/phlex/deferred_render.rb +0 -29
- data/lib/phlex/element_clobbering_guard.rb +0 -18
@@ -2,71 +2,109 @@
|
|
2
2
|
|
3
3
|
# Void HTML elements don't accept content and never have a closing tag.
|
4
4
|
module Phlex::HTML::VoidElements
|
5
|
-
extend Phlex::Elements
|
5
|
+
extend Phlex::SGML::Elements
|
6
6
|
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
# Outputs an `<area>` tag.
|
8
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/area
|
9
|
+
__register_void_element__ def area(
|
10
|
+
class: nil,
|
11
|
+
id: nil,
|
12
|
+
**attributes
|
13
|
+
) = nil
|
12
14
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# Outputs a `<base>` tag.
|
16
|
+
# See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
17
|
+
__register_void_element__ def base(
|
18
|
+
class: nil,
|
19
|
+
href: nil,
|
20
|
+
id: nil,
|
21
|
+
target: nil,
|
22
|
+
**attributes
|
23
|
+
) = nil
|
18
24
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
# Outputs a `<br>` tag.
|
26
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/br
|
27
|
+
__register_void_element__ def br(
|
28
|
+
class: nil,
|
29
|
+
id: nil,
|
30
|
+
**attributes
|
31
|
+
) = nil
|
24
32
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
# Outputs a `<col>` tag.
|
34
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/col
|
35
|
+
__register_void_element__ def col(
|
36
|
+
class: nil,
|
37
|
+
id: nil,
|
38
|
+
**attributes
|
39
|
+
) = nil
|
30
40
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
# Outputs an `<embed>` tag.
|
42
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/embed
|
43
|
+
__register_void_element__ def embed(
|
44
|
+
class: nil,
|
45
|
+
id: nil,
|
46
|
+
**attributes
|
47
|
+
) = nil
|
36
48
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
# Outputs an `<hr>` tag.
|
50
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/hr
|
51
|
+
__register_void_element__ def hr(
|
52
|
+
class: nil,
|
53
|
+
id: nil,
|
54
|
+
**attributes
|
55
|
+
) = nil
|
42
56
|
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
57
|
+
# Outputs an `<img>` tag.
|
58
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/img
|
59
|
+
__register_void_element__ def img(
|
60
|
+
alt: nil,
|
61
|
+
class: nil,
|
62
|
+
id: nil,
|
63
|
+
src: nil,
|
64
|
+
**attributes
|
65
|
+
) = nil
|
48
66
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
67
|
+
# Outputs an `<input>` tag.
|
68
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/input
|
69
|
+
__register_void_element__ def input(
|
70
|
+
class: nil,
|
71
|
+
id: nil,
|
72
|
+
name: nil,
|
73
|
+
type: nil,
|
74
|
+
**attributes
|
75
|
+
) = nil
|
54
76
|
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
77
|
+
# Outputs a `<link>` tag.
|
78
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/link
|
79
|
+
__register_void_element__ def link(
|
80
|
+
class: nil,
|
81
|
+
id: nil,
|
82
|
+
**attributes
|
83
|
+
) = nil
|
60
84
|
|
61
|
-
#
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
85
|
+
# Outputs a `<meta>` tag.
|
86
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/meta
|
87
|
+
__register_void_element__ def meta(
|
88
|
+
charset: nil,
|
89
|
+
class: nil,
|
90
|
+
id: nil,
|
91
|
+
name: nil,
|
92
|
+
**attributes
|
93
|
+
) = nil
|
66
94
|
|
67
|
-
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
95
|
+
# Outputs a `<source>` tag.
|
96
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/source
|
97
|
+
__register_void_element__ def source(
|
98
|
+
class: nil,
|
99
|
+
id: nil,
|
100
|
+
**attributes
|
101
|
+
) = nil
|
102
|
+
|
103
|
+
# Outputs a `<track>` tag.
|
104
|
+
# See https://developer.mozilla.org/docs/Web/HTML/Element/track
|
105
|
+
__register_void_element__ def track(
|
106
|
+
class: nil,
|
107
|
+
id: nil,
|
108
|
+
**attributes
|
109
|
+
) = nil
|
72
110
|
end
|
data/lib/phlex/html.rb
CHANGED
@@ -4,10 +4,7 @@ class Phlex::HTML < Phlex::SGML
|
|
4
4
|
autoload :StandardElements, "phlex/html/standard_elements"
|
5
5
|
autoload :VoidElements, "phlex/html/void_elements"
|
6
6
|
|
7
|
-
|
8
|
-
UNSAFE_ATTRIBUTES = Set.new(%w[onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick oncontextmenu oncopy oncuechange oncut ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onfocus onhashchange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onpopstate onprogress onratechange onreset onresize onscroll onsearch onseeked onseeking onselect onstalled onstorage onsubmit onsuspend ontimeupdate ontoggle onunload onvolumechange onwaiting onwheel srcdoc]).freeze
|
9
|
-
|
10
|
-
extend Phlex::Elements
|
7
|
+
extend Phlex::SGML::Elements
|
11
8
|
include VoidElements, StandardElements
|
12
9
|
|
13
10
|
# Output an HTML doctype.
|
@@ -41,7 +38,4 @@ class Phlex::HTML < Phlex::SGML
|
|
41
38
|
def content_type
|
42
39
|
"text/html"
|
43
40
|
end
|
44
|
-
|
45
|
-
# This should be extended after all method definitions
|
46
|
-
extend Phlex::ElementClobberingGuard
|
47
41
|
end
|
data/lib/phlex/kit.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
module Phlex::Kit
|
4
4
|
module LazyLoader
|
5
5
|
def method_missing(name, ...)
|
6
|
-
|
6
|
+
mod = self.class
|
7
|
+
|
8
|
+
if name[0] == name[0].upcase && mod.constants.include?(name) && mod.const_get(name) && methods.include?(name)
|
7
9
|
public_send(name, ...)
|
8
10
|
else
|
9
11
|
super
|
@@ -11,7 +13,9 @@ module Phlex::Kit
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def respond_to_missing?(name, include_private = false)
|
14
|
-
|
16
|
+
mod = self.class
|
17
|
+
|
18
|
+
if name[0] == name[0].upcase && mod.constants.include?(name) && mod.const_get(name) && methods.include?(name)
|
15
19
|
true
|
16
20
|
else
|
17
21
|
super
|
@@ -19,20 +23,24 @@ module Phlex::Kit
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
22
|
-
include LazyLoader
|
23
|
-
|
24
26
|
def self.extended(mod)
|
25
27
|
mod.include(LazyLoader)
|
26
|
-
mod.define_method(:__phlex_kit_constants__) { mod.__phlex_kit_constants__ }
|
27
|
-
mod.define_method(:__get_phlex_kit_constant__) { |name| mod.__get_phlex_kit_constant__(name) }
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
constants
|
30
|
+
def method_missing(name, ...)
|
31
|
+
if name[0] == name[0].upcase && constants.include?(name) && const_get(name) && methods.include?(name)
|
32
|
+
public_send(name, ...)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
|
-
def
|
35
|
-
const_get(name)
|
38
|
+
def respond_to_missing?(name, include_private = false)
|
39
|
+
if name[0] == name[0].upcase && constants.include?(name) && const_get(name) && methods.include?(name)
|
40
|
+
true
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
38
46
|
def const_added(name)
|
@@ -44,14 +52,18 @@ module Phlex::Kit
|
|
44
52
|
if Class === constant && constant < Phlex::SGML
|
45
53
|
constant.include(self)
|
46
54
|
|
55
|
+
constant = nil
|
56
|
+
|
47
57
|
define_method(name) do |*args, **kwargs, &block|
|
48
58
|
constant = me.const_get(name)
|
49
59
|
render(constant.new(*args, **kwargs), &block)
|
50
60
|
end
|
51
61
|
|
52
62
|
define_singleton_method(name) do |*args, **kwargs, &block|
|
53
|
-
|
63
|
+
component, fiber_id = Thread.current[:__phlex_component__]
|
64
|
+
if (component && fiber_id == Fiber.current.object_id)
|
54
65
|
component.instance_exec do
|
66
|
+
constant = me.const_get(name)
|
55
67
|
render(constant.new(*args, **kwargs), &block)
|
56
68
|
end
|
57
69
|
else
|
@@ -1,33 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# extend Phlex::Elements
|
7
|
-
#
|
8
|
-
# register_element :trix_editor
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# class MyComponent < Phlex::HTML
|
12
|
-
# include MyCustomElements
|
13
|
-
#
|
14
|
-
# def view_template
|
15
|
-
# trix_editor
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
module Phlex::Elements
|
19
|
-
# @api private
|
20
|
-
def registered_elements
|
21
|
-
@registered_elements ||= {}
|
3
|
+
module Phlex::SGML::Elements
|
4
|
+
def __registered_elements__
|
5
|
+
@__registered_elements__ ||= {}
|
22
6
|
end
|
23
7
|
|
24
|
-
# Register a custom element. This macro defines an element method for the current class and descendents only. There is no global element registry.
|
25
|
-
# @param method_name [Symbol]
|
26
|
-
# @param tag [String] the name of the tag, otherwise this will be the method name with underscores replaced with dashes.
|
27
|
-
# @return [Symbol] the name of the method created
|
28
|
-
# @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.
|
29
|
-
# @example Register the custom element `<trix-editor>`
|
30
|
-
# register_element :trix_editor
|
31
8
|
def register_element(method_name, tag: method_name.name.tr("_", "-"))
|
32
9
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
33
10
|
# frozen_string_literal: true
|
@@ -63,14 +40,14 @@ module Phlex::Elements
|
|
63
40
|
content = yield(self)
|
64
41
|
if original_length == buffer.bytesize
|
65
42
|
case content
|
43
|
+
when ::Phlex::SGML::SafeObject
|
44
|
+
buffer << content.to_s
|
66
45
|
when String
|
67
46
|
buffer << ::Phlex::Escape.html_escape(content)
|
68
47
|
when Symbol
|
69
48
|
buffer << ::Phlex::Escape.html_escape(content.name)
|
70
49
|
when nil
|
71
50
|
nil
|
72
|
-
when ::Phlex::SGML::SafeObject
|
73
|
-
buffer << content.to_s
|
74
51
|
else
|
75
52
|
if (formatted_object = format_object(content))
|
76
53
|
buffer << ::Phlex::Escape.html_escape(formatted_object)
|
@@ -90,14 +67,14 @@ module Phlex::Elements
|
|
90
67
|
content = yield(self)
|
91
68
|
if original_length == buffer.bytesize
|
92
69
|
case content
|
70
|
+
when ::Phlex::SGML::SafeObject
|
71
|
+
buffer << content.to_s
|
93
72
|
when String
|
94
73
|
buffer << ::Phlex::Escape.html_escape(content)
|
95
74
|
when Symbol
|
96
75
|
buffer << ::Phlex::Escape.html_escape(content.name)
|
97
76
|
when nil
|
98
77
|
nil
|
99
|
-
when ::Phlex::SGML::SafeObject
|
100
|
-
buffer << content.to_s
|
101
78
|
else
|
102
79
|
if (formatted_object = format_object(content))
|
103
80
|
buffer << ::Phlex::Escape.html_escape(formatted_object)
|
@@ -117,17 +94,14 @@ module Phlex::Elements
|
|
117
94
|
|
118
95
|
nil
|
119
96
|
end
|
120
|
-
|
121
|
-
alias_method :_#{method_name}, :#{method_name}
|
122
97
|
RUBY
|
123
98
|
|
124
|
-
|
99
|
+
__registered_elements__[method_name] = tag
|
125
100
|
|
126
101
|
method_name
|
127
102
|
end
|
128
103
|
|
129
|
-
|
130
|
-
def register_void_element(method_name, tag: method_name.name.tr("_", "-"))
|
104
|
+
def __register_void_element__(method_name, tag: method_name.name.tr("_", "-"))
|
131
105
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
132
106
|
# frozen_string_literal: true
|
133
107
|
|
@@ -165,7 +139,7 @@ module Phlex::Elements
|
|
165
139
|
alias_method :_#{method_name}, :#{method_name}
|
166
140
|
RUBY
|
167
141
|
|
168
|
-
|
142
|
+
__registered_elements__[method_name] = tag
|
169
143
|
|
170
144
|
method_name
|
171
145
|
end
|