Skip to content
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

perf: Improve performance when rendering elements #86

Merged
merged 1 commit into from
Oct 19, 2024
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
24 changes: 19 additions & 5 deletions src/blueprint/html/element_registrar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,45 @@ module Blueprint::HTML::ElementRegistrar
{% tag ||= method_name.tr("_", "-") %}

private def {{method_name.id}}(**attributes, &block) : Nil
element({{tag}}, **attributes) { yield }
@buffer << "<{{tag.id}}"
append_attributes(attributes)
@buffer << ">"
capture_content { yield }
@buffer << "</{{tag.id}}>"
end

private def {{method_name.id}}(**attributes) : Nil
element({{tag}}, "", **attributes)
@buffer << "<{{tag.id}}"
append_attributes(attributes)
@buffer << "></{{tag.id}}>"
end

private def {{method_name.id}}(__content__, **attributes) : Nil
element({{tag}}, __content__, **attributes)
@buffer << "<{{tag.id}}"
append_attributes(attributes)
@buffer << ">"
append_to_buffer(__content__)
@buffer << "</{{tag.id}}>"
end
end

macro register_empty_element(method_name, tag = nil)
{% tag ||= method_name.tr("_", "-") %}

private def {{method_name.id}}(**attributes) : Nil
element({{tag}}, "", **attributes)
@buffer << "<{{tag.id}}"
append_attributes(attributes)
@buffer << "></{{tag.id}}>"
end
end

macro register_void_element(method_name, tag = nil)
{% tag ||= method_name.tr("_", "-") %}

private def {{method_name.id}}(**attributes) : Nil
void_element({{tag}}, **attributes)
@buffer << "<{{tag.id}}"
append_attributes(attributes)
@buffer << ">"
end
end
end
Loading