module Erubis::Converter

def self.supported_properties # :nodoc:

:nodoc:
def self.supported_properties    # :nodoc:
  return [
          [:preamble,  nil,    "preamble (no preamble when false)"],
          [:postamble, nil,    "postamble (no postamble when false)"],
          [:escape,    nil,    "escape expression or not in default"],
         ]
end

def convert(input)

# convert input string into target language
def convert(input)
  codebuf = ""    # or []
  @preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble))
  convert_input(codebuf, input)
  @postamble.nil? ? add_postamble(codebuf) : (@postamble && (codebuf << @postamble))
  @_proc = nil    # clear cached proc object
  return codebuf  # or codebuf.join()
end

def convert_input(codebuf, input)

#
# (abstract) convert input to code
#
def convert_input(codebuf, input)
  not_implemented
end

def detect_spaces_at_bol(text, is_bol)

#
# detect spaces at beginning of line
#
def detect_spaces_at_bol(text, is_bol)
  lspace = nil
  if text.empty?
    lspace = "" if is_bol
  elsif text[-1] == ?\n
    lspace = ""
  else
    rindex = text.rindex(?\n)
    if rindex
      s = text[rindex+1..-1]
      if s =~ /\A[ \t]*\z/
        lspace = s
        #text = text[0..rindex]
        text[rindex+1..-1] = ''
      end
    else
      if is_bol && text =~ /\A[ \t]*\z/
        #lspace = text
        #text = nil
        lspace = text.dup
        text[0..-1] = ''
      end
    end
  end
  return lspace
end

def init_converter(properties={})

def init_converter(properties={})
  @preamble  = properties[:preamble]
  @postamble = properties[:postamble]
  @escape    = properties[:escape]
end