8000 Ensure HTML output by joeldrapper · Pull Request #864 · yippee-fun/phlex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ensure HTML output #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 60 additions & 39 deletions lib/phlex/sgml/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,69 @@ def #{method_name}(**attributes)

if attributes.length > 0 # with attributes
if block_given # with content block
buffer << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes)) << ">"

original_length = buffer.bytesize
content = yield(self)
if original_length == buffer.bytesize
case content
when ::Phlex::SGML::SafeObject
buffer << content.to_s
when String
buffer << ::Phlex::Escape.html_escape(content)
when Symbol
buffer << ::Phlex::Escape.html_escape(content.name)
when nil
nil
else
if (formatted_object = format_object(content))
buffer << ::Phlex::Escape.html_escape(formatted_object)
buffer << "<#{tag}"
begin
buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
ensure
buffer << ">"
end

begin
original_length = buffer.bytesize
content = yield(self)
if original_length == buffer.bytesize
case content
when ::Phlex::SGML::SafeObject
buffer << content.to_s
when String
buffer << ::Phlex::Escape.html_escape(content)
when Symbol
buffer << ::Phlex::Escape.html_escape(content.name)
when nil
nil
else
if (formatted_object = format_object(content))
buffer << ::Phlex::Escape.html_escape(formatted_object)
end
end
end
ensure
buffer << "</#{tag}>"
end

buffer << "</#{tag}>"
else # without content
buffer << "<#{tag}" << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes)) << "></#{tag}>"
buffer << "<#{tag}"
begin
buffer << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
ensure
buffer << "></#{tag}>"
end
end
else # without attributes
if block_given # with content block
buffer << "<#{tag}>"

original_length = buffer.bytesize
content = yield(self)
if original_length == buffer.bytesize
case content
when ::Phlex::SGML::SafeObject
buffer << content.to_s
when String
buffer << ::Phlex::Escape.html_escape(content)
when Symbol
buffer << ::Phlex::Escape.html_escape(content.name)
when nil
nil
else
if (formatted_object = format_object(content))
buffer << ::Phlex::Escape.html_escape(formatted_object)
begin
original_length = buffer.bytesize
content = yield(self)
if original_length == buffer.bytesize
case content
when ::Phlex::SGML::SafeObject
buffer << content.to_s
when String
buffer << ::Phlex::Escape.html_escape(content)
when Symbol
buffer << ::Phlex::Escape.html_escape(content.name)
when nil
nil
else
if (formatted_object = format_object(content))
buffer << ::Phlex::Escape.html_escape(formatted_object)
end
end
end
ensure
buffer << "</#{tag}>"
end

buffer << "</#{tag}>"
else # without content
buffer << "<#{tag}></#{tag}>"
end
Expand All @@ -95,10 +109,17 @@ def #{method_name}(**attributes)

return unless state.should_render?

buffer = state.buffer

if attributes.length > 0 # with attributes
state.buffer << "<#{tag}" << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes)) << ">"
buffer << "<#{tag}"
begin
buffer << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
ensure
buffer << ">"
end
else # without attributes
state.buffer << "<#{tag}>"
buffer << "<#{tag}>"
end

nil
Expand Down
0