39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/phlex/opal_compat.rb', line 39
def register_element(method_name, tag: method_name.name.tr("_", "-"))
define_method(method_name) do |**attributes, &content|
state = @_state
buffer = state.buffer
has_content = !content.nil?
unless state.should_render?
content.call(self) if has_content
return nil
end
if attributes.length > 0
buffer << "<#{tag}"
__homura_normalize_comma_separated_tokens__(method_name, attributes)
buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes))
buffer << ">"
if has_content
original_length = buffer.bytesize
rendered_content = content.call(self)
__implicit_output__(rendered_content) if original_length == buffer.bytesize
buffer << "</#{tag}>"
else
buffer << "</#{tag}>"
end
elsif has_content
buffer << "<#{tag}>"
original_length = buffer.bytesize
rendered_content = content.call(self)
__implicit_output__(rendered_content) if original_length == buffer.bytesize
buffer << "</#{tag}>"
else
buffer << "<#{tag}></#{tag}>"
end
flush if tag == "head"
nil
end
__registered_elements__[method_name] = tag
method_name
end
|