Skip to content

Engine: Omit __herb = ::Herb::Engine; in compiled template if it's not needed #652

Description

@marcoroth

Compiling a HTML+ERB document using the Herb::Engine always emits the __herb = ::Herb::Engine; preamble.

For example in a document like:

<h1>
  <% if true %>
    <div>Text1</div>
  <% elsif false %>
    <div>Text2</div>
  <% else %>
    <div>Text3</div>
  <% end %>
</h1>

This gets compiled to:

__herb = ::Herb::Engine; _buf = ::String.new;
 _buf << '<h1>
  '.freeze; if true; _buf << '
    <div>Text1</div>
  '.freeze; elsif false; _buf << '
    <div>Text2</div>
  '.freeze; else; _buf << '
    <div>Text3</div>
  '.freeze; end; _buf << '
</h1>
'.freeze;
_buf.to_s

We could omit the preamble if we notice that we aren't using it in the compiled Ruby template.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions