class Temple::ERB::Trimming

ERB trimming Set option :trim_mode to

<> - omit newline for lines starting with <% and ending in %>
>  - omit newline for lines ending in %>

@api public

Public Instance Methods

on_multi(*exps) click to toggle source
# File lib/temple/erb/trimming.rb, line 12
def on_multi(*exps)
  case options[:trim_mode]
  when '>'
    i = 0
    while i < exps.size
      exps.delete_at(i + 1) if code?(exps[i]) && exps[i+1] == [:static, "\n"]
      i += 1
    end
  when '<>'
    i = 0
    while i < exps.size
      exps.delete_at(i + 1) if code?(exps[i]) && exps[i+1] == [:static, "\n"] &&
                               (!exps[i-1] || (exps[i-1] == [:newline]))
      i += 1
    end
  end
  [:multi, *exps]
end

Protected Instance Methods

code?(exp) click to toggle source
# File lib/temple/erb/trimming.rb, line 33
def code?(exp)
  exp[0] == :escape || exp[0] == :code
end