class Hanami::View::ERB::Filters::Trimming

Trims spurious spaces from ERB-generated text.

Deletes spaces around “<% %>” and leave spaces around “<%= %>”.

This is a copy of Temple::ERB::Trimming, with the one difference being that it descends into the sexp-tree by running ‘compile(e)` for any non-`:static` sexps. This is necessary for our implementation of ERB, because we capture block content by creating additional `:multi` sexps with their own nested content.

@api private @since 2.1.0

Public Instance Methods

on_multi(*exps) click to toggle source
# File lib/hanami/view/erb/filters/trimming.rb, line 25
def on_multi(*exps)
  exps = exps.each_with_index.map do |e,i|
    if e.first == :static && i > 0 && exps[i-1].first == :code
      [:static, e.last.lstrip]
    elsif e.first == :static && i < exps.size-1 && exps[i+1].first == :code
      [:static, e.last.rstrip]
    else
      compile(e)
    end
  end if options[:trim]

  [:multi, *exps]
end