Skip to content

Engine: Optimize Action View Tag Helpers when compiling template #653

@marcoroth

Description

@marcoroth

We can optimize static or partially static Action View Tag Helpers, since the Herb Parser is soon going to understand and transform Action View Tag Helpers to HTML-elements.

Fully Static with dynamic content

For example, for fully static Tag Helpers:

<%= tag.p class: "flex" do %>
  <span><%= content %></span>
<% end %>

Currently gets compiled to:

__herb = ::Herb::Engine; _buf = ::String.new;
 _buf << __herb.h(tag.p class: "flex" do); _buf << '
  <span>'.freeze; _buf << __herb.h((content)); _buf << '</span>
'.freeze; end; _buf << '
'.freeze;
_buf.to_s

Since everything in this Tag-helper call is static, we could optimize it to avoid the helper-related method calls at runtime:

__herb = ::Herb::Engine; _buf = ::String.new;
 _buf << '<p class="flex">
  <span>'.freeze; _buf << __herb.h((content)); _buf << '</span>
</p>
'.freeze;
_buf.to_s

Fully Static with static content

For fully static tag helper calls with only static content:

<%= tag.p class: "flex" do %>
  <span>Content</span>
<% end %>

We can inline everything into a single string:

__herb = ::Herb::Engine; _buf = ::String.new;
 _buf << '<p class="flex">
  <span>Content</span>
</p>
'.freeze;
_buf.to_s

Partially Static

For partially static Tag Helpers like this:

<%= tag.p class: classes do %>
  <span><%= content %></span>
<% end %>

We could optimize it to:

__herb = ::Herb::Engine; _buf = ::String.new;
 _buf << '<p class="'.freeze; _buf << ::Herb::Engine.attr((classes)); _buf << '">
  <span>'.freeze; _buf << __herb.h((content)); _buf << '</span>
</p>
'.freeze;
_buf.to_s

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions