class Erb::Indent::IndentCompiler

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/erb/indent.rb, line 14
def initialize(*)
  super
  @indent_level = nil
end

Public Instance Methods

add_insert_cmd(out, content) click to toggle source
Calls superclass method
# File lib/erb/indent.rb, line 27
def add_insert_cmd(out, content)
  if @indent_level
    super(out, "(#{content}).to_s.sub(/^ +/, ' ' * #{@indent_level})")
  else
    super
  end
end
add_put_cmd(out, content) click to toggle source
Calls superclass method
# File lib/erb/indent.rb, line 19
def add_put_cmd(out, content)
  if @indent_level
    super(out, content.sub(/^ +/, ' ' * @indent_level))
  else
    super
  end
end
compile_stag(stag, out, scanner) click to toggle source
Calls superclass method
# File lib/erb/indent.rb, line 35
def compile_stag(stag, out, scanner)
  case stag
  when '<%|'
    if @indent_level
      @indent_level = nil
    else
      spaces = content.lines.last&.match(/\A +/)&.to_s
      @indent_level = spaces ? spaces.length : 0
    end
    super('<%', out, scanner)
  else
    super
  end
end
make_scanner(src) click to toggle source
# File lib/erb/indent.rb, line 50
def make_scanner(src)
  IndentScanner.new(src, @trim_mode, @percent)
end