Sha256: 065cee29b33e91064987ec9400116e873c7239c0b5efa2fb761de0af82111592
Contents?: true
Size: 910 Bytes
Versions: 49
Compression:
Stored size: 910 Bytes
Contents
module Temple module ERB # ERB trimming # Set option :trim_mode to # <> - omit newline for lines starting with <% and ending in %> # > - omit newline for lines ending in %> # # @api public class Trimming < Filter 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 def code?(exp) exp[0] == :escape || exp[0] == :code end end end end
Version data entries
49 entries across 49 versions & 2 rubygems